fix: Make ShellCommandRunner run without root

Currently, every command run by a ShellCommandRunner will be run with su (root required). With this PR, root will only be required from a RootInstaller.
Also remove latest \n from shell output
This commit is contained in:
brosssh
2025-05-29 10:19:16 +02:00
parent 5df2bb81bf
commit 7db4942bba
3 changed files with 4 additions and 4 deletions

View File

@@ -35,7 +35,7 @@ class AdbShellCommandRunner : ShellCommandRunner {
override fun runCommand(command: String) = device.shellProcessBuilder(command).start().let { process -> override fun runCommand(command: String) = device.shellProcessBuilder(command).start().let { process ->
object : RunResult { object : RunResult {
override val exitCode by lazy { process.waitFor() } override val exitCode by lazy { process.waitFor() }
override val output by lazy { process.inputStream.bufferedReader().readText() } override val output by lazy { process.inputStream.bufferedReader().readText().removeSuffix("\n") }
override val error by lazy { process.errorStream.bufferedReader().readText() } override val error by lazy { process.errorStream.bufferedReader().readText() }
override fun waitFor() { override fun waitFor() {
@@ -44,7 +44,7 @@ class AdbShellCommandRunner : ShellCommandRunner {
} }
} }
override fun hasRootPermission(): Boolean = invoke("whoami").exitCode == 0 override fun hasRootPermission(): Boolean = invoke("su -c whoami").exitCode == 0
override fun write(content: InputStream, targetFilePath: String) = override fun write(content: InputStream, targetFilePath: String) =
device.push(content, System.currentTimeMillis(), 644, RemoteFile(targetFilePath)) device.push(content, System.currentTimeMillis(), 644, RemoteFile(targetFilePath))

View File

@@ -55,5 +55,5 @@ abstract class ShellCommandRunner internal constructor() {
*/ */
internal operator fun invoke( internal operator fun invoke(
command: String, command: String,
) = runCommand("su -c \'$command\'") ) = runCommand(command)
} }

View File

@@ -100,7 +100,7 @@ abstract class RootInstaller internal constructor(
/** /**
* Runs a command on the device. * Runs a command on the device.
*/ */
protected operator fun String.invoke() = shellCommandRunner(this) protected operator fun String.invoke() = shellCommandRunner("su -c \'$this\'")
/** /**
* Moves the given file to the given [targetFilePath]. * Moves the given file to the given [targetFilePath].