From e988ae3208444c83ca2ffcbeeb26d2b6e99312d4 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Wed, 25 Jun 2025 01:15:44 -0700 Subject: [PATCH] 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 --- .../net/module/util/LocationPermissionChecker.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/staticlibs/framework/com/android/net/module/util/LocationPermissionChecker.java b/staticlibs/framework/com/android/net/module/util/LocationPermissionChecker.java index e4d25cdf07..9e755599e1 100644 --- a/staticlibs/framework/com/android/net/module/util/LocationPermissionChecker.java +++ b/staticlibs/framework/com/android/net/module/util/LocationPermissionChecker.java @@ -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)