Ensure /system/bin is in PATH
This commit is contained in:
@@ -20,12 +20,19 @@ import java.io.FileOutputStream
|
||||
import java.io.InterruptedIOException
|
||||
import java.util.concurrent.Executor
|
||||
|
||||
fun ProcessBuilder.fixPath(redirect: Boolean = false) = apply {
|
||||
environment().compute("PATH") { _, value ->
|
||||
if (value.isNullOrEmpty()) "/system/bin" else "$value:/system/bin"
|
||||
}
|
||||
redirectErrorStream(redirect)
|
||||
}
|
||||
|
||||
@Parcelize
|
||||
class Dump(val path: String, val cacheDir: File = app.deviceStorage.codeCacheDir) : RootCommandNoResult {
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
override suspend fun execute() = withContext(Dispatchers.IO) {
|
||||
FileOutputStream(path, true).use { out ->
|
||||
val process = ProcessBuilder("sh").redirectErrorStream(true).start()
|
||||
val process = ProcessBuilder("sh").fixPath(true).start()
|
||||
process.outputStream.bufferedWriter().use { commands ->
|
||||
// https://android.googlesource.com/platform/external/iptables/+/android-7.0.0_r1/iptables/Android.mk#34
|
||||
val iptablesSave = if (Build.VERSION.SDK_INT < 24) File(cacheDir, "iptables-save").absolutePath.also {
|
||||
@@ -191,7 +198,7 @@ class SettingsGlobalPut(val name: String, val value: String) : RootCommandNoResu
|
||||
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
override suspend fun execute() = withContext(Dispatchers.IO) {
|
||||
val process = ProcessBuilder("settings", "put", "global", name, value).redirectErrorStream(true).start()
|
||||
val process = ProcessBuilder("settings", "put", "global", name, value).fixPath(true).start()
|
||||
val error = process.inputStream.bufferedReader().readText()
|
||||
check(process.waitFor() == 0)
|
||||
if (error.isNotEmpty()) throw RemoteException(error)
|
||||
|
||||
Reference in New Issue
Block a user