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

Commit 16276a48 authored by Wei Wang's avatar Wei Wang
Browse files

Use checkOp instead noteOp for location permission checks.

Also don't report location access in getLastLocation() unless there
exists a location that can be delivered to the client.

Bug: 123533751
Bug: 122748680
Test: Manual
Change-Id: I62897cefbfb35422a076c9a5cd0e1d0df62a39b1
parent 1a9862c9
Loading
Loading
Loading
Loading
+17 −13
Original line number Diff line number Diff line
@@ -1369,7 +1369,7 @@ public class LocationManagerService extends ILocationManager.Stub {
                }
            } else {
                if (!allowMonitoring
                        || mAppOps.noteOpNoThrow(op, mCallerIdentity.mUid,
                        || mAppOps.checkOpNoThrow(op, mCallerIdentity.mUid,
                        mCallerIdentity.mPackageName) != AppOpsManager.MODE_ALLOWED) {
                    mAppOps.finishOp(op, mCallerIdentity.mUid, mCallerIdentity.mPackageName);
                    return false;
@@ -1904,7 +1904,7 @@ public class LocationManagerService extends ILocationManager.Stub {
            int allowedResolutionLevel) {
        int op = resolutionLevelToOp(allowedResolutionLevel);
        if (op >= 0) {
            if (mAppOps.noteOp(op, uid, packageName) != AppOpsManager.MODE_ALLOWED) {
            if (mAppOps.checkOp(op, uid, packageName) != AppOpsManager.MODE_ALLOWED) {
                return false;
            }
        }
@@ -2549,13 +2549,6 @@ public class LocationManagerService extends ILocationManager.Stub {
                    return null;
                }

                if (!reportLocationAccessNoThrow(pid, uid, packageName, allowedResolutionLevel)) {
                    if (D) {
                        Log.d(TAG, "not returning last loc for no op app: "
                                + packageName);
                    }
                    return null;
                }

                // Figure out the provider. Either its explicitly request (deprecated API's),
                // or use the fused provider
@@ -2599,16 +2592,27 @@ public class LocationManagerService extends ILocationManager.Stub {
                    return null;
                }

                Location lastLocation = null;
                if (allowedResolutionLevel < RESOLUTION_LEVEL_FINE) {
                    Location noGPSLocation = location.getExtraLocation(
                            Location.EXTRA_NO_GPS_LOCATION);
                    if (noGPSLocation != null) {
                        return new Location(mLocationFudger.getOrCreate(noGPSLocation));
                        lastLocation = new Location(mLocationFudger.getOrCreate(noGPSLocation));
                    }
                } else {
                    return new Location(location);
                    lastLocation = new Location(location);
                }
                return null;
                // Don't report location access if there is no last location to deliver.
                if (lastLocation != null) {
                    if (!reportLocationAccessNoThrow(
                            pid, uid, packageName, allowedResolutionLevel)) {
                        if (D) {
                            Log.d(TAG, "not returning last loc for no op app: " + packageName);
                        }
                        lastLocation =  null;
                    }
                }
                return lastLocation;
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
@@ -3249,7 +3253,7 @@ public class LocationManagerService extends ILocationManager.Stub {
    // Mock Providers

    private boolean canCallerAccessMockLocation(String opPackageName) {
        return mAppOps.noteOp(AppOpsManager.OP_MOCK_LOCATION, Binder.getCallingUid(),
        return mAppOps.checkOp(AppOpsManager.OP_MOCK_LOCATION, Binder.getCallingUid(),
                opPackageName) == AppOpsManager.MODE_ALLOWED;
    }