mirror of
https://github.com/ReVanced/revanced-library.git
synced 2026-01-11 13:56:17 +00:00
36 lines
974 B
Kotlin
36 lines
974 B
Kotlin
package app.revanced.library.adb
|
|
|
|
import se.vidstige.jadb.JadbDevice
|
|
import se.vidstige.jadb.RemoteFile
|
|
import se.vidstige.jadb.ShellProcessBuilder
|
|
import java.io.File
|
|
|
|
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,
|
|
) = this.buildCommand(command, su).start()
|
|
|
|
internal fun JadbDevice.hasSu() = this.run("whoami", true).waitFor() == 0
|
|
|
|
internal fun JadbDevice.push(
|
|
file: File,
|
|
targetFilePath: String,
|
|
) = push(file, RemoteFile(targetFilePath))
|
|
|
|
internal fun JadbDevice.createFile(
|
|
targetFile: String,
|
|
content: String,
|
|
) = push(content.byteInputStream(), System.currentTimeMillis(), 644, RemoteFile(targetFile))
|