diff --git a/core/api/current.txt b/core/api/current.txt index 24eca01a40641..6f8719fbc203d 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -42333,7 +42333,7 @@ package android.telephony { } public static interface TelephonyCallback.DisplayInfoListener { - method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public void onDisplayInfoChanged(@NonNull android.telephony.TelephonyDisplayInfo); + method public void onDisplayInfoChanged(@NonNull android.telephony.TelephonyDisplayInfo); } public static interface TelephonyCallback.EmergencyNumberListListener { diff --git a/core/java/android/telephony/PhoneStateListener.java b/core/java/android/telephony/PhoneStateListener.java index d47ae2783336c..1da7dc403d397 100644 --- a/core/java/android/telephony/PhoneStateListener.java +++ b/core/java/android/telephony/PhoneStateListener.java @@ -343,11 +343,14 @@ public class PhoneStateListener { /** * Listen for display info changed event. * - * Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE - * READ_PHONE_STATE} or that the calling app has carrier privileges (see - * {@link TelephonyManager#hasCarrierPrivileges}). + * For clients compiled on Android 11 SDK, requires permission: + * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier + * privileges (see {@link TelephonyManager#hasCarrierPrivileges}). + * For clients compiled on Android 12 SDK or newer, + * {@link android.Manifest.permission#READ_PHONE_STATE} or carrier privileges is not required + * anymore. * - * @see #onDisplayInfoChanged + * @see #onDisplayInfoChanged * @deprecated Use {@link TelephonyCallback.DisplayInfoListener} instead. */ @Deprecated @@ -981,8 +984,12 @@ public class PhoneStateListener { *

The {@link TelephonyDisplayInfo} contains status information shown to the user based on * carrier policy. * - * Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling - * app has carrier privileges (see {@link TelephonyManager#hasCarrierPrivileges}). + * For clients compiled on Android 11 SDK, requires permission: + * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier + * privileges (see {@link TelephonyManager#hasCarrierPrivileges}). + * For clients compiled on Android 12 SDK or newer, + * {@link android.Manifest.permission#READ_PHONE_STATE} or carrier privileges is not required + * anymore. * * @param telephonyDisplayInfo The display information. * @deprecated Use {@link TelephonyCallback.DisplayInfoListener} instead. diff --git a/core/java/android/telephony/TelephonyCallback.java b/core/java/android/telephony/TelephonyCallback.java index d0000005c237c..18949cdbeeabe 100644 --- a/core/java/android/telephony/TelephonyCallback.java +++ b/core/java/android/telephony/TelephonyCallback.java @@ -1057,7 +1057,6 @@ public class TelephonyCallback { * * @param telephonyDisplayInfo The display information. */ - @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public void onDisplayInfoChanged(@NonNull TelephonyDisplayInfo telephonyDisplayInfo); } diff --git a/services/core/java/com/android/server/TelephonyRegistry.java b/services/core/java/com/android/server/TelephonyRegistry.java index 411fc6778984e..6b796c2b2b976 100644 --- a/services/core/java/com/android/server/TelephonyRegistry.java +++ b/services/core/java/com/android/server/TelephonyRegistry.java @@ -366,11 +366,13 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { || events.contains(TelephonyCallback.EVENT_BARRING_INFO_CHANGED); } - private boolean isPhoneStatePermissionRequired(Set events) { + private boolean isPhoneStatePermissionRequired(Set events, int targetSdk) { return events.contains(TelephonyCallback.EVENT_CALL_FORWARDING_INDICATOR_CHANGED) || events.contains(TelephonyCallback.EVENT_MESSAGE_WAITING_INDICATOR_CHANGED) || events.contains(TelephonyCallback.EVENT_EMERGENCY_NUMBER_LIST_CHANGED) - || events.contains(TelephonyCallback.EVENT_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGED); + || events.contains(TelephonyCallback.EVENT_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGED) + || (targetSdk <= android.os.Build.VERSION_CODES.R ? events.contains( + TelephonyCallback.EVENT_DISPLAY_INFO_CHANGED) : false); } private boolean isPrecisePhoneStatePermissionRequired(Set events) { @@ -882,12 +884,12 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { remove(callback.asBinder()); return; } - + int callerTargetSdk = TelephonyPermissions.getTargetSdk(mContext, callingPackage); // Checks permission and throws SecurityException for disallowed operations. For pre-M // apps whose runtime permission has been revoked, we return immediately to skip sending // events to the app without crashing it. if (!checkListenerPermission(events, subId, callingPackage, callingFeatureId, - "listen")) { + "listen", callerTargetSdk)) { return; } @@ -920,7 +922,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { } r.phoneId = phoneId; r.eventList = events; - r.targetSdk = TelephonyPermissions.getTargetSdk(mContext, callingPackage); + r.targetSdk = callerTargetSdk; if (DBG) { log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId); @@ -2876,7 +2878,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { } private boolean checkListenerPermission(Set events, int subId, String callingPackage, - @Nullable String callingFeatureId, String message) { + @Nullable String callingFeatureId, String message, int targetSdk) { LocationAccessPolicy.LocationPermissionQuery.Builder locationQueryBuilder = new LocationAccessPolicy.LocationPermissionQuery.Builder() .setCallingPackage(callingPackage) @@ -2912,7 +2914,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { } } - if (isPhoneStatePermissionRequired(events)) { + if (isPhoneStatePermissionRequired(events, targetSdk)) { if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( mContext, subId, callingPackage, callingFeatureId, message)) { isPermissionCheckSuccessful = false;