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

Commit 9a34dd68 authored by Nathan Harold's avatar Nathan Harold Committed by Automerger Merge Worker
Browse files

Merge "[BACKPORT] Improve location checks in TelephonyRegistry" into rvc-dev...

Merge "[BACKPORT] Improve location checks in TelephonyRegistry" into rvc-dev am: 21a19167 am: c96eba62

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11589690

Change-Id: I6f2f6ce14f2aa62f3b0034b19852426b53239d96
parents 7b4ee3d5 c96eba62
Loading
Loading
Loading
Loading
+31 −24
Original line number Original line Diff line number Diff line
@@ -315,11 +315,10 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
    private List<Map<Pair<Integer, ApnSetting>, PreciseDataConnectionState>>
    private List<Map<Pair<Integer, ApnSetting>, PreciseDataConnectionState>>
            mPreciseDataConnectionStates;
            mPreciseDataConnectionStates;


    static final int ENFORCE_COARSE_LOCATION_PERMISSION_MASK =
    // Starting in Q, almost all cellular location requires FINE location enforcement.
            PhoneStateListener.LISTEN_REGISTRATION_FAILURE
    // Prior to Q, cellular was available with COARSE location enforcement. Bits in this
                    | PhoneStateListener.LISTEN_BARRING_INFO;
    // list will be checked for COARSE on apps targeting P or earlier and FINE on Q or later.

    static final int ENFORCE_LOCATION_PERMISSION_MASK =
    static final int ENFORCE_FINE_LOCATION_PERMISSION_MASK =
            PhoneStateListener.LISTEN_CELL_LOCATION
            PhoneStateListener.LISTEN_CELL_LOCATION
                    | PhoneStateListener.LISTEN_CELL_INFO
                    | PhoneStateListener.LISTEN_CELL_INFO
                    | PhoneStateListener.LISTEN_REGISTRATION_FAILURE
                    | PhoneStateListener.LISTEN_REGISTRATION_FAILURE
