Skip to content

Commit 70eadb8

Browse files
committed
Merge code
1 parent 6d7d729 commit 70eadb8

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

app/src/main/java/com/fankes/coloros/notify/utils/factory/FunctionFactory.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,19 @@ fun findPropString(key: String, default: String = "") = safeOf(default) {
329329
}
330330

331331
/**
332-
* 执行命令 - su
332+
* 是否有 Root 权限
333+
* @return [Boolean]
334+
*/
335+
val isRootAccess get() = safeOfFalse { Shell.rootAccess() }
336+
337+
/**
338+
* 执行命令
333339
* @param cmd 命令
340+
* @param isSu 是否使用 Root 权限执行 - 默认:是
334341
* @return [String] 执行结果
335342
*/
336-
fun execShellSu(cmd: String) = safeOfNothing {
337-
Shell.su(cmd).exec().out.let {
343+
fun execShell(cmd: String, isSu: Boolean = true) = safeOfNothing {
344+
(if (isSu) Shell.su(cmd) else Shell.sh(cmd)).exec().out.let {
338345
if (it.isNotEmpty()) it[0].trim() else ""
339346
}
340347
}

app/src/main/java/com/fankes/coloros/notify/utils/tool/SystemUITool.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ object SystemUITool {
8686
msg = "你确定要立即重启系统界面吗?\n\n" +
8787
"重启过程会黑屏并等待进入锁屏重新解锁。"
8888
confirmButton {
89-
execShellSu(cmd = "pgrep systemui").also { pid ->
89+
execShell(cmd = "pgrep systemui").also { pid ->
9090
if (pid.isNotBlank())
91-
execShellSu(cmd = "kill -9 $pid")
91+
execShell(cmd = "kill -9 $pid")
9292
else toast(msg = "ROOT 权限获取失败")
9393
}
9494
}

0 commit comments

Comments
 (0)