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

Commit a5e76102 authored by Svetoslav Ganov's avatar Svetoslav Ganov Committed by android-build-merger
Browse files

Merge "Throw on revoked location permission - framework" into pi-dev am: 4acd39d3

am: d16a343e

Change-Id: Ia24bf580203f3155e5a21236739a0e9d4de16685
parents c1b52efc d16a343e
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -1753,7 +1753,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);
        }
+9 −5
Original line number Diff line number Diff line
@@ -40,17 +40,19 @@ import java.util.List;
 */
public final class LocationAccessPolicy {
    private static final String LOG_TAG = LocationAccessPolicy.class.getSimpleName();

    /**
     * API to determine if the caller has permissions to get cell location.
     *
     * @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 {
        Trace.beginSection("TelephonyLocationCheck");
            int uid, int pid, boolean throwOnDeniedPermission) throws SecurityException {
        Trace.beginSection("TelephonyLohcationCheck");
        try {
            // Always allow the phone process to access location. This avoid breaking legacy code
            // that rely on public-facing APIs to access cell location, and it doesn't create a
@@ -65,9 +67,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 (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(