Skip to content

Commit 2c7fcaf

Browse files
committed
fix: fix running commands not running
1 parent 52c3be2 commit 2c7fcaf

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

src/main/kotlin/app/revanced/cli/command/MainCommand.kt

+5-6
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ fun main(args: Array<String>) {
1818
}
1919

2020
object : Handler() {
21-
override fun publish(record: LogRecord) = formatter.format(record).let {
22-
if (record.level.intValue() > Level.INFO.intValue()) {
23-
System.err.write(it.toByteArray())
24-
} else {
25-
System.out.write(it.toByteArray())
26-
}
21+
override fun publish(record: LogRecord) = formatter.format(record).toByteArray().let {
22+
if (record.level.intValue() > Level.INFO.intValue())
23+
System.err.write(it)
24+
else
25+
System.out.write(it)
2726
}
2827

2928
override fun flush() {

src/main/kotlin/app/revanced/utils/adb/Commands.kt

+14-10
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@ package app.revanced.utils.adb
22

33
import se.vidstige.jadb.JadbDevice
44
import se.vidstige.jadb.RemoteFile
5+
import se.vidstige.jadb.ShellProcessBuilder
56
import java.io.File
6-
import java.util.concurrent.Callable
7-
import java.util.concurrent.Executors
8-
9-
// return the input or output stream, depending on which first returns a value
10-
internal fun JadbDevice.run(command: String, su: Boolean = false) = with(this.startCommand(command, su)) {
11-
Executors.newFixedThreadPool(2).let { service ->
12-
arrayOf(inputStream, errorStream).map { stream ->
13-
Callable { stream.bufferedReader().use { it.readLine() } }
14-
}.let { tasks -> service.invokeAny(tasks).also { service.shutdown() } }
15-
}
7+
8+
9+
internal fun JadbDevice.buildCommand(command: String, su: Boolean = true): ShellProcessBuilder {
10+
if (su) return shellProcessBuilder("su -c \'$command\'")
11+
12+
val args = command.split(" ") as ArrayList<String>
13+
val cmd = args.removeFirst()
14+
15+
return shellProcessBuilder(cmd, *args.toTypedArray())
16+
}
17+
18+
internal fun JadbDevice.run(command: String, su: Boolean = true): Int {
19+
return this.buildCommand(command, su).start().waitFor()
1620
}
1721

1822
internal fun JadbDevice.hasSu() =

src/main/kotlin/app/revanced/utils/adb/Constants.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal object Constants {
2424

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

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

0 commit comments

Comments
 (0)