Skip to content

Commit eb483ca

Browse files
authored
fix: Make ShellCommandRunner run without root (#101)
1 parent 93482dc commit eb483ca

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

library/src/commonMain/kotlin/app/revanced/library/installation/command/AdbShellCommandRunner.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class AdbShellCommandRunner : ShellCommandRunner {
3535
override fun runCommand(command: String) = device.shellProcessBuilder(command).start().let { process ->
3636
object : RunResult {
3737
override val exitCode by lazy { process.waitFor() }
38-
override val output by lazy { process.inputStream.bufferedReader().readText() }
38+
override val output by lazy { process.inputStream.bufferedReader().readText().removeSuffix("\n") }
3939
override val error by lazy { process.errorStream.bufferedReader().readText() }
4040

4141
override fun waitFor() {
@@ -44,7 +44,7 @@ class AdbShellCommandRunner : ShellCommandRunner {
4444
}
4545
}
4646

47-
override fun hasRootPermission(): Boolean = invoke("whoami").exitCode == 0
47+
override fun hasRootPermission(): Boolean = invoke("su -c whoami").exitCode == 0
4848

4949
override fun write(content: InputStream, targetFilePath: String) =
5050
device.push(content, System.currentTimeMillis(), 644, RemoteFile(targetFilePath))

library/src/commonMain/kotlin/app/revanced/library/installation/command/ShellCommandRunner.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ abstract class ShellCommandRunner internal constructor() {
5555
*/
5656
internal operator fun invoke(
5757
command: String,
58-
) = runCommand("su -c \'$command\'")
58+
) = runCommand(command)
5959
}

library/src/commonMain/kotlin/app/revanced/library/installation/installer/RootInstaller.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ abstract class RootInstaller internal constructor(
100100
/**
101101
* Runs a command on the device.
102102
*/
103-
protected operator fun String.invoke() = shellCommandRunner(this)
103+
protected operator fun String.invoke() = shellCommandRunner("su -c \'$this\'")
104104

105105
/**
106106
* Moves the given file to the given [targetFilePath].

0 commit comments

Comments
 (0)