diff options
| -rw-r--r-- | core/java/android/telephony/TelephonyCallback.java | 27 | ||||
| -rw-r--r-- | services/core/java/com/android/server/TelephonyRegistry.java | 50 |
2 files changed, 41 insertions, 36 deletions
diff --git a/core/java/android/telephony/TelephonyCallback.java b/core/java/android/telephony/TelephonyCallback.java index a50e6db5d3d9..f8df668cef4e 100644 --- a/core/java/android/telephony/TelephonyCallback.java +++ b/core/java/android/telephony/TelephonyCallback.java @@ -106,6 +106,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 @@ -485,8 +489,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 @@ -504,8 +509,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 @@ -691,10 +697,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 @@ -1284,6 +1288,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). @@ -1462,6 +1469,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 */ diff --git a/services/core/java/com/android/server/TelephonyRegistry.java b/services/core/java/com/android/server/TelephonyRegistry.java index 992281828f51..9bedbd0ec584 100644 --- a/services/core/java/com/android/server/TelephonyRegistry.java +++ b/services/core/java/com/android/server/TelephonyRegistry.java @@ -493,9 +493,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, @@ -1359,15 +1357,19 @@ 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); - try { - r.callback.onBarringInfoChanged( - checkFineLocationAccess(r, Build.VERSION_CODES.BASE) - ? barringInfo : biNoLocation); - } catch (RemoteException ex) { - remove(r.binder); + if (VDBG) { + log("listen: call onBarringInfoChanged=" + barringInfo); + } + if (barringInfo != null) { + BarringInfo biNoLocation = barringInfo.createLocationInfoSanitizedCopy(); + + try { + r.callback.onBarringInfoChanged( + checkFineLocationAccess(r, Build.VERSION_CODES.BASE) + ? barringInfo : biNoLocation); + } catch (RemoteException ex) { + remove(r.binder); + } } } if (events.contains( @@ -3618,29 +3620,21 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { private boolean checkListenerPermission(Set<Integer> events, int subId, String callingPackage, @Nullable String callingFeatureId, String message) { - LocationAccessPolicy.LocationPermissionQuery.Builder locationQueryBuilder = - new LocationAccessPolicy.LocationPermissionQuery.Builder() - .setCallingPackage(callingPackage) - .setCallingFeatureId(callingFeatureId) - .setMethod(message + " events: " + events) - .setCallingPid(Binder.getCallingPid()) - .setCallingUid(Binder.getCallingUid()); - - boolean shouldCheckLocationPermissions = false; - + boolean isPermissionCheckSuccessful = true; if (isLocationPermissionRequired(events)) { + LocationAccessPolicy.LocationPermissionQuery.Builder locationQueryBuilder = + new LocationAccessPolicy.LocationPermissionQuery.Builder() + .setCallingPackage(callingPackage) + .setCallingFeatureId(callingFeatureId) + .setMethod(message + " events: " + events) + .setCallingPid(Binder.getCallingPid()) + .setCallingUid(Binder.getCallingUid()); // 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()); |