Revert "manager: Optimized import, optimized all libsu shell calls, and fixed WebUI memory leaks Partial modification (#369)"
This reverts commit c3533861f2.
Resolved delayed access to globally mounted storage spaces
Co-authored-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
This commit is contained in:
@@ -33,6 +33,18 @@ private val ksuDaemonPath by lazy {
|
|||||||
"${ksuApp.applicationInfo.nativeLibraryDir}${File.separator}libzakozako.so"
|
"${ksuApp.applicationInfo.nativeLibraryDir}${File.separator}libzakozako.so"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
object KsuCli {
|
||||||
|
val SHELL: Shell = createRootShell()
|
||||||
|
val GLOBAL_MNT_SHELL: Shell = createRootShell(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getRootShell(globalMnt: Boolean = false): Shell {
|
||||||
|
return if (globalMnt) KsuCli.GLOBAL_MNT_SHELL else {
|
||||||
|
KsuCli.SHELL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline fun <T> withNewRootShell(
|
inline fun <T> withNewRootShell(
|
||||||
globalMnt: Boolean = false,
|
globalMnt: Boolean = false,
|
||||||
block: Shell.() -> T
|
block: Shell.() -> T
|
||||||
@@ -84,7 +96,7 @@ fun execKsud(args: String, newShell: Boolean = false): Boolean {
|
|||||||
ShellUtils.fastCmdResult(this, "$ksuDaemonPath $args")
|
ShellUtils.fastCmdResult(this, "$ksuDaemonPath $args")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ShellUtils.fastCmdResult("$ksuDaemonPath $args")
|
ShellUtils.fastCmdResult(getRootShell(), "$ksuDaemonPath $args")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,8 +108,9 @@ fun install() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun listModules(): String {
|
fun listModules(): String {
|
||||||
|
val shell = getRootShell()
|
||||||
val out =
|
val out =
|
||||||
Shell.cmd("$ksuDaemonPath module list").to(ArrayList(), null).exec().out
|
shell.newJob().add("$ksuDaemonPath module list").to(ArrayList(), null).exec().out
|
||||||
return out.joinToString("\n").ifBlank { "[]" }
|
return out.joinToString("\n").ifBlank { "[]" }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,17 +324,22 @@ fun installBoot(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun reboot(reason: String = "") {
|
fun reboot(reason: String = "") {
|
||||||
|
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.fastCmdResult("/system/bin/input keyevent 26")
|
ShellUtils.fastCmd(shell, "/system/bin/input keyevent 26")
|
||||||
}
|
}
|
||||||
ShellUtils.fastCmdResult("/system/bin/svc power reboot $reason || /system/bin/reboot $reason")
|
ShellUtils.fastCmd(shell, "/system/bin/svc power reboot $reason || /system/bin/reboot $reason")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun rootAvailable() = Shell.isAppGrantedRoot() == true
|
fun rootAvailable(): Boolean {
|
||||||
|
val shell = getRootShell()
|
||||||
|
return shell.isRoot
|
||||||
|
}
|
||||||
|
|
||||||
fun isAbDevice(): Boolean {
|
fun isAbDevice(): Boolean {
|
||||||
return ShellUtils.fastCmd("getprop ro.build.ab_update").trim().toBoolean()
|
val shell = getRootShell()
|
||||||
|
return ShellUtils.fastCmd(shell, "getprop ro.build.ab_update").trim().toBoolean()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isInitBoot(): Boolean {
|
fun isInitBoot(): Boolean {
|
||||||
@@ -329,77 +347,91 @@ fun isInitBoot(): Boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getCurrentKmi(): String = withContext(Dispatchers.IO) {
|
suspend fun getCurrentKmi(): String = withContext(Dispatchers.IO) {
|
||||||
|
val shell = getRootShell()
|
||||||
val cmd = "boot-info current-kmi"
|
val cmd = "boot-info current-kmi"
|
||||||
ShellUtils.fastCmd("$ksuDaemonPath $cmd")
|
ShellUtils.fastCmd(shell, "$ksuDaemonPath $cmd")
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getSupportedKmis(): List<String> = withContext(Dispatchers.IO) {
|
suspend fun getSupportedKmis(): List<String> = withContext(Dispatchers.IO) {
|
||||||
|
val shell = getRootShell()
|
||||||
val cmd = "boot-info supported-kmi"
|
val cmd = "boot-info supported-kmi"
|
||||||
val out = Shell.cmd("$ksuDaemonPath $cmd").to(ArrayList(), null).exec().out
|
val out = shell.newJob().add("$ksuDaemonPath $cmd").to(ArrayList(), null).exec().out
|
||||||
out.filter { it.isNotBlank() }.map { it.trim() }
|
out.filter { it.isNotBlank() }.map { it.trim() }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hasMagisk(): Boolean {
|
fun hasMagisk(): Boolean {
|
||||||
val result = ShellUtils.fastCmdResult("which magisk")
|
val shell = getRootShell(true)
|
||||||
Log.i(TAG, "has magisk: $result")
|
val result = shell.newJob().add("which magisk").exec()
|
||||||
return result
|
Log.i(TAG, "has magisk: ${result.isSuccess}")
|
||||||
|
return result.isSuccess
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isSepolicyValid(rules: String?): Boolean {
|
fun isSepolicyValid(rules: String?): Boolean {
|
||||||
if (rules == null) {
|
if (rules == null) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
val shell = getRootShell()
|
||||||
val result =
|
val result =
|
||||||
Shell.cmd("$ksuDaemonPath sepolicy check '$rules'").to(ArrayList(), null)
|
shell.newJob().add("$ksuDaemonPath sepolicy check '$rules'").to(ArrayList(), null)
|
||||||
.exec()
|
.exec()
|
||||||
return result.isSuccess
|
return result.isSuccess
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getSepolicy(pkg: String): String {
|
fun getSepolicy(pkg: String): String {
|
||||||
|
val shell = getRootShell()
|
||||||
val result =
|
val result =
|
||||||
Shell.cmd("$ksuDaemonPath profile get-sepolicy $pkg").to(ArrayList(), null)
|
shell.newJob().add("$ksuDaemonPath profile get-sepolicy $pkg").to(ArrayList(), null)
|
||||||
.exec()
|
.exec()
|
||||||
Log.i(TAG, "code: ${result.code}, out: ${result.out}, err: ${result.err}")
|
Log.i(TAG, "code: ${result.code}, out: ${result.out}, err: ${result.err}")
|
||||||
return result.out.joinToString("\n")
|
return result.out.joinToString("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setSepolicy(pkg: String, rules: String): Boolean {
|
fun setSepolicy(pkg: String, rules: String): Boolean {
|
||||||
val result = Shell.cmd("$ksuDaemonPath profile set-sepolicy $pkg '$rules'")
|
val shell = getRootShell()
|
||||||
|
val result = shell.newJob().add("$ksuDaemonPath profile set-sepolicy $pkg '$rules'")
|
||||||
.to(ArrayList(), null).exec()
|
.to(ArrayList(), null).exec()
|
||||||
Log.i(TAG, "set sepolicy result: ${result.code}")
|
Log.i(TAG, "set sepolicy result: ${result.code}")
|
||||||
return result.isSuccess
|
return result.isSuccess
|
||||||
}
|
}
|
||||||
|
|
||||||
fun listAppProfileTemplates(): List<String> {
|
fun listAppProfileTemplates(): List<String> {
|
||||||
return Shell.cmd("$ksuDaemonPath profile list-templates").to(ArrayList(), null)
|
val shell = getRootShell()
|
||||||
|
return shell.newJob().add("$ksuDaemonPath profile list-templates").to(ArrayList(), null)
|
||||||
.exec().out
|
.exec().out
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAppProfileTemplate(id: String): String {
|
fun getAppProfileTemplate(id: String): String {
|
||||||
return Shell.cmd("$ksuDaemonPath profile get-template '${id}'")
|
val shell = getRootShell()
|
||||||
|
return shell.newJob().add("$ksuDaemonPath profile get-template '${id}'")
|
||||||
.to(ArrayList(), null).exec().out.joinToString("\n")
|
.to(ArrayList(), null).exec().out.joinToString("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setAppProfileTemplate(id: String, template: String): Boolean {
|
fun setAppProfileTemplate(id: String, template: String): Boolean {
|
||||||
|
val shell = getRootShell()
|
||||||
val escapedTemplate = template.replace("\"", "\\\"")
|
val escapedTemplate = template.replace("\"", "\\\"")
|
||||||
val cmd = """$ksuDaemonPath profile set-template "$id" "$escapedTemplate'""""
|
val cmd = """$ksuDaemonPath profile set-template "$id" "$escapedTemplate'""""
|
||||||
return Shell.cmd(cmd)
|
return shell.newJob().add(cmd)
|
||||||
.to(ArrayList(), null).exec().isSuccess
|
.to(ArrayList(), null).exec().isSuccess
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteAppProfileTemplate(id: String): Boolean {
|
fun deleteAppProfileTemplate(id: String): Boolean {
|
||||||
return Shell.cmd("$ksuDaemonPath profile delete-template '${id}'")
|
val shell = getRootShell()
|
||||||
|
return shell.newJob().add("$ksuDaemonPath profile delete-template '${id}'")
|
||||||
.to(ArrayList(), null).exec().isSuccess
|
.to(ArrayList(), null).exec().isSuccess
|
||||||
}
|
}
|
||||||
|
|
||||||
fun forceStopApp(packageName: String) {
|
fun forceStopApp(packageName: String) {
|
||||||
val result = Shell.cmd("am force-stop $packageName").exec()
|
val shell = getRootShell()
|
||||||
|
val result = shell.newJob().add("am force-stop $packageName").exec()
|
||||||
Log.i(TAG, "force stop $packageName result: $result")
|
Log.i(TAG, "force stop $packageName result: $result")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun launchApp(packageName: String) {
|
fun launchApp(packageName: String) {
|
||||||
|
|
||||||
|
val shell = getRootShell()
|
||||||
val result =
|
val result =
|
||||||
Shell.cmd("cmd package resolve-activity --brief $packageName | tail -n 1 | xargs cmd activity start-activity -n")
|
shell.newJob()
|
||||||
|
.add("cmd package resolve-activity --brief $packageName | tail -n 1 | xargs cmd activity start-activity -n")
|
||||||
.exec()
|
.exec()
|
||||||
Log.i(TAG, "launch $packageName result: $result")
|
Log.i(TAG, "launch $packageName result: $result")
|
||||||
}
|
}
|
||||||
@@ -414,31 +446,45 @@ val suSFSDaemonPath by lazy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getSuSFS(): String {
|
fun getSuSFS(): String {
|
||||||
return ShellUtils.fastCmd("$suSFSDaemonPath support")
|
val shell = getRootShell()
|
||||||
|
val result = ShellUtils.fastCmd(shell, "$suSFSDaemonPath support")
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getSuSFSVersion(): String {
|
fun getSuSFSVersion(): String {
|
||||||
return ShellUtils.fastCmd("$suSFSDaemonPath version")
|
val shell = getRootShell()
|
||||||
|
val result = ShellUtils.fastCmd(shell, "$suSFSDaemonPath version")
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getSuSFSVariant(): String {
|
fun getSuSFSVariant(): String {
|
||||||
return ShellUtils.fastCmd("$suSFSDaemonPath variant")
|
val shell = getRootShell()
|
||||||
|
val result = ShellUtils.fastCmd(shell, "$suSFSDaemonPath variant")
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getSuSFSFeatures(): String {
|
fun getSuSFSFeatures(): String {
|
||||||
return ShellUtils.fastCmd("$suSFSDaemonPath features")
|
val shell = getRootShell()
|
||||||
|
val result = ShellUtils.fastCmd(shell, "$suSFSDaemonPath features")
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
fun susfsSUS_SU_0(): String {
|
fun susfsSUS_SU_0(): String {
|
||||||
return ShellUtils.fastCmd("$suSFSDaemonPath sus_su 0")
|
val shell = getRootShell()
|
||||||
|
val result = ShellUtils.fastCmd(shell, "$suSFSDaemonPath sus_su 0")
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
fun susfsSUS_SU_2(): String {
|
fun susfsSUS_SU_2(): String {
|
||||||
return ShellUtils.fastCmd("$suSFSDaemonPath sus_su 2")
|
val shell = getRootShell()
|
||||||
|
val result = ShellUtils.fastCmd(shell, "$suSFSDaemonPath sus_su 2")
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
fun susfsSUS_SU_Mode(): String {
|
fun susfsSUS_SU_Mode(): String {
|
||||||
return ShellUtils.fastCmd("$suSFSDaemonPath sus_su mode")
|
val shell = getRootShell()
|
||||||
|
val result = ShellUtils.fastCmd(shell, "$suSFSDaemonPath sus_su mode")
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
val kpmmgrPath by lazy {
|
val kpmmgrPath by lazy {
|
||||||
|
|||||||
Reference in New Issue
Block a user