diff --git a/src/main/kotlin/app/revanced/cli/command/MainCommand.kt b/src/main/kotlin/app/revanced/cli/command/MainCommand.kt index f54c0969..99ac1b1c 100644 --- a/src/main/kotlin/app/revanced/cli/command/MainCommand.kt +++ b/src/main/kotlin/app/revanced/cli/command/MainCommand.kt @@ -18,12 +18,11 @@ fun main(args: Array) { } 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() { diff --git a/src/main/kotlin/app/revanced/utils/adb/Commands.kt b/src/main/kotlin/app/revanced/utils/adb/Commands.kt index 6d7f95d6..7ec7eb8b 100644 --- a/src/main/kotlin/app/revanced/utils/adb/Commands.kt +++ b/src/main/kotlin/app/revanced/utils/adb/Commands.kt @@ -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 + 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() = diff --git a/src/main/kotlin/app/revanced/utils/adb/Constants.kt b/src/main/kotlin/app/revanced/utils/adb/Constants.kt index 96cc409c..ea5095e8 100644 --- a/src/main/kotlin/app/revanced/utils/adb/Constants.kt +++ b/src/main/kotlin/app/revanced/utils/adb/Constants.kt @@ -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 @@ -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() }