From 4e016ac105a61557b4321529cee56eb861d7a509 Mon Sep 17 00:00:00 2001 From: Zoey Chen Date: Wed, 24 Mar 2021 16:06:39 +0800 Subject: [PATCH] [Telephony] TelephonyCallback API update - Keep the permission consistency 1. PhoneStateListener.LISTEN_XXX 2. PhoneStateListener.onXxxxx 3. TelephonyCallback.EVENT_XXX 4. XxxListener.onXxxx - Remove the permission to keep the consistency with PSL 1. DataConnectionSTateListener 2. DataActivityListener, 3. SignalStrengthListener, 4. DataActivationStateListener 5. UserMobileDataStateListener 6. PhoneCapabilityListener - Remove AlwaysReportedSignalStengthListener - onCellInfoChanged and onActiveDataSubscriptionIdChanged: Should add READ_PHONE_STATE in TelephonyCallback and PSL, target SDK to check the permission Bug: 182478738 Test: make Change-Id: I0b477e5f53f4187223808258b45f0b5f0c1d5578 --- core/api/current.txt | 52 +++--- core/api/system-current.txt | 20 +-- .../android/telephony/PhoneStateListener.java | 54 +++++- .../android/telephony/TelephonyCallback.java | 125 ++++++-------- .../telephony/TelephonyRegistryManager.java | 4 - .../com/android/server/TelephonyRegistry.java | 155 +++++++++++++++--- 6 files changed, 260 insertions(+), 150 deletions(-) diff --git a/core/api/current.txt b/core/api/current.txt index fb32055a45c2f..846a14b796b0b 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -41910,42 +41910,42 @@ package android.telephony { @Deprecated public class PhoneStateListener { ctor @Deprecated public PhoneStateListener(); ctor @Deprecated public PhoneStateListener(@NonNull java.util.concurrent.Executor); - method @Deprecated public void onActiveDataSubscriptionIdChanged(int); - method @Deprecated public void onBarringInfoChanged(@NonNull android.telephony.BarringInfo); + method @Deprecated @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public void onActiveDataSubscriptionIdChanged(int); + method @Deprecated @RequiresPermission(allOf={android.Manifest.permission.READ_PRECISE_PHONE_STATE, android.Manifest.permission.ACCESS_FINE_LOCATION}) public void onBarringInfoChanged(@NonNull android.telephony.BarringInfo); method @Deprecated @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE) public void onCallDisconnectCauseChanged(int, int); - method @Deprecated public void onCallForwardingIndicatorChanged(boolean); + method @Deprecated @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public void onCallForwardingIndicatorChanged(boolean); method @Deprecated @RequiresPermission(value=android.Manifest.permission.READ_PHONE_STATE, conditional=true) public void onCallStateChanged(int, String); - method @Deprecated public void onCellInfoChanged(java.util.List); - method @Deprecated public void onCellLocationChanged(android.telephony.CellLocation); + method @Deprecated @RequiresPermission(allOf={android.Manifest.permission.READ_PHONE_STATE, android.Manifest.permission.ACCESS_FINE_LOCATION}) public void onCellInfoChanged(java.util.List); + method @Deprecated @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) public void onCellLocationChanged(android.telephony.CellLocation); method @Deprecated public void onDataActivity(int); method @Deprecated public void onDataConnectionStateChanged(int); method @Deprecated public void onDataConnectionStateChanged(int, int); method @Deprecated @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public void onDisplayInfoChanged(@NonNull android.telephony.TelephonyDisplayInfo); - method @Deprecated public void onEmergencyNumberListChanged(@NonNull java.util.Map>); + method @Deprecated @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public void onEmergencyNumberListChanged(@NonNull java.util.Map>); method @Deprecated @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE) public void onImsCallDisconnectCauseChanged(@NonNull android.telephony.ims.ImsReasonInfo); - method @Deprecated public void onMessageWaitingIndicatorChanged(boolean); - method @Deprecated @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void onPreciseDataConnectionStateChanged(@NonNull android.telephony.PreciseDataConnectionState); - method @Deprecated public void onRegistrationFailed(@NonNull android.telephony.CellIdentity, @NonNull String, int, int, int); + method @Deprecated @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public void onMessageWaitingIndicatorChanged(boolean); + method @Deprecated @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE) public void onPreciseDataConnectionStateChanged(@NonNull android.telephony.PreciseDataConnectionState); + method @Deprecated @RequiresPermission(allOf={android.Manifest.permission.READ_PRECISE_PHONE_STATE, android.Manifest.permission.ACCESS_FINE_LOCATION}) public void onRegistrationFailed(@NonNull android.telephony.CellIdentity, @NonNull String, int, int, int); method @Deprecated public void onServiceStateChanged(android.telephony.ServiceState); method @Deprecated public void onSignalStrengthChanged(int); method @Deprecated public void onSignalStrengthsChanged(android.telephony.SignalStrength); method @Deprecated public void onUserMobileDataStateChanged(boolean); - field @Deprecated public static final int LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE = 4194304; // 0x400000 - field @Deprecated @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE) public static final int LISTEN_BARRING_INFO = -2147483648; // 0x80000000 + field @Deprecated @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public static final int LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE = 4194304; // 0x400000 + field @Deprecated @RequiresPermission(allOf={android.Manifest.permission.READ_PRECISE_PHONE_STATE, android.Manifest.permission.ACCESS_FINE_LOCATION}) public static final int LISTEN_BARRING_INFO = -2147483648; // 0x80000000 field @Deprecated @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE) public static final int LISTEN_CALL_DISCONNECT_CAUSES = 33554432; // 0x2000000 - field @Deprecated public static final int LISTEN_CALL_FORWARDING_INDICATOR = 8; // 0x8 + field @Deprecated @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public static final int LISTEN_CALL_FORWARDING_INDICATOR = 8; // 0x8 field @Deprecated public static final int LISTEN_CALL_STATE = 32; // 0x20 - field @Deprecated public static final int LISTEN_CELL_INFO = 1024; // 0x400 - field @Deprecated public static final int LISTEN_CELL_LOCATION = 16; // 0x10 + field @Deprecated @RequiresPermission(allOf={android.Manifest.permission.READ_PHONE_STATE, android.Manifest.permission.ACCESS_FINE_LOCATION}) public static final int LISTEN_CELL_INFO = 1024; // 0x400 + field @Deprecated @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) public static final int LISTEN_CELL_LOCATION = 16; // 0x10 field @Deprecated public static final int LISTEN_DATA_ACTIVITY = 128; // 0x80 field @Deprecated public static final int LISTEN_DATA_CONNECTION_STATE = 64; // 0x40 field @Deprecated public static final int LISTEN_DISPLAY_INFO_CHANGED = 1048576; // 0x100000 - field @Deprecated public static final int LISTEN_EMERGENCY_NUMBER_LIST = 16777216; // 0x1000000 + field @Deprecated @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public static final int LISTEN_EMERGENCY_NUMBER_LIST = 16777216; // 0x1000000 field @Deprecated @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE) public static final int LISTEN_IMS_CALL_DISCONNECT_CAUSES = 134217728; // 0x8000000 - field @Deprecated public static final int LISTEN_MESSAGE_WAITING_INDICATOR = 4; // 0x4 + field @Deprecated @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public static final int LISTEN_MESSAGE_WAITING_INDICATOR = 4; // 0x4 field @Deprecated public static final int LISTEN_NONE = 0; // 0x0 field @Deprecated @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE) public static final int LISTEN_PRECISE_DATA_CONNECTION_STATE = 4096; // 0x1000 - field @Deprecated @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE) public static final int LISTEN_REGISTRATION_FAILURE = 1073741824; // 0x40000000 + field @Deprecated @RequiresPermission(allOf={android.Manifest.permission.READ_PRECISE_PHONE_STATE, android.Manifest.permission.ACCESS_FINE_LOCATION}) public static final int LISTEN_REGISTRATION_FAILURE = 1073741824; // 0x40000000 field @Deprecated public static final int LISTEN_SERVICE_STATE = 1; // 0x1 field @Deprecated public static final int LISTEN_SIGNAL_STRENGTH = 2; // 0x2 field @Deprecated public static final int LISTEN_SIGNAL_STRENGTHS = 256; // 0x100 @@ -42443,10 +42443,6 @@ package android.telephony { method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public void onActiveDataSubscriptionIdChanged(int); } - public static interface TelephonyCallback.AlwaysReportedSignalStrengthListener { - method @RequiresPermission("android.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH") public void onSignalStrengthsChanged(@NonNull android.telephony.SignalStrength); - } - public static interface TelephonyCallback.BarringInfoListener { method @RequiresPermission(allOf={android.Manifest.permission.READ_PRECISE_PHONE_STATE, android.Manifest.permission.ACCESS_FINE_LOCATION}) public void onBarringInfoChanged(@NonNull android.telephony.BarringInfo); } @@ -42468,7 +42464,7 @@ package android.telephony { } public static interface TelephonyCallback.CellInfoListener { - method @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) public void onCellInfoChanged(@NonNull java.util.List); + method @RequiresPermission(allOf={android.Manifest.permission.READ_PHONE_STATE, android.Manifest.permission.ACCESS_FINE_LOCATION}) public void onCellInfoChanged(@NonNull java.util.List); } public static interface TelephonyCallback.CellLocationListener { @@ -42476,15 +42472,15 @@ package android.telephony { } public static interface TelephonyCallback.DataActivationStateListener { - method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void onDataActivationStateChanged(int); + method public void onDataActivationStateChanged(int); } public static interface TelephonyCallback.DataActivityListener { - method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void onDataActivity(int); + method public void onDataActivity(int); } public static interface TelephonyCallback.DataConnectionStateListener { - method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void onDataConnectionStateChanged(int, int); + method public void onDataConnectionStateChanged(int, int); } public static interface TelephonyCallback.DisplayInfoListener { @@ -42516,15 +42512,15 @@ package android.telephony { } public static interface TelephonyCallback.ServiceStateListener { - method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void onServiceStateChanged(@NonNull android.telephony.ServiceState); + method public void onServiceStateChanged(@NonNull android.telephony.ServiceState); } public static interface TelephonyCallback.SignalStrengthsListener { - method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void onSignalStrengthsChanged(@NonNull android.telephony.SignalStrength); + method public void onSignalStrengthsChanged(@NonNull android.telephony.SignalStrength); } public static interface TelephonyCallback.UserMobileDataStateListener { - method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void onUserMobileDataStateChanged(boolean); + method public void onUserMobileDataStateChanged(boolean); } public final class TelephonyDisplayInfo implements android.os.Parcelable { diff --git a/core/api/system-current.txt b/core/api/system-current.txt index a9413f5d803e9..291d105271600 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -11345,15 +11345,15 @@ package android.telephony { } @Deprecated public class PhoneStateListener { - method @Deprecated public void onCallAttributesChanged(@NonNull android.telephony.CallAttributes); - method @Deprecated public void onOutgoingEmergencyCall(@NonNull android.telephony.emergency.EmergencyNumber); - method @Deprecated public void onOutgoingEmergencyCall(@NonNull android.telephony.emergency.EmergencyNumber, int); - method @Deprecated public void onOutgoingEmergencySms(@NonNull android.telephony.emergency.EmergencyNumber); + method @Deprecated @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE) public void onCallAttributesChanged(@NonNull android.telephony.CallAttributes); + method @Deprecated @RequiresPermission(android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION) public void onOutgoingEmergencyCall(@NonNull android.telephony.emergency.EmergencyNumber); + method @Deprecated @RequiresPermission(android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION) public void onOutgoingEmergencyCall(@NonNull android.telephony.emergency.EmergencyNumber, int); + method @Deprecated @RequiresPermission(android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION) public void onOutgoingEmergencySms(@NonNull android.telephony.emergency.EmergencyNumber); method @Deprecated public void onOutgoingEmergencySms(@NonNull android.telephony.emergency.EmergencyNumber, int); method @Deprecated @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE) public void onPreciseCallStateChanged(@NonNull android.telephony.PreciseCallState); - method @Deprecated public void onRadioPowerStateChanged(int); - method @Deprecated public void onSrvccStateChanged(int); - method @Deprecated public void onVoiceActivationStateChanged(int); + method @Deprecated @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void onRadioPowerStateChanged(int); + method @Deprecated @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void onSrvccStateChanged(int); + method @Deprecated @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void onVoiceActivationStateChanged(int); field @Deprecated @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE) public static final int LISTEN_CALL_ATTRIBUTES_CHANGED = 67108864; // 0x4000000 field @Deprecated @RequiresPermission(android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION) public static final int LISTEN_OUTGOING_EMERGENCY_CALL = 268435456; // 0x10000000 field @Deprecated @RequiresPermission(android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION) public static final int LISTEN_OUTGOING_EMERGENCY_SMS = 536870912; // 0x20000000 @@ -11703,14 +11703,14 @@ package android.telephony { public class TelephonyCallback { field @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public static final int EVENT_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGED = 23; // 0x17 field @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public static final int EVENT_ALLOWED_NETWORK_TYPE_LIST_CHANGED = 35; // 0x23 - field @RequiresPermission("android.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH") public static final int EVENT_ALWAYS_REPORTED_SIGNAL_STRENGTH_CHANGED = 10; // 0xa + field public static final int EVENT_ALWAYS_REPORTED_SIGNAL_STRENGTH_CHANGED = 10; // 0xa field @RequiresPermission(allOf={android.Manifest.permission.READ_PRECISE_PHONE_STATE, android.Manifest.permission.ACCESS_FINE_LOCATION}) public static final int EVENT_BARRING_INFO_CHANGED = 32; // 0x20 field @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE) public static final int EVENT_CALL_ATTRIBUTES_CHANGED = 27; // 0x1b field @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE) public static final int EVENT_CALL_DISCONNECT_CAUSE_CHANGED = 26; // 0x1a field @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public static final int EVENT_CALL_FORWARDING_INDICATOR_CHANGED = 4; // 0x4 field public static final int EVENT_CALL_STATE_CHANGED = 6; // 0x6 field public static final int EVENT_CARRIER_NETWORK_CHANGED = 17; // 0x11 - field @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) public static final int EVENT_CELL_INFO_CHANGED = 11; // 0xb + field @RequiresPermission(allOf={android.Manifest.permission.READ_PHONE_STATE, android.Manifest.permission.ACCESS_FINE_LOCATION}) public static final int EVENT_CELL_INFO_CHANGED = 11; // 0xb field @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) public static final int EVENT_CELL_LOCATION_CHANGED = 5; // 0x5 field public static final int EVENT_DATA_ACTIVATION_STATE_CHANGED = 19; // 0x13 field public static final int EVENT_DATA_ACTIVITY_CHANGED = 8; // 0x8 @@ -11765,7 +11765,7 @@ package android.telephony { } public static interface TelephonyCallback.PhoneCapabilityListener { - method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void onPhoneCapabilityChanged(@NonNull android.telephony.PhoneCapability); + method public void onPhoneCapabilityChanged(@NonNull android.telephony.PhoneCapability); } public static interface TelephonyCallback.PreciseCallStateListener { diff --git a/core/java/android/telephony/PhoneStateListener.java b/core/java/android/telephony/PhoneStateListener.java index 49065aaa2d23b..a1ffe345d4579 100644 --- a/core/java/android/telephony/PhoneStateListener.java +++ b/core/java/android/telephony/PhoneStateListener.java @@ -110,6 +110,7 @@ public class PhoneStateListener { * @deprecated Use {@link TelephonyCallback.MessageWaitingIndicatorListener} instead. */ @Deprecated + @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public static final int LISTEN_MESSAGE_WAITING_INDICATOR = 0x00000004; /** @@ -123,6 +124,7 @@ public class PhoneStateListener { * @deprecated Use {@link TelephonyCallback.CallForwardingIndicatorListener} instead. */ @Deprecated + @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public static final int LISTEN_CALL_FORWARDING_INDICATOR = 0x00000008; /** @@ -141,6 +143,7 @@ public class PhoneStateListener { * @deprecated Use {@link TelephonyCallback.CellLocationListener} instead. */ @Deprecated + @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) public static final int LISTEN_CELL_LOCATION = 0x00000010; /** @@ -194,7 +197,7 @@ public class PhoneStateListener { * @see #onSignalStrengthsChanged * * @hide - * @deprecated Use {@link TelephonyCallback.AlwaysReportedSignalStrengthListener} + * @deprecated Use TelephonyManager#setSignalStrengthUpdateRequest * instead. */ @Deprecated @@ -204,13 +207,18 @@ public class PhoneStateListener { /** * Listen for changes to observed cell info. * - * Listening to this event requires the {@link Manifest.permission#ACCESS_FINE_LOCATION} + * Listening to this event requires the {@link Manifest.permission#READ_PHONE_STATE} and + * {@link Manifest.permission#ACCESS_FINE_LOCATION} * permission. * * @see #onCellInfoChanged * @deprecated Use {@link TelephonyCallback.CellInfoListener} instead. */ @Deprecated + @RequiresPermission(allOf = { + Manifest.permission.READ_PHONE_STATE, + Manifest.permission.ACCESS_FINE_LOCATION + }) public static final int LISTEN_CELL_INFO = 0x00000400; /** @@ -261,7 +269,7 @@ public class PhoneStateListener { * *

