From 2c7fcaf4add65a12052afc5bef779dbc73debd69 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Thu, 24 Aug 2023 17:51:31 +0200 Subject: [PATCH] fix: fix running commands not running --- .../app/revanced/cli/command/MainCommand.kt | 11 +++++----- .../kotlin/app/revanced/utils/adb/Commands.kt | 22 +++++++++++-------- .../app/revanced/utils/adb/Constants.kt | 4 ++-- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/main/kotlin/app/revanced/cli/command/MainCommand.kt b/src/main/kotlin/app/revanced/cli/command/MainCommand.kt index f54c096..99ac1b1 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 6d7f95d..7ec7eb8 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 96cc409..ea5095e 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() }