Fix crash in LocationPermissionChecker when app is not installed.

AppOpsManager#noteOp can throw SecurityException in some cases (for
example, if the app is not installed). Don't crash the system when
this happens.

Test: None
Fix: 416189588
Flag: TEST_ONLY
Change-Id: Idf017ccf6b033ec80f4c4f3397cf4e417af7ad11
This commit is contained in:
Lorenzo Colitti 2025-06-25 01:15:44 -07:00
commit e988ae3208

View file

@ -221,8 +221,13 @@ public class LocationPermissionChecker {
private boolean noteAppOpAllowed(String op, String pkgName, @Nullable String featureId,
int uid, @Nullable String message) {
return mAppOpsManager.noteOp(op, uid, pkgName, featureId, message)
== AppOpsManager.MODE_ALLOWED;
try {
return mAppOpsManager.noteOp(op, uid, pkgName, featureId, message)
== AppOpsManager.MODE_ALLOWED;
} catch (SecurityException e) {
// Can happen, for example, if the app is not currently installed. // b/416189588
return false;
}
}
private void checkPackage(int uid, String pkgName)