Requires permission {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE} * - * @see #onServiceStateChanged(ServiceState) + * @see #onSrvccStateChanged * @hide * @deprecated Use {@link TelephonyCallback.SrvccStateListener} instead. */ @@ -376,6 +384,7 @@ public class PhoneStateListener { * @deprecated Use {@link TelephonyCallback.ActiveDataSubscriptionIdListener} instead. */ @Deprecated + @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public static final int LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE = 0x00400000; /** @@ -399,6 +408,7 @@ public class PhoneStateListener { * @deprecated Use {@link TelephonyCallback.EmergencyNumberListListener} instead. */ @Deprecated + @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public static final int LISTEN_EMERGENCY_NUMBER_LIST = 0x01000000; /** @@ -487,7 +497,10 @@ public class PhoneStateListener { * @deprecated Use {@link TelephonyCallback.RegistrationFailedListener} instead. */ @Deprecated - @RequiresPermission(Manifest.permission.READ_PRECISE_PHONE_STATE) + @RequiresPermission(allOf = { + Manifest.permission.READ_PRECISE_PHONE_STATE, + Manifest.permission.ACCESS_FINE_LOCATION + }) public static final int LISTEN_REGISTRATION_FAILURE = 0x40000000; /** @@ -503,7 +516,10 @@ public class PhoneStateListener { * @deprecated Use {@link TelephonyCallback.BarringInfoListener} instead. */ @Deprecated - @RequiresPermission(Manifest.permission.READ_PRECISE_PHONE_STATE) + @RequiresPermission(allOf = { + Manifest.permission.READ_PRECISE_PHONE_STATE, + Manifest.permission.ACCESS_FINE_LOCATION + }) public static final int LISTEN_BARRING_INFO = 0x80000000; /* @@ -650,6 +666,7 @@ public class PhoneStateListener { * @deprecated Use {@link TelephonyCallback.MessageWaitingIndicatorListener} instead. */ @Deprecated + @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public void onMessageWaitingIndicatorChanged(boolean mwi) { // default implementation empty } @@ -666,6 +683,7 @@ public class PhoneStateListener { * @deprecated Use {@link TelephonyCallback.CallForwardingIndicatorListener} instead. */ @Deprecated + @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public void onCallForwardingIndicatorChanged(boolean cfi) { // default implementation empty } @@ -682,6 +700,7 @@ public class PhoneStateListener { * @deprecated Use {@link TelephonyCallback.CellLocationListener} instead. */ @Deprecated + @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) public void onCellLocationChanged(CellLocation location) { // default implementation empty } @@ -801,6 +820,10 @@ public class PhoneStateListener { * @param cellInfo is the list of currently visible cells. * @deprecated Use {@link TelephonyCallback.CellInfoListener} instead. */ + @RequiresPermission(allOf = { + Manifest.permission.READ_PHONE_STATE, + Manifest.permission.ACCESS_FINE_LOCATION + }) @Deprecated public void onCellInfoChanged(List cellInfo) { // default implementation empty @@ -875,14 +898,14 @@ public class PhoneStateListener { * subId. Otherwise, this callback applies to * {@link SubscriptionManager#getDefaultSubscriptionId()}. * - *

