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

Commit 6a3887bb authored by Sewook Seo's avatar Sewook Seo
Browse files

Register BarringInfo and RegistrationFailed without location permission.

Allows listeners to register BarringInfoListener & RegisRegistrationFailedListener without location access permission.
In case of this, they will receive location sanitized data as a callback.
With this change, Listeners don't need to possess unrequired location permission.

Bug: 259614273
Test: atest FrameworksTelephonyTests, device test b/263097627
Change-Id: I6aa19210e8de8035ee13a5223f126e812f0f00ad
parent 384234e2
Loading
Loading
Loading
Loading
+19 −8
Original line number Diff line number Diff line
@@ -104,6 +104,10 @@ public class TelephonyCallback {
    /**
     * Event for changes to the network service state (cellular).
     *
     * <p>Requires {@link Manifest.permission#ACCESS_FINE_LOCATION} or {@link
     * Manifest.permission#ACCESS_COARSE_LOCATION} depending on the accuracy of the location info
     * listeners want to get.
     *
     * @hide
     * @see ServiceStateListener#onServiceStateChanged
     * @see ServiceState
@@ -483,8 +487,9 @@ public class TelephonyCallback {
     * <p>Requires permission {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE} or
     * the calling app has carrier privileges (see {@link TelephonyManager#hasCarrierPrivileges}).
     *
     * <p>Also requires the {@link Manifest.permission#ACCESS_FINE_LOCATION} permission, regardless
     * of whether the calling app has carrier privileges.
     * <p>Requires the {@link Manifest.permission#ACCESS_FINE_LOCATION} permission in case that
     * listener want to get location info in {@link CellIdentity} regardless of whether the calling
     * app has carrier privileges.
     *
     * @hide
     * @see RegistrationFailedListener#onRegistrationFailed
@@ -502,8 +507,9 @@ public class TelephonyCallback {
     * <p>Requires permission {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE} or
     * the calling app has carrier privileges (see {@link TelephonyManager#hasCarrierPrivileges}).
     *
     * <p>Also requires the {@link Manifest.permission#ACCESS_FINE_LOCATION} permission, regardless
     * of whether the calling app has carrier privileges.
     * <p>Requires the {@link Manifest.permission#ACCESS_FINE_LOCATION} permission in case that
     * listener want to get {@link BarringInfo} which includes location info in {@link CellIdentity}
     * regardless of whether the calling app has carrier privileges.
     *
     * @hide
     * @see BarringInfoListener#onBarringInfoChanged
@@ -675,10 +681,8 @@ public class TelephonyCallback {
         * Only apps holding the {@link Manifest.permission#ACCESS_FINE_LOCATION} permission will
         * receive all the information in {@link ServiceState}, otherwise the cellIdentity
         * will be null if apps only holding the {@link Manifest.permission#ACCESS_COARSE_LOCATION}
         * permission.
         * Network operator name in long/short alphanumeric format and numeric id will be null if
         * apps holding neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION} nor
         * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}.
         * permission. Network operator name in long/short alphanumeric format and numeric id will
         * be null if apps holding neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION}
         *
         * @see ServiceState#STATE_EMERGENCY_ONLY
         * @see ServiceState#STATE_IN_SERVICE
@@ -1268,6 +1272,9 @@ public class TelephonyCallback {
         * {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE} and
         * {@link android.Manifest.permission#ACCESS_FINE_LOCATION}.
         *
         * If the calling app doesn't have {@link android.Manifest.permission#ACCESS_FINE_LOCATION},
         * it will receive {@link CellIdentity} without location-sensitive information included.
         *
         * @param cellIdentity        the CellIdentity, which must include the globally unique
         *                            identifier
         *                            for the cell (for example, all components of the CGI or ECGI).
@@ -1446,6 +1453,10 @@ public class TelephonyCallback {
         * {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE} and
         * {@link android.Manifest.permission#ACCESS_FINE_LOCATION}.
         *
         * If the calling app doesn't have {@link android.Manifest.permission#ACCESS_FINE_LOCATION},
         * it will receive {@link BarringInfo} including {@link CellIdentity} without
         * location-sensitive information included.
         *
         * @param barringInfo for all services on the current cell.
         * @see android.telephony.BarringInfo
         */
+22 −28
Original line number Diff line number Diff line
@@ -487,9 +487,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {

    private boolean isLocationPermissionRequired(Set<Integer> events) {
        return events.contains(TelephonyCallback.EVENT_CELL_LOCATION_CHANGED)
                || events.contains(TelephonyCallback.EVENT_CELL_INFO_CHANGED)
                || events.contains(TelephonyCallback.EVENT_REGISTRATION_FAILURE)
                || events.contains(TelephonyCallback.EVENT_BARRING_INFO_CHANGED);
                || events.contains(TelephonyCallback.EVENT_CELL_INFO_CHANGED);
    }

    private boolean isPhoneStatePermissionRequired(Set<Integer> events, String callingPackage,
@@ -1349,9 +1347,12 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
                }
                if (events.contains(TelephonyCallback.EVENT_BARRING_INFO_CHANGED)) {
                    BarringInfo barringInfo = mBarringInfo.get(r.phoneId);
                    BarringInfo biNoLocation = barringInfo != null
                            ? barringInfo.createLocationInfoSanitizedCopy() : null;
                    if (VDBG) log("listen: call onBarringInfoChanged=" + barringInfo);
                    if (VDBG) {
                        log("listen: call onBarringInfoChanged=" + barringInfo);
                    }
                    if (barringInfo != null) {
                        BarringInfo biNoLocation = barringInfo.createLocationInfoSanitizedCopy();

                        try {
                            r.callback.onBarringInfoChanged(
                                    checkFineLocationAccess(r, Build.VERSION_CODES.BASE)
@@ -1360,6 +1361,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
                            remove(r.binder);
                        }
                    }
                }
                if (events.contains(
                        TelephonyCallback.EVENT_PHYSICAL_CHANNEL_CONFIG_CHANGED)) {
                    try {
@@ -3522,6 +3524,8 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {

    private boolean checkListenerPermission(Set<Integer> events, int subId, String callingPackage,
            @Nullable String callingFeatureId, String message) {
        boolean isPermissionCheckSuccessful = true;
        if (isLocationPermissionRequired(events)) {
            LocationAccessPolicy.LocationPermissionQuery.Builder locationQueryBuilder =
                    new LocationAccessPolicy.LocationPermissionQuery.Builder()
                            .setCallingPackage(callingPackage)
@@ -3529,22 +3533,12 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
                            .setMethod(message + " events: " + events)
                            .setCallingPid(Binder.getCallingPid())
                            .setCallingUid(Binder.getCallingUid());

        boolean shouldCheckLocationPermissions = false;

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

        boolean isPermissionCheckSuccessful = true;

        if (shouldCheckLocationPermissions) {
            LocationAccessPolicy.LocationPermissionResult result =
                    LocationAccessPolicy.checkLocationPermission(
                            mContext, locationQueryBuilder.build());