fix: fix running commands not running

This commit is contained in:
oSumAtrIX 2023-08-24 17:51:31 +02:00
parent 52c3be23f2
commit 2c7fcaf4ad
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
3 changed files with 20 additions and 17 deletions

View File

@ -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() {

View File

@ -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() =

View File

@ -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()
}