Merge "Add always full location check to LocationAccessPolicy" into tm-dev
This commit is contained in:
@@ -316,9 +316,11 @@ public final class LocationAccessPolicy {
|
|||||||
return LocationPermissionResult.ALLOWED;
|
return LocationPermissionResult.ALLOWED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the system-wide requirements. If the location main switch is off or
|
// Check the system-wide requirements. If the location main switch is off and the caller is
|
||||||
// the app's profile isn't in foreground, return a soft denial.
|
// not in the allowlist of apps that always have loation access or the app's profile
|
||||||
if (!checkSystemLocationAccess(context, query.callingUid, query.callingPid)) {
|
// isn't in the foreground, return a soft denial.
|
||||||
|
if (!checkSystemLocationAccess(context, query.callingUid, query.callingPid,
|
||||||
|
query.callingPackage)) {
|
||||||
return LocationPermissionResult.DENIED_SOFT;
|
return LocationPermissionResult.DENIED_SOFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -344,15 +346,16 @@ public final class LocationAccessPolicy {
|
|||||||
return LocationPermissionResult.ALLOWED;
|
return LocationPermissionResult.ALLOWED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static boolean checkManifestPermission(Context context, int pid, int uid,
|
private static boolean checkManifestPermission(Context context, int pid, int uid,
|
||||||
String permissionToCheck) {
|
String permissionToCheck) {
|
||||||
return context.checkPermission(permissionToCheck, pid, uid)
|
return context.checkPermission(permissionToCheck, pid, uid)
|
||||||
== PackageManager.PERMISSION_GRANTED;
|
== PackageManager.PERMISSION_GRANTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean checkSystemLocationAccess(@NonNull Context context, int uid, int pid) {
|
private static boolean checkSystemLocationAccess(@NonNull Context context, int uid, int pid,
|
||||||
if (!isLocationModeEnabled(context, UserHandle.getUserHandleForUid(uid).getIdentifier())) {
|
@NonNull String callingPackage) {
|
||||||
|
if (!isLocationModeEnabled(context, UserHandle.getUserHandleForUid(uid).getIdentifier())
|
||||||
|
&& !isLocationBypassAllowed(context, callingPackage)) {
|
||||||
if (DBG) Log.w(TAG, "Location disabled, failed, (" + uid + ")");
|
if (DBG) Log.w(TAG, "Location disabled, failed, (" + uid + ")");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -373,6 +376,16 @@ public final class LocationAccessPolicy {
|
|||||||
return locationManager.isLocationEnabledForUser(UserHandle.of(userId));
|
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.
|
* @return An array of packages that are always allowed to access location.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user