diff options
| author | 2022-05-13 18:27:40 +0000 | |
|---|---|---|
| committer | 2022-05-13 18:27:40 +0000 | |
| commit | a9235c320813d6e4fe0ebe4f16361751c3a947eb (patch) | |
| tree | 3ca713aa952d3559316f59351e9f43296bcbe70e | |
| parent | b7715733a06c0acfcce1457c1d4355fe126423c5 (diff) | |
| parent | 3a70f7b6e64042034f480ff246099b33fc1eda4c (diff) | |
Merge "Add always full location check to LocationAccessPolicy" into tm-dev
| -rw-r--r-- | telephony/common/android/telephony/LocationAccessPolicy.java | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/telephony/common/android/telephony/LocationAccessPolicy.java b/telephony/common/android/telephony/LocationAccessPolicy.java index 9dfb0cc289ee..d4b6c91eb7a0 100644 --- a/telephony/common/android/telephony/LocationAccessPolicy.java +++ b/telephony/common/android/telephony/LocationAccessPolicy.java @@ -316,9 +316,11 @@ public final class LocationAccessPolicy { return LocationPermissionResult.ALLOWED; } - // Check the system-wide requirements. If the location main switch is off or - // the app's profile isn't in foreground, return a soft denial. - if (!checkSystemLocationAccess(context, query.callingUid, query.callingPid)) { + // Check the system-wide requirements. If the location main switch is off and the caller is + // not in the allowlist of apps that always have loation access or the app's profile + // isn't in the foreground, return a soft denial. + if (!checkSystemLocationAccess(context, query.callingUid, query.callingPid, + query.callingPackage)) { return LocationPermissionResult.DENIED_SOFT; } @@ -344,15 +346,16 @@ public final class LocationAccessPolicy { return LocationPermissionResult.ALLOWED; } - private static boolean checkManifestPermission(Context context, int pid, int uid, String permissionToCheck) { return context.checkPermission(permissionToCheck, pid, uid) == PackageManager.PERMISSION_GRANTED; } - private static boolean checkSystemLocationAccess(@NonNull Context context, int uid, int pid) { - if (!isLocationModeEnabled(context, UserHandle.getUserHandleForUid(uid).getIdentifier())) { + private static boolean checkSystemLocationAccess(@NonNull Context context, int uid, int pid, + @NonNull String callingPackage) { + if (!isLocationModeEnabled(context, UserHandle.getUserHandleForUid(uid).getIdentifier()) + && !isLocationBypassAllowed(context, callingPackage)) { if (DBG) Log.w(TAG, "Location disabled, failed, (" + uid + ")"); return false; } @@ -373,6 +376,16 @@ public final class LocationAccessPolicy { return locationManager.isLocationEnabledForUser(UserHandle.of(userId)); } + private static boolean isLocationBypassAllowed(@NonNull Context context, + @NonNull String callingPackage) { + for (String bypassPackage : getLocationBypassPackages(context)) { + if (callingPackage.equals(bypassPackage)) { + return true; + } + } + return false; + } + /** * @return An array of packages that are always allowed to access location. */ |