@@ -376,7 +375,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
                                + " newDefaultPhoneId=" + newDefaultPhoneId);
                                + " newDefaultPhoneId=" + newDefaultPhoneId);
                    }
                    }


                    //Due to possible risk condition,(notify call back using the new
                    //Due to possible race condition,(notify call back using the new
                    //defaultSubId comes before new defaultSubId update) we need to recall all
                    //defaultSubId comes before new defaultSubId update) we need to recall all
                    //possible missed notify callback
                    //possible missed notify callback
                    synchronized (mRecords) {
                    synchronized (mRecords) {
@@ -909,7 +908,8 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
                    if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
                    if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
                        try {
                        try {
                            if (DBG_LOC) log("listen: mCellIdentity = " + mCellIdentity[phoneId]);
                            if (DBG_LOC) log("listen: mCellIdentity = " + mCellIdentity[phoneId]);
                            if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
                            if (checkCoarseLocationAccess(r, Build.VERSION_CODES.BASE)
                                    && checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
                                // null will be translated to empty CellLocation object in client.
                                // null will be translated to empty CellLocation object in client.
                                r.callback.onCellLocationChanged(mCellIdentity[phoneId]);
                                r.callback.onCellLocationChanged(mCellIdentity[phoneId]);
                            }
                            }
@@ -964,7 +964,8 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
                        try {
                        try {
                            if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
                            if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
                                    + mCellInfo.get(phoneId));
                                    + mCellInfo.get(phoneId));
                            if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
                            if (checkCoarseLocationAccess(r, Build.VERSION_CODES.BASE)
                                    && checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
                                r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
                                r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
                            }
                            }
                        } catch (RemoteException ex) {
                        } catch (RemoteException ex) {
@@ -1518,7 +1519,8 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
                for (Record r : mRecords) {
                for (Record r : mRecords) {
                    if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
                    if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
                            idMatch(r.subId, subId, phoneId) &&
                            idMatch(r.subId, subId, phoneId) &&
                            checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
                            (checkCoarseLocationAccess(r, Build.VERSION_CODES.BASE)
                                    && checkFineLocationAccess(r, Build.VERSION_CODES.Q))) {
                        try {
                        try {
                            if (DBG_LOC) {
                            if (DBG_LOC) {
                                log("notifyCellInfoForSubscriber: mCellInfo=" + cellInfo
                                log("notifyCellInfoForSubscriber: mCellInfo=" + cellInfo
@@ -1795,7 +1797,8 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
                for (Record r : mRecords) {
                for (Record r : mRecords) {
                    if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
                    if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
                            idMatch(r.subId, subId, phoneId) &&
                            idMatch(r.subId, subId, phoneId) &&
                            checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
                            (checkCoarseLocationAccess(r, Build.VERSION_CODES.BASE)
                                    && checkFineLocationAccess(r, Build.VERSION_CODES.Q))) {
                        try {
                        try {
                            if (DBG_LOC) {
                            if (DBG_LOC) {
                                log("notifyCellLocation: cellIdentity=" + cellIdentity
                                log("notifyCellLocation: cellIdentity=" + cellIdentity
@@ -2540,19 +2543,13 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
                .setCallingPid(Binder.getCallingPid())
                .setCallingPid(Binder.getCallingPid())
                .setCallingUid(Binder.getCallingUid());
                .setCallingUid(Binder.getCallingUid());


        boolean shouldCheckLocationPermissions = false;
        if ((events & ENFORCE_LOCATION_PERMISSION_MASK) != 0) {
        if ((events & ENFORCE_COARSE_LOCATION_PERMISSION_MASK) != 0) {
            locationQueryBuilder.setMinSdkVersionForCoarse(0);
            shouldCheckLocationPermissions = true;
        }

        if ((events & ENFORCE_FINE_LOCATION_PERMISSION_MASK) != 0) {
            // Everything that requires fine location started in Q. So far...
            // Everything that requires fine location started in Q. So far...
            locationQueryBuilder.setMinSdkVersionForFine(Build.VERSION_CODES.Q);
            locationQueryBuilder.setMinSdkVersionForFine(Build.VERSION_CODES.Q);
            shouldCheckLocationPermissions = true;
            // If we're enforcing fine starting in Q, we also want to enforce coarse even for
        }
            // older SDK versions.
            locationQueryBuilder.setMinSdkVersionForCoarse(0);


        if (shouldCheckLocationPermissions) {
            LocationAccessPolicy.LocationPermissionResult result =
            LocationAccessPolicy.LocationPermissionResult result =
                    LocationAccessPolicy.checkLocationPermission(
                    LocationAccessPolicy.checkLocationPermission(
                            mContext, locationQueryBuilder.build());
                            mContext, locationQueryBuilder.build());
@@ -2719,8 +2716,16 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
            try {
            try {
                if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
                if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
                        mServiceState[phoneId]);
                        mServiceState[phoneId]);
                ServiceState ss = new ServiceState(mServiceState[phoneId]);
                if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
                    r.callback.onServiceStateChanged(ss);
                } else if (checkCoarseLocationAccess(r, Build.VERSION_CODES.Q)) {
                    r.callback.onServiceStateChanged(
                            ss.createLocationInfoSanitizedCopy(false));
                } else {
                    r.callback.onServiceStateChanged(
                    r.callback.onServiceStateChanged(
                        new ServiceState(mServiceState[phoneId]));
                            ss.createLocationInfoSanitizedCopy(true));
                }
            } catch (RemoteException ex) {
            } catch (RemoteException ex) {
                mRemoveList.add(r.binder);
                mRemoveList.add(r.binder);
            }
            }
@@ -2765,7 +2770,8 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
                    log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
                    log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
                            + mCellInfo.get(phoneId));
                            + mCellInfo.get(phoneId));
                }
                }
                if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
                if (checkCoarseLocationAccess(r, Build.VERSION_CODES.BASE)
                        && checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
                    r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
                    r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
                }
                }
            } catch (RemoteException ex) {
            } catch (RemoteException ex) {
@@ -2831,7 +2837,8 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
                    log("checkPossibleMissNotify: onCellLocationChanged mCellIdentity = "
                    log("checkPossibleMissNotify: onCellLocationChanged mCellIdentity = "
                            + mCellIdentity[phoneId]);
                            + mCellIdentity[phoneId]);
                }
                }
                if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
                if (checkCoarseLocationAccess(r, Build.VERSION_CODES.BASE)
                        && checkFineLocationAccess(r, Build.VERSION_CODES.Q)) {
                    // null will be translated to empty CellLocation object in client.
                    // null will be translated to empty CellLocation object in client.
                    r.callback.onCellLocationChanged(mCellIdentity[phoneId]);
                    r.callback.onCellLocationChanged(mCellIdentity[phoneId]);
                }
                }