Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

Commit

Permalink
fix: fix running commands not running
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Aug 24, 2023
1 parent 52c3be2 commit 2c7fcaf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
11 changes: 5 additions & 6 deletions src/main/kotlin/app/revanced/cli/command/MainCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ fun main(args: Array<String>) {
}

object : Handler() {
override fun publish(record: LogRecord) = formatter.format(record).let {
if (record.level.intValue() > Level.INFO.intValue()) {
System.err.write(it.toByteArray())
} else {
System.out.write(it.toByteArray())
}
override fun publish(record: LogRecord) = formatter.format(record).toByteArray().let {
if (record.level.intValue() > Level.INFO.intValue())
System.err.write(it)
else
System.out.write(it)
}

override fun flush() {
Expand Down
24 changes: 14 additions & 10 deletions src/main/kotlin/app/revanced/utils/adb/Commands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ package app.revanced.utils.adb

import se.vidstige.jadb.JadbDevice
import se.vidstige.jadb.RemoteFile
import se.vidstige.jadb.ShellProcessBuilder
import java.io.File
import java.util.concurrent.Callable
import java.util.concurrent.Executors

// return the input or output stream, depending on which first returns a value
internal fun JadbDevice.run(command: String, su: Boolean = false) = with(this.startCommand(command, su)) {
Executors.newFixedThreadPool(2).let { service ->
arrayOf(inputStream, errorStream).map { stream ->
Callable { stream.bufferedReader().use { it.readLine() } }
}.let { tasks -> service.invokeAny(tasks).also { service.shutdown() } }
}


internal fun JadbDevice.buildCommand(command: String, su: Boolean = true): ShellProcessBuilder {
if (su) return shellProcessBuilder("su -c \'$command\'")

val args = command.split(" ") as ArrayList<String>
val cmd = args.removeFirst()

return shellProcessBuilder(cmd, *args.toTypedArray())
}

internal fun JadbDevice.run(command: String, su: Boolean = true): Int {
return this.buildCommand(command, su).start().waitFor()
}

internal fun JadbDevice.hasSu() =
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/app/revanced/utils/adb/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal object Constants {

internal const val INSTALL_MOUNT = "mv $TMP_PATH $MOUNT_PATH && chmod +x $MOUNT_PATH"

internal const val MOUNT_SCRIPT =
internal val MOUNT_SCRIPT =
"""
#!/system/bin/sh
MAGISKTMP="${'$'}(magisk --path)" || MAGISKTMP=/sbin
Expand All @@ -36,5 +36,5 @@ internal object Constants {
chcon u:object_r:apk_data_file:s0 ${'$'}base_path
mount -o bind ${'$'}MIRROR${'$'}base_path ${'$'}stock_path
"""
""".trimIndent()
}

0 comments on commit 2c7fcaf

Please sign in to comment.