Requires permission {@link android.Manifest.permission#MODIFY_PHONE_STATE} + *

Requires permission {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE} * or the calling app has carrier privileges * (see {@link TelephonyManager#hasCarrierPrivileges}). * * @param dataConnectionState {@link PreciseDataConnectionState} * @deprecated Use {@link TelephonyCallback.PreciseDataConnectionStateListener} instead. */ - @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) + @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE) @Deprecated public void onPreciseDataConnectionStateChanged( @NonNull PreciseDataConnectionState dataConnectionState) { @@ -924,6 +947,7 @@ public class PhoneStateListener { */ @SystemApi @Deprecated + @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void onSrvccStateChanged(@SrvccState int srvccState) { // default implementation empty } @@ -944,6 +968,7 @@ public class PhoneStateListener { */ @SystemApi @Deprecated + @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void onVoiceActivationStateChanged(@SimActivationState int state) { // default implementation empty } @@ -1026,6 +1051,7 @@ public class PhoneStateListener { * @deprecated Use {@link TelephonyCallback.EmergencyNumberListListener} instead. */ @Deprecated + @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public void onEmergencyNumberListChanged( @NonNull Map> emergencyNumberList) { // default implementation empty @@ -1043,6 +1069,7 @@ public class PhoneStateListener { */ @SystemApi @Deprecated + @RequiresPermission(Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION) public void onOutgoingEmergencyCall(@NonNull EmergencyNumber placedEmergencyNumber) { // default implementation empty } @@ -1068,6 +1095,7 @@ public class PhoneStateListener { */ @SystemApi @Deprecated + @RequiresPermission(Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION) public void onOutgoingEmergencyCall(@NonNull EmergencyNumber placedEmergencyNumber, int subscriptionId) { // Default implementation for backwards compatibility @@ -1086,6 +1114,7 @@ public class PhoneStateListener { */ @SystemApi @Deprecated + @RequiresPermission(Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION) public void onOutgoingEmergencySms(@NonNull EmergencyNumber sentEmergencyNumber) { // default implementation empty } @@ -1158,6 +1187,7 @@ public class PhoneStateListener { * @deprecated Use {@link TelephonyCallback.ActiveDataSubscriptionIdListener} instead. */ @Deprecated + @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public void onActiveDataSubscriptionIdChanged(int subId) { // default implementation empty } @@ -1178,6 +1208,7 @@ public class PhoneStateListener { */ @SystemApi @Deprecated + @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE) public void onCallAttributesChanged(@NonNull CallAttributes callAttributes) { // default implementation empty } @@ -1199,6 +1230,7 @@ public class PhoneStateListener { */ @SystemApi @Deprecated + @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void onRadioPowerStateChanged(@RadioPowerState int state) { // default implementation empty } @@ -1253,6 +1285,10 @@ public class PhoneStateListener { * @deprecated Use {@link TelephonyCallback.RegistrationFailedListener} instead. */ @Deprecated + @RequiresPermission(allOf = { + Manifest.permission.READ_PRECISE_PHONE_STATE, + Manifest.permission.ACCESS_FINE_LOCATION + }) public void onRegistrationFailed(@NonNull CellIdentity cellIdentity, @NonNull String chosenPlmn, int domain, int causeCode, int additionalCauseCode) { // default implementation empty @@ -1269,6 +1305,10 @@ public class PhoneStateListener { * @deprecated Use {@link TelephonyCallback.BarringInfoListener} instead. */ @Deprecated + @RequiresPermission(allOf = { + Manifest.permission.READ_PRECISE_PHONE_STATE, + Manifest.permission.ACCESS_FINE_LOCATION + }) public void onBarringInfoChanged(@NonNull BarringInfo barringInfo) { // default implementation empty } diff --git a/core/java/android/telephony/TelephonyCallback.java b/core/java/android/telephony/TelephonyCallback.java index 1ab6e0ffc34ed..1a25c8b4e6710 100644 --- a/core/java/android/telephony/TelephonyCallback.java +++ b/core/java/android/telephony/TelephonyCallback.java @@ -218,10 +218,9 @@ public class TelephonyCallback { * even in some situations such as the screen of the device is off. * * @hide - * @see AlwaysReportedSignalStrengthListener#onSignalStrengthsChanged + * @see TelephonyManager#setSignalStrengthUpdateRequest */ @SystemApi - @RequiresPermission(android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH) public static final int EVENT_ALWAYS_REPORTED_SIGNAL_STRENGTH_CHANGED = 10; /** @@ -231,8 +230,10 @@ public class TelephonyCallback { * @see CellInfoListener#onCellInfoChanged */ @SystemApi - @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) - public static final int EVENT_CELL_INFO_CHANGED = 11; + @RequiresPermission(allOf = { + Manifest.permission.READ_PHONE_STATE, + Manifest.permission.ACCESS_FINE_LOCATION + }) public static final int EVENT_CELL_INFO_CHANGED = 11; /** * Event for {@link android.telephony.Annotation.PreciseCallStates} of ringing, @@ -369,9 +370,10 @@ public class TelephonyCallback { /** * Event for changes to active data subscription ID. Active data subscription is - * the current subscription used to setup Cellular Internet data. For example, - * it could be the current active opportunistic subscription in use, or the - * subscription user selected as default data subscription in DSDS mode. + * the current subscription used to setup Cellular Internet data. The data is only active on the + * subscription at a time, even it is multi-SIM mode. For example, it could be the current + * active opportunistic subscription in use, or the subscription user selected as default data + * subscription in DSDS mode. * *

Requires permission {@link android.Manifest.permission#READ_PHONE_STATE} or the calling * app has carrier privileges (see {@link TelephonyManager#hasCarrierPrivileges}). @@ -668,8 +670,7 @@ public class TelephonyCallback { * @see ServiceState#STATE_OUT_OF_SERVICE * @see ServiceState#STATE_POWER_OFF */ - @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) - public void onServiceStateChanged(@NonNull ServiceState serviceState); + void onServiceStateChanged(@NonNull ServiceState serviceState); } /** @@ -687,7 +688,7 @@ public class TelephonyCallback { * {@link SubscriptionManager#getDefaultSubscriptionId()}. */ @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) - public void onMessageWaitingIndicatorChanged(boolean mwi); + void onMessageWaitingIndicatorChanged(boolean mwi); } /** @@ -706,7 +707,7 @@ public class TelephonyCallback { * {@link SubscriptionManager#getDefaultSubscriptionId()}. */ @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) - public void onCallForwardingIndicatorChanged(boolean cfi); + void onCallForwardingIndicatorChanged(boolean cfi); } /** @@ -724,7 +725,7 @@ public class TelephonyCallback { * {@link SubscriptionManager#getDefaultSubscriptionId()}. */ @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) - public void onCellLocationChanged(@NonNull CellLocation location); + void onCellLocationChanged(@NonNull CellLocation location); } /** @@ -753,7 +754,7 @@ public class TelephonyCallback { * @param state the current call state */ @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) - public void onCallStateChanged(@Annotation.CallState int state); + void onCallStateChanged(@Annotation.CallState int state); } /** @@ -777,9 +778,8 @@ public class TelephonyCallback { * @see TelephonyManager#DATA_CONNECTED * @see TelephonyManager#DATA_SUSPENDED */ - @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) - public void onDataConnectionStateChanged(@TelephonyManager.DataState int state, - @Annotation.NetworkType int networkType); + void onDataConnectionStateChanged(@TelephonyManager.DataState int state, + @Annotation.NetworkType int networkType); } /** @@ -802,8 +802,7 @@ public class TelephonyCallback { * @see TelephonyManager#DATA_ACTIVITY_INOUT * @see TelephonyManager#DATA_ACTIVITY_DORMANT */ - @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) - public void onDataActivity(@Annotation.DataActivityType int direction); + void onDataActivity(@Annotation.DataActivityType int direction); } /** @@ -820,27 +819,7 @@ public class TelephonyCallback { * subscription ID. Otherwise, this callback applies to * {@link SubscriptionManager#getDefaultSubscriptionId()}. */ - @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) - public void onSignalStrengthsChanged(@NonNull SignalStrength signalStrength); - } - - /** - * Interface for network signal strengths callback which always reported from modem. - */ - public interface AlwaysReportedSignalStrengthListener { - /** - * Callback always invoked from modem when network signal strengths changes on the - * registered subscription. - * Note, the registration subscription ID comes from {@link TelephonyManager} object - * which registers TelephonyCallback by - * {@link TelephonyManager#registerTelephonyCallback(Executor, TelephonyCallback)}. - * If this TelephonyManager object was created with - * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the - * subscription ID. Otherwise, this callback applies to - * {@link SubscriptionManager#getDefaultSubscriptionId()}. - */ - @RequiresPermission(android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH) - public void onSignalStrengthsChanged(@NonNull SignalStrength signalStrength); + void onSignalStrengthsChanged(@NonNull SignalStrength signalStrength); } /** @@ -860,8 +839,11 @@ public class TelephonyCallback { * * @param cellInfo is the list of currently visible cells. */ - @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) - public void onCellInfoChanged(@NonNull List cellInfo); + @RequiresPermission(allOf = { + Manifest.permission.READ_PHONE_STATE, + Manifest.permission.ACCESS_FINE_LOCATION + }) + void onCellInfoChanged(@NonNull List cellInfo); } /** @@ -884,7 +866,7 @@ public class TelephonyCallback { * @param callState {@link PreciseCallState} */ @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE) - public void onPreciseCallStateChanged(@NonNull PreciseCallState callState); + void onPreciseCallStateChanged(@NonNull PreciseCallState callState); } /** @@ -905,8 +887,8 @@ public class TelephonyCallback { * @param preciseDisconnectCause {@link PreciseDisconnectCause}. */ @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE) - public void onCallDisconnectCauseChanged(@Annotation.DisconnectCauses int disconnectCause, - @Annotation.PreciseDisconnectCauses int preciseDisconnectCause); + void onCallDisconnectCauseChanged(@Annotation.DisconnectCauses int disconnectCause, + @Annotation.PreciseDisconnectCauses int preciseDisconnectCause); } /** @@ -926,7 +908,7 @@ public class TelephonyCallback { * @param imsReasonInfo {@link ImsReasonInfo} contains details on why IMS call failed. */ @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE) - public void onImsCallDisconnectCauseChanged(@NonNull ImsReasonInfo imsReasonInfo); + void onImsCallDisconnectCauseChanged(@NonNull ImsReasonInfo imsReasonInfo); } /** @@ -952,7 +934,7 @@ public class TelephonyCallback { * @param dataConnectionState {@link PreciseDataConnectionState} */ @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE) - public void onPreciseDataConnectionStateChanged( + void onPreciseDataConnectionStateChanged( @NonNull PreciseDataConnectionState dataConnectionState); } @@ -976,7 +958,7 @@ public class TelephonyCallback { * {@link SubscriptionManager#getDefaultSubscriptionId()}. */ @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) - public void onSrvccStateChanged(@Annotation.SrvccState int srvccState); + void onSrvccStateChanged(@Annotation.SrvccState int srvccState); } /** @@ -1000,7 +982,7 @@ public class TelephonyCallback { * @param state is the current SIM voice activation state */ @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) - public void onVoiceActivationStateChanged(@Annotation.SimActivationState int state); + void onVoiceActivationStateChanged(@Annotation.SimActivationState int state); } @@ -1021,8 +1003,7 @@ public class TelephonyCallback { * * @param state is the current SIM data activation state */ - @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) - public void onDataActivationStateChanged(@Annotation.SimActivationState int state); + void onDataActivationStateChanged(@Annotation.SimActivationState int state); } /** @@ -1043,8 +1024,7 @@ public class TelephonyCallback { * @param enabled indicates whether the current user mobile data state is enabled or * disabled. */ - @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) - public void onUserMobileDataStateChanged(boolean enabled); + void onUserMobileDataStateChanged(boolean enabled); } /** @@ -1058,7 +1038,7 @@ public class TelephonyCallback { * * @param telephonyDisplayInfo The display information. */ - public void onDisplayInfoChanged(@NonNull TelephonyDisplayInfo telephonyDisplayInfo); + void onDisplayInfoChanged(@NonNull TelephonyDisplayInfo telephonyDisplayInfo); } /** @@ -1089,8 +1069,8 @@ public class TelephonyCallback { * empty. */ @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) - public void onEmergencyNumberListChanged( - @NonNull Map> emergencyNumberList); + void onEmergencyNumberListChanged(@NonNull Map> emergencyNumberList); } /** @@ -1118,8 +1098,8 @@ public class TelephonyCallback { * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID}. */ @RequiresPermission(Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION) - public void onOutgoingEmergencyCall(@NonNull EmergencyNumber placedEmergencyNumber, - int subscriptionId); + void onOutgoingEmergencyCall(@NonNull EmergencyNumber placedEmergencyNumber, + int subscriptionId); } /** @@ -1139,8 +1119,8 @@ public class TelephonyCallback { * @param subscriptionId The subscription ID used to send the emergency sms. */ @RequiresPermission(Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION) - public void onOutgoingEmergencySms(@NonNull EmergencyNumber sentEmergencyNumber, - int subscriptionId); + void onOutgoingEmergencySms(@NonNull EmergencyNumber sentEmergencyNumber, + int subscriptionId); } /** @@ -1156,8 +1136,7 @@ public class TelephonyCallback { * * @param capability the new phone capability */ - @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) - public void onPhoneCapabilityChanged(@NonNull PhoneCapability capability); + void onPhoneCapabilityChanged(@NonNull PhoneCapability capability); } /** @@ -1168,13 +1147,14 @@ public class TelephonyCallback { * Callback invoked when active data subscription ID changes. * Note, this callback triggers regardless of registered subscription. * - * @param subId current subscription used to setup Cellular Internet data. + * @param subId current subscription used to setup Cellular Internet data. The data is + * only active on the subscription at a time, even it is multi-SIM mode. * For example, it could be the current active opportunistic subscription * in use, or the subscription user selected as default data subscription in * DSDS mode. */ @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) - public void onActiveDataSubscriptionIdChanged(int subId); + void onActiveDataSubscriptionIdChanged(int subId); } /** @@ -1197,7 +1177,7 @@ public class TelephonyCallback { * @param state the modem radio power state */ @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) - public void onRadioPowerStateChanged(@Annotation.RadioPowerState int state); + void onRadioPowerStateChanged(@Annotation.RadioPowerState int state); } /** @@ -1221,7 +1201,7 @@ public class TelephonyCallback { * @param active If the carrier network change is or shortly will be active, * {@code true} indicate that showing alternative UI, {@code false} otherwise. */ - public void onCarrierNetworkChange(boolean active); + void onCarrierNetworkChange(boolean active); } /** @@ -1263,9 +1243,8 @@ public class TelephonyCallback { Manifest.permission.READ_PRECISE_PHONE_STATE, Manifest.permission.ACCESS_FINE_LOCATION }) - public void onRegistrationFailed(@NonNull CellIdentity cellIdentity, - @NonNull String chosenPlmn, @NetworkRegistrationInfo.Domain int domain, int causeCode, - int additionalCauseCode); + void onRegistrationFailed(@NonNull CellIdentity cellIdentity, @NonNull String chosenPlmn, + @NetworkRegistrationInfo.Domain int domain, int causeCode, int additionalCauseCode); } /** @@ -1303,8 +1282,7 @@ public class TelephonyCallback { * long type value}. */ @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) - void onAllowedNetworkTypesChanged( - @TelephonyManager.AllowedNetworkTypesReason int reason, + void onAllowedNetworkTypesChanged(@TelephonyManager.AllowedNetworkTypesReason int reason, @TelephonyManager.NetworkTypeBitMask long allowedNetworkType); } @@ -1348,7 +1326,7 @@ public class TelephonyCallback { Manifest.permission.READ_PRECISE_PHONE_STATE, Manifest.permission.ACCESS_FINE_LOCATION }) - public void onBarringInfoChanged(@NonNull BarringInfo barringInfo); + void onBarringInfoChanged(@NonNull BarringInfo barringInfo); } /** @@ -1361,7 +1339,7 @@ public class TelephonyCallback { * @param configs List of the current {@link PhysicalChannelConfig}s */ @RequiresPermission(Manifest.permission.READ_PRECISE_PHONE_STATE) - public void onPhysicalChannelConfigChanged(@NonNull List configs); + void onPhysicalChannelConfigChanged(@NonNull List configs); } /** @@ -1379,8 +1357,7 @@ public class TelephonyCallback { * See {@link TelephonyManager.DataEnabledReason}. */ @RequiresPermission(Manifest.permission.READ_PRECISE_PHONE_STATE) - public void onDataEnabledChanged(boolean enabled, - @TelephonyManager.DataEnabledReason int reason); + void onDataEnabledChanged(boolean enabled, @TelephonyManager.DataEnabledReason int reason); } /** diff --git a/core/java/android/telephony/TelephonyRegistryManager.java b/core/java/android/telephony/TelephonyRegistryManager.java index 1ec12fe12b36d..340fa406bbb7e 100644 --- a/core/java/android/telephony/TelephonyRegistryManager.java +++ b/core/java/android/telephony/TelephonyRegistryManager.java @@ -894,10 +894,6 @@ public class TelephonyRegistryManager { eventList.add(TelephonyCallback.EVENT_SIGNAL_STRENGTHS_CHANGED); } - if (telephonyCallback instanceof TelephonyCallback.AlwaysReportedSignalStrengthListener) { - eventList.add(TelephonyCallback.EVENT_ALWAYS_REPORTED_SIGNAL_STRENGTH_CHANGED); - } - if (telephonyCallback instanceof TelephonyCallback.CellInfoListener) { eventList.add(TelephonyCallback.EVENT_CELL_INFO_CHANGED); } diff --git a/services/core/java/com/android/server/TelephonyRegistry.java b/services/core/java/com/android/server/TelephonyRegistry.java index b42a16db5814f..26a6a1219a8f7 100644 --- a/services/core/java/com/android/server/TelephonyRegistry.java +++ b/services/core/java/com/android/server/TelephonyRegistry.java @@ -29,6 +29,8 @@ import android.annotation.Nullable; import android.app.ActivityManager; import android.app.AppOpsManager; import android.app.compat.CompatChanges; +import android.compat.annotation.ChangeId; +import android.compat.annotation.EnabledSince; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -155,7 +157,6 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; int phoneId = SubscriptionManager.INVALID_SIM_SLOT_INDEX; - int targetSdk; boolean matchTelephonyCallbackEvent(int event) { return (callback != null) && (this.eventList.contains(event)); @@ -228,6 +229,54 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, packageName, userHandle)); } + + /** + * To check the SDK version for + * {@link android.telephony.TelephonyCallback.ActiveDataSubscriptionIdListener} should add + * {@link android.Manifest.permission#READ_PHONE_STATE} since Android 12. + * @noinspection ConstantConditions + */ + public boolean isActiveDataSubIdReadPhoneStateEnforcedInPlatformCompat(String packageName, + UserHandle userHandle) { + return Binder.withCleanCallingIdentity(() -> CompatChanges.isChangeEnabled( + REQUIRE_READ_PHONE_STATE_PERMISSION_FOR_ACTIVE_DATA_SUB_ID, packageName, + userHandle)); + } + + /** + * To check the SDK version for + * {@link android.telephony.TelephonyCallback.CellInfoListener} should add + * {@link android.Manifest.permission#READ_PHONE_STATE} since Android 12. + * @noinspection ConstantConditions + */ + public boolean isCellInfoReadPhoneStateEnforcedInPlatformCompat(String packageName, + UserHandle userHandle) { + return Binder.withCleanCallingIdentity(() -> CompatChanges.isChangeEnabled( + REQUIRE_READ_PHONE_STATE_PERMISSION_FOR_CELL_INFO, packageName, userHandle)); + } + + /** + * To check the SDK version for + * {@link android.telephony.TelephonyCallback.DisplayInfoListener} should remove + * {@link android.Manifest.permission#READ_PHONE_STATE} since Android 12. + * @noinspection ConstantConditions + */ + public boolean isDisplayInfoReadPhoneStateEnforcedInPlatformCompat(String packageName, + UserHandle userHandle) { + return Binder.withCleanCallingIdentity(() -> CompatChanges.isChangeEnabled( + REQUIRE_READ_PHONE_STATE_PERMISSION_FOR_DISPLAY_INFO, packageName, userHandle)); + } + + /** + * Support backward compatibility for {@link android.telephony.TelephonyDisplayInfo}. + * + * @noinspection ConstantConditions + */ + public boolean isDisplayInfoNrAdvancedSupported(String packageName, + UserHandle userHandle) { + return Binder.withCleanCallingIdentity(() -> CompatChanges.isChangeEnabled( + DISPLAY_INFO_NR_ADVANCED_SUPPORTED, packageName, userHandle)); + } } private final Context mContext; @@ -346,6 +395,39 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { */ private List, PreciseDataConnectionState>> mPreciseDataConnectionStates; + /** + * Support backward compatibility for {@link android.telephony.TelephonyDisplayInfo}. + */ + @ChangeId + @EnabledSince(targetSdkVersion = Build.VERSION_CODES.S) + private static final long DISPLAY_INFO_NR_ADVANCED_SUPPORTED = 181658987L; + + /** + * To check the SDK version for + * {@link android.telephony.TelephonyCallback.DisplayInfoListener} should remove + * {@link android.Manifest.permission#READ_PHONE_STATE} since Android 12. + */ + @ChangeId + @EnabledSince(targetSdkVersion = Build.VERSION_CODES.S) + private static final long REQUIRE_READ_PHONE_STATE_PERMISSION_FOR_DISPLAY_INFO = 183164979L; + + /** + * To check the SDK version for + * {@link android.telephony.TelephonyCallback.ActiveDataSubscriptionIdListener} should add + * {@link android.Manifest.permission#READ_PHONE_STATE} since Android 12. + */ + @ChangeId + @EnabledSince(targetSdkVersion = Build.VERSION_CODES.S) + private static final long REQUIRE_READ_PHONE_STATE_PERMISSION_FOR_ACTIVE_DATA_SUB_ID + = 182478738L; + + /** + * To check the SDK version for {@link android.telephony.TelephonyCallback.CellInfoListener} + * should add {@link android.Manifest.permission#READ_PHONE_STATE} since Android 12. + */ + @ChangeId + @EnabledSince(targetSdkVersion = Build.VERSION_CODES.S) + private static final long REQUIRE_READ_PHONE_STATE_PERMISSION_FOR_CELL_INFO = 184323934L; private static final Set REQUIRE_PRECISE_PHONE_STATE_PERMISSION; static { @@ -379,13 +461,46 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { || events.contains(TelephonyCallback.EVENT_BARRING_INFO_CHANGED); } - private boolean isPhoneStatePermissionRequired(Set events, int targetSdk) { - return events.contains(TelephonyCallback.EVENT_CALL_FORWARDING_INDICATOR_CHANGED) + private boolean isPhoneStatePermissionRequired(Set events, String callingPackage, + UserHandle userHandle) { + if (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) - || (targetSdk <= android.os.Build.VERSION_CODES.R ? events.contains( - TelephonyCallback.EVENT_DISPLAY_INFO_CHANGED) : false); + || events.contains(TelephonyCallback.EVENT_EMERGENCY_NUMBER_LIST_CHANGED)) { + return true; + } + + // Only check READ_PHONE_STATE for CALL_STATE_CHANGED for Android 12 or above. + if ((events.contains(TelephonyCallback.EVENT_LEGACY_CALL_STATE_CHANGED) + || events.contains(TelephonyCallback.EVENT_CALL_STATE_CHANGED)) + && mConfigurationProvider.isCallStateReadPhoneStateEnforcedInPlatformCompat( + callingPackage, userHandle)) { + return true; + } + + // Only check READ_PHONE_STATE for ACTIVE_DATA_SUBSCRIPTION_ID_CHANGED for Android 12 + // or above. + if (events.contains(TelephonyCallback.EVENT_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGED) + && mConfigurationProvider.isActiveDataSubIdReadPhoneStateEnforcedInPlatformCompat( + callingPackage, userHandle)) { + return true; + } + + // Only check READ_PHONE_STATE for CELL_INFO_CHANGED for Android 12 or above. + if (events.contains(TelephonyCallback.EVENT_CELL_INFO_CHANGED) + && mConfigurationProvider.isCellInfoReadPhoneStateEnforcedInPlatformCompat( + callingPackage, userHandle)) { + return true; + } + + // Only check READ_PHONE_STATE for DISPLAY_INFO_CHANGED for Android 11 or older. + // READ_PHONE_STATE is not required anymore after Android 12. + if (events.contains(TelephonyCallback.EVENT_DISPLAY_INFO_CHANGED) + && !mConfigurationProvider.isDisplayInfoReadPhoneStateEnforcedInPlatformCompat( + callingPackage, userHandle)) { + return true; + } + + return false; } private boolean isPrecisePhoneStatePermissionRequired(Set events) { @@ -897,12 +1012,11 @@ 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", callerTargetSdk)) { + if (!checkListenerPermission(events, subId, callingPackage, callingFeatureId, "listen")) { return; } @@ -935,7 +1049,6 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { } r.phoneId = phoneId; r.eventList = events; - r.targetSdk = callerTargetSdk; if (DBG) { log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId); @@ -1768,7 +1881,8 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { TelephonyCallback.EVENT_DISPLAY_INFO_CHANGED) && idMatchWithoutDefaultPhoneCheck(r.subId, subId)) { try { - if (r.targetSdk <= android.os.Build.VERSION_CODES.R) { + if (!mConfigurationProvider.isDisplayInfoNrAdvancedSupported( + r.callingPackage, Binder.getCallingUserHandle())) { telephonyDisplayInfo = getBackwardCompatibleTelephonyDisplayInfo( telephonyDisplayInfo); @@ -2917,7 +3031,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { } private boolean checkListenerPermission(Set events, int subId, String callingPackage, - @Nullable String callingFeatureId, String message, int targetSdk) { + @Nullable String callingFeatureId, String message) { LocationAccessPolicy.LocationPermissionQuery.Builder locationQueryBuilder = new LocationAccessPolicy.LocationPermissionQuery.Builder() .setCallingPackage(callingPackage) @@ -2953,26 +3067,13 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { } } - if (isPhoneStatePermissionRequired(events, targetSdk)) { + if (isPhoneStatePermissionRequired(events, callingPackage, Binder.getCallingUserHandle())) { if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( mContext, subId, callingPackage, callingFeatureId, message)) { isPermissionCheckSuccessful = false; } } - // Only check READ_PHONE_STATE for CALL_STATE_CHANGED for API 31+. - if (mConfigurationProvider.isCallStateReadPhoneStateEnforcedInPlatformCompat(callingPackage, - Binder.getCallingUserHandle())) { - if (events.contains(TelephonyCallback.EVENT_LEGACY_CALL_STATE_CHANGED) - || events.contains(TelephonyCallback.EVENT_CALL_STATE_CHANGED)) { - if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( - mContext, subId, callingPackage, callingFeatureId, message)) { - throw new SecurityException("CALL_STATE_CHANGED event requires " - + "READ_PHONE_STATE"); - } - } - } - if (isPrecisePhoneStatePermissionRequired(events)) { // check if calling app has either permission READ_PRECISE_PHONE_STATE // or with carrier privileges