[Settings] fix Settings crash on App info for archived apps

For archived apps, isClearRestrictionAllowed (introduced in ag/26048774)
can throw NameNotFoundException, which causes Settings app to crash if
uncaught. This CL fixes that.

Test: manual by archiving an app and then try to go to it's app info
page
BUG: 332397754

Change-Id: I49a39dba36261f36215f0389ffe41523e8a2f4e8
This commit is contained in:
Songchun Fan
2024-04-02 14:26:30 -07:00
committed by Song Chun Fan
parent 27607a47a5
commit faeaa7650e

View File

@@ -20,6 +20,7 @@ import android.app.AppOpsManager
import android.app.ecm.EnhancedConfirmationManager
import android.content.Context
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.os.UserManager
import android.widget.Toast
import androidx.compose.runtime.Composable
@@ -180,7 +181,12 @@ private fun ApplicationInfo.shouldShowAccessRestrictedSettings(context: Context)
return if (android.permission.flags.Flags.enhancedConfirmationModeApisEnabled()
&& android.security.Flags.extendEcmToAllSettings()) {
val manager = context.getSystemService(EnhancedConfirmationManager::class.java)!!
manager.isClearRestrictionAllowed(packageName)
try {
manager.isClearRestrictionAllowed(packageName)
} catch (e: PackageManager.NameNotFoundException) {
// Package might have been archived
false
}
} else {
context.appOpsManager.noteOpNoThrow(
AppOpsManager.OP_ACCESS_RESTRICTED_SETTINGS, uid, packageName, null, null