From f2588f5a52aea96d9026ec58d7721f84c067bd89 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Apr 2026 09:30:24 +0000 Subject: [PATCH 1/5] Initial plan From 9074fa771542f12bced8a9194331263281b77957 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Apr 2026 09:33:37 +0000 Subject: [PATCH 2/5] fix: improve root access detection fallback Agent-Logs-Url: https://github.com/KitsunePie/AppErrorsTracking/sessions/5185e974-4067-41e1-9e70-b5dc47fbae7e Co-authored-by: fankes <37344460+fankes@users.noreply.github.com> --- .../apperrorstracking/utils/factory/FunctionFactory.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/module-app/src/main/java/com/fankes/apperrorstracking/utils/factory/FunctionFactory.kt b/module-app/src/main/java/com/fankes/apperrorstracking/utils/factory/FunctionFactory.kt index 5ea7876c..7788b9c6 100644 --- a/module-app/src/main/java/com/fankes/apperrorstracking/utils/factory/FunctionFactory.kt +++ b/module-app/src/main/java/com/fankes/apperrorstracking/utils/factory/FunctionFactory.kt @@ -418,7 +418,10 @@ fun Context.openApp(packageName: String = getPackageName(), userId: Int = 0) = r val isRootAccess get() = runCatching { @Suppress("DEPRECATION") Shell.rootAccess() -}.getOrNull() ?: false +}.getOrNull() == true || runCatching { + @Suppress("DEPRECATION") + Shell.su("id").exec().out.any { it.contains("uid=0") || it.trim() == "root" } +}.getOrNull() == true /** * 执行命令 @@ -454,4 +457,4 @@ fun Context.hideOrShowLauncherIcon(isShow: Boolean) { val Context.isLauncherIconShowing get() = packageManager?.getComponentEnabledSetting( ComponentName(packageName, "${BuildConfigWrapper.APPLICATION_ID}.Home") - ) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED \ No newline at end of file + ) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED From 445253bbf430a33a4e91af908ae47a5fc0471aa9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Apr 2026 09:35:00 +0000 Subject: [PATCH 3/5] refactor: harden root fallback detection check Agent-Logs-Url: https://github.com/KitsunePie/AppErrorsTracking/sessions/5185e974-4067-41e1-9e70-b5dc47fbae7e Co-authored-by: fankes <37344460+fankes@users.noreply.github.com> --- .../apperrorstracking/utils/factory/FunctionFactory.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/module-app/src/main/java/com/fankes/apperrorstracking/utils/factory/FunctionFactory.kt b/module-app/src/main/java/com/fankes/apperrorstracking/utils/factory/FunctionFactory.kt index 7788b9c6..dc10a39b 100644 --- a/module-app/src/main/java/com/fankes/apperrorstracking/utils/factory/FunctionFactory.kt +++ b/module-app/src/main/java/com/fankes/apperrorstracking/utils/factory/FunctionFactory.kt @@ -69,6 +69,9 @@ import java.text.DecimalFormat import java.text.SimpleDateFormat import java.util.Date import java.util.Locale +import java.util.concurrent.atomic.AtomicBoolean + +private val isRootAccessFallbackConfirmed = AtomicBoolean(false) /** * 当前系统环境是否为简体中文 @@ -418,9 +421,11 @@ fun Context.openApp(packageName: String = getPackageName(), userId: Int = 0) = r val isRootAccess get() = runCatching { @Suppress("DEPRECATION") Shell.rootAccess() -}.getOrNull() == true || runCatching { +}.getOrNull() == true || isRootAccessFallbackConfirmed.get() || runCatching { @Suppress("DEPRECATION") - Shell.su("id").exec().out.any { it.contains("uid=0") || it.trim() == "root" } + Shell.su("id").exec().out.any { Regex("\\buid=0\\b").containsMatchIn(it) }.also { + if (it) isRootAccessFallbackConfirmed.set(true) + } }.getOrNull() == true /** From 531fb09c83f1aa3645de5fbb845c9de09edd12ef Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Apr 2026 09:35:45 +0000 Subject: [PATCH 4/5] perf: reuse root uid regex pattern Agent-Logs-Url: https://github.com/KitsunePie/AppErrorsTracking/sessions/5185e974-4067-41e1-9e70-b5dc47fbae7e Co-authored-by: fankes <37344460+fankes@users.noreply.github.com> --- .../fankes/apperrorstracking/utils/factory/FunctionFactory.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/module-app/src/main/java/com/fankes/apperrorstracking/utils/factory/FunctionFactory.kt b/module-app/src/main/java/com/fankes/apperrorstracking/utils/factory/FunctionFactory.kt index dc10a39b..4e3a1d04 100644 --- a/module-app/src/main/java/com/fankes/apperrorstracking/utils/factory/FunctionFactory.kt +++ b/module-app/src/main/java/com/fankes/apperrorstracking/utils/factory/FunctionFactory.kt @@ -72,6 +72,7 @@ import java.util.Locale import java.util.concurrent.atomic.AtomicBoolean private val isRootAccessFallbackConfirmed = AtomicBoolean(false) +private val rootUidPattern = Regex("\\buid=0\\b") /** * 当前系统环境是否为简体中文 @@ -423,7 +424,7 @@ val isRootAccess get() = runCatching { Shell.rootAccess() }.getOrNull() == true || isRootAccessFallbackConfirmed.get() || runCatching { @Suppress("DEPRECATION") - Shell.su("id").exec().out.any { Regex("\\buid=0\\b").containsMatchIn(it) }.also { + Shell.su("id").exec().out.any { rootUidPattern.containsMatchIn(it) }.also { if (it) isRootAccessFallbackConfirmed.set(true) } }.getOrNull() == true From 0504cfe8612ad1ed7100c9985031c036b079bfd8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Apr 2026 09:38:11 +0000 Subject: [PATCH 5/5] refactor: extract synchronized root fallback check Agent-Logs-Url: https://github.com/KitsunePie/AppErrorsTracking/sessions/5185e974-4067-41e1-9e70-b5dc47fbae7e Co-authored-by: fankes <37344460+fankes@users.noreply.github.com> --- .../utils/factory/FunctionFactory.kt | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/module-app/src/main/java/com/fankes/apperrorstracking/utils/factory/FunctionFactory.kt b/module-app/src/main/java/com/fankes/apperrorstracking/utils/factory/FunctionFactory.kt index 4e3a1d04..d244103b 100644 --- a/module-app/src/main/java/com/fankes/apperrorstracking/utils/factory/FunctionFactory.kt +++ b/module-app/src/main/java/com/fankes/apperrorstracking/utils/factory/FunctionFactory.kt @@ -73,6 +73,17 @@ import java.util.concurrent.atomic.AtomicBoolean private val isRootAccessFallbackConfirmed = AtomicBoolean(false) private val rootUidPattern = Regex("\\buid=0\\b") +private val rootAccessCheckLock = Any() + +private fun hasRootAccessFallback() = synchronized(rootAccessCheckLock) { + if (isRootAccessFallbackConfirmed.get()) true + else runCatching { + @Suppress("DEPRECATION") + Shell.su("id").exec().out.any { rootUidPattern.containsMatchIn(it) }.also { + if (it) isRootAccessFallbackConfirmed.set(true) + } + }.getOrNull() == true +} /** * 当前系统环境是否为简体中文 @@ -422,12 +433,7 @@ fun Context.openApp(packageName: String = getPackageName(), userId: Int = 0) = r val isRootAccess get() = runCatching { @Suppress("DEPRECATION") Shell.rootAccess() -}.getOrNull() == true || isRootAccessFallbackConfirmed.get() || runCatching { - @Suppress("DEPRECATION") - Shell.su("id").exec().out.any { rootUidPattern.containsMatchIn(it) }.also { - if (it) isRootAccessFallbackConfirmed.set(true) - } -}.getOrNull() == true +}.getOrNull() == true || isRootAccessFallbackConfirmed.get() || hasRootAccessFallback() /** * 执行命令