manager: don't create root shell everytime. this should close #361. MeiZu kernel seems cache something in execve syscall, which will cause double free in kernel.

This commit is contained in:
tiann
2023-04-11 12:56:07 +08:00
parent 2f8373f9c5
commit d065a7ca22
2 changed files with 15 additions and 7 deletions

View File

@@ -21,6 +21,14 @@ private fun getKsuDaemonPath(): String {
return ksuApp.applicationInfo.nativeLibraryDir + File.separator + "libksud.so" return ksuApp.applicationInfo.nativeLibraryDir + File.separator + "libksud.so"
} }
object KsuCli {
val SHELL: Shell = createRootShell()
}
fun getRootShell(): Shell {
return KsuCli.SHELL
}
fun createRootShell(): Shell { fun createRootShell(): Shell {
Shell.enableVerboseLogging = BuildConfig.DEBUG Shell.enableVerboseLogging = BuildConfig.DEBUG
val builder = Shell.Builder.create() val builder = Shell.Builder.create()
@@ -33,7 +41,7 @@ fun createRootShell(): Shell {
} }
fun execKsud(args: String): Boolean { fun execKsud(args: String): Boolean {
val shell = createRootShell() val shell = getRootShell()
return ShellUtils.fastCmdResult(shell, "${getKsuDaemonPath()} $args") return ShellUtils.fastCmdResult(shell, "${getKsuDaemonPath()} $args")
} }
@@ -44,7 +52,7 @@ fun install() {
} }
fun listModules(): String { fun listModules(): String {
val shell = createRootShell() val shell = getRootShell()
val out = shell.newJob().add("${getKsuDaemonPath()} module list").to(ArrayList(), null).exec().out val out = shell.newJob().add("${getKsuDaemonPath()} module list").to(ArrayList(), null).exec().out
return out.joinToString("\n").ifBlank { "[]" } return out.joinToString("\n").ifBlank { "[]" }
@@ -77,7 +85,7 @@ fun installModule(uri: Uri, onFinish: (Boolean)->Unit, onOutput: (String) -> Uni
} }
val cmd = "module install ${file.absolutePath}" val cmd = "module install ${file.absolutePath}"
val shell = createRootShell() val shell = getRootShell()
val callbackList: CallbackList<String?> = object : CallbackList<String?>() { val callbackList: CallbackList<String?> = object : CallbackList<String?>() {
override fun onAddElement(s: String?) { override fun onAddElement(s: String?) {
@@ -96,7 +104,7 @@ fun installModule(uri: Uri, onFinish: (Boolean)->Unit, onOutput: (String) -> Uni
} }
fun reboot(reason: String = "") { fun reboot(reason: String = "") {
val shell = createRootShell() val shell = getRootShell()
if (reason == "recovery") { if (reason == "recovery") {
// KEYCODE_POWER = 26, hide incorrect "Factory data reset" message // KEYCODE_POWER = 26, hide incorrect "Factory data reset" message
ShellUtils.fastCmd(shell, "/system/bin/input keyevent 26") ShellUtils.fastCmd(shell, "/system/bin/input keyevent 26")
@@ -105,13 +113,13 @@ fun reboot(reason: String = "") {
} }
fun overlayFsAvailable(): Boolean { fun overlayFsAvailable(): Boolean {
val shell = createRootShell() val shell = getRootShell()
// check /proc/filesystems // check /proc/filesystems
return ShellUtils.fastCmdResult(shell, "cat /proc/filesystems | grep overlay") return ShellUtils.fastCmdResult(shell, "cat /proc/filesystems | grep overlay")
} }
fun hasMagisk(): Boolean { fun hasMagisk(): Boolean {
val shell = createRootShell() val shell = getRootShell()
val result = shell.newJob().add("nsenter --mount=/proc/1/ns/mnt which magisk").exec() val result = shell.newJob().add("nsenter --mount=/proc/1/ns/mnt which magisk").exec()
Log.i(TAG, "has magisk: ${result.isSuccess}") Log.i(TAG, "has magisk: ${result.isSuccess}")
return result.isSuccess return result.isSuccess

View File

@@ -28,7 +28,7 @@ fun getBugreportFile(context: Context): File {
val appListFile = File(bugreportDir, "app_list.txt") val appListFile = File(bugreportDir, "app_list.txt")
val propFile = File(bugreportDir, "props.txt") val propFile = File(bugreportDir, "props.txt")
val shell = createRootShell() val shell = getRootShell()
shell.newJob().add("dmesg > ${dmesgFile.absolutePath}").exec() shell.newJob().add("dmesg > ${dmesgFile.absolutePath}").exec()
shell.newJob().add("logcat -d > ${logcatFile.absolutePath}").exec() shell.newJob().add("logcat -d > ${logcatFile.absolutePath}").exec()