@@ -159,15 +159,20 @@ class AppDetailBottomSheet : BottomSheetDialogFragment() {
159159 lifecycleScope.launch {
160160 // Load detailed background state via root commands
161161 val (runInBg, runAnyInBg) = withContext(Dispatchers .IO ) {
162- if (executor != null ) {
163- val runInBgResult = executor!! .execute(" appops get $packageName RUN_IN_BACKGROUND" )
164- val runAnyInBgResult = executor!! .execute(" appops get $packageName RUN_ANY_IN_BACKGROUND" )
162+ val exec = executor
163+ if (exec != null ) {
164+ val runInBgResult = exec.execute(" appops get $packageName RUN_IN_BACKGROUND" )
165+ val runAnyInBgResult = exec.execute(" appops get $packageName RUN_ANY_IN_BACKGROUND" )
166+
167+ val runInBgOutput = runInBgResult.getOrNull() ? : runInBgResult.exceptionOrNull()?.message ? : " "
168+ val runAnyInBgOutput = runAnyInBgResult.getOrNull() ? : runAnyInBgResult.exceptionOrNull()?.message ? : " "
169+
165170 Pair (
166- parseAppOpsOutput(runInBgResult.getOrDefault( " " ) ),
167- parseAppOpsOutput(runAnyInBgResult.getOrDefault( " " ) )
171+ parseAppOpsOutput(runInBgOutput ),
172+ parseAppOpsOutput(runAnyInBgOutput )
168173 )
169174 } else {
170- Pair (" N/A " , " N/A " )
175+ Pair (" No Root " , " No Root " )
171176 }
172177 }
173178
@@ -176,12 +181,16 @@ class AppDetailBottomSheet : BottomSheetDialogFragment() {
176181 }
177182
178183 private fun parseAppOpsOutput (output : String ): String {
184+ // Output format: "RUN_IN_BACKGROUND: allow" or "RUN_IN_BACKGROUND: allow; time=..."
185+ val lowerOutput = output.lowercase()
179186 return when {
180- output.contains(" ignore" ) -> " ignore"
181- output.contains(" deny" ) -> " deny"
182- output.contains(" allow" ) -> " allow"
183- output.contains(" default" ) -> " default"
184- else -> " unknown"
187+ lowerOutput.contains(" : ignore" ) || lowerOutput.contains(" :ignore" ) -> " ignore"
188+ lowerOutput.contains(" : deny" ) || lowerOutput.contains(" :deny" ) -> " deny"
189+ lowerOutput.contains(" : allow" ) || lowerOutput.contains(" :allow" ) -> " allow"
190+ lowerOutput.contains(" : default" ) || lowerOutput.contains(" :default" ) -> " default"
191+ lowerOutput.contains(" no operations" ) -> " default"
192+ output.isBlank() -> " error"
193+ else -> output.trim().take(20 ) // Show raw output for debug
185194 }
186195 }
187196
0 commit comments