Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 56c4148e authored by Svet Ganov's avatar Svet Ganov Committed by Nathan Harold
Browse files

Throw on revoked location permission - framework

When we fixed proper handling of location permisison gating
sensitive telephony calls we stopped throwing a security
exception when the permission is not held by the caller.
While this is not a security issue there is no reason to
change this behavior which is checked by CTS. This CL starts
throwing a security exception if the permission is not held.

Test: atest android.permission.cts.NoLocationPermissionTest

bug: 74074103

Merged-In: Ic891d62b408c692f84a345f24503f7f25d583e35
Change-Id: Ic891d62b408c692f84a345f24503f7f25d583e35
(cherry picked from commit 33b15093)
parent c14a4be7
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -1789,7 +1789,8 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub {
        long token = Binder.clearCallingIdentity();
        try {
            return LocationAccessPolicy.canAccessCellLocation(mContext,
                    r.callingPackage, r.callerUid, r.callerPid);
                    r.callingPackage, r.callerUid, r.callerPid,
                    /*throwOnDeniedPermission*/ false);
        } finally {
            Binder.restoreCallingIdentity(token);
        }
+7 −5
Original line number Diff line number Diff line
@@ -48,10 +48,11 @@ public final class LocationAccessPolicy {
     * @param pkgName Package name of the application requesting access
     * @param uid The uid of the package
     * @param pid The pid of the package
     * @param throwOnDeniedPermission Whether to throw if the location permission is denied.
     * @return boolean true or false if permissions is granted
     */
    public static boolean canAccessCellLocation(@NonNull Context context, @NonNull String pkgName,
            int uid, int pid) throws SecurityException {
            int uid, int pid, boolean throwOnDeniedPermission) throws SecurityException {
        Trace.beginSection("TelephonyLocationCheck");
        try {
            // Always allow the phone process and system server to access location. This avoid
@@ -68,10 +69,11 @@ public final class LocationAccessPolicy {
            // where a legacy app the user is not using tracks their location.
            // Granting ACCESS_FINE_LOCATION to an app automatically grants it
            // ACCESS_COARSE_LOCATION.

            if (context.checkPermission(Manifest.permission.ACCESS_COARSE_LOCATION, pid, uid) ==
                    PackageManager.PERMISSION_DENIED) {
                if (DBG) Log.w(TAG, "Permission checked failed (" + pid + "," + uid + ")");
            if (throwOnDeniedPermission) {
                context.enforcePermission(Manifest.permission.ACCESS_COARSE_LOCATION,
                        pid, uid, "canAccessCellLocation");
            } else if (context.checkPermission(Manifest.permission.ACCESS_COARSE_LOCATION,
                    pid, uid) == PackageManager.PERMISSION_DENIED) {
                return false;
            }
            final int opCode = AppOpsManager.permissionToOpCode(