Shizuku-API
Shizuku-API copied to clipboard
Cannot access 'newProcess': it is private in 'Shizuku'
private fun runShellCommandWithShizuku(command: Array<String>): Pair<String, String> {
return try {
val clazz = Class.forName("rikka.shizuku.Shizuku")
val method = clazz.getDeclaredMethod("newProcess", Array<String>::class.java, Array<String>::class.java, String::class.java)
method.isAccessible = true
val remoteProcess = method.invoke(null, command, null, null) as rikka.shizuku.ShizukuRemoteProcess
val output = remoteProcess.inputStream.bufferedReader().use { it.readText() }
val error = remoteProcess.errorStream.bufferedReader().use { it.readText() }
remoteProcess.destroy()
Pair(output.trim(), error.trim())
} catch (exception: Exception) {
Pair("", "Exception: ${exception.message}")
}
}
I don't know why this is private, probably for security reasons. However, I find it pointless to go crazy with AIDL, binder, etc. to run a very simple command that you could run with adb. I expect an end user, when installing Shizuku, to understand the risks of incorrect use.
This is a workaround and gives you access to the private function. You shouldn't use it in production; it's not guaranteed to work.
Or use api version 12.2.0.
+1