Ensure /system/bin is in PATH

This commit is contained in:
Mygod
2020-07-28 04:22:33 +08:00
parent 4675b1d9d3
commit f226eb8a05
2 changed files with 11 additions and 4 deletions

View File

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