diff options
8 files changed, 81 insertions, 31 deletions
diff --git a/core/api/current.txt b/core/api/current.txt index 2e0282a8d7a4..ba6f4409306d 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -42142,7 +42142,7 @@ package android.telephony { } public static interface TelephonyCallback.CallStateListener { - method @RequiresPermission(android.Manifest.permission.READ_CALL_LOG) public void onCallStateChanged(int, @Nullable String); + method public void onCallStateChanged(int); } public static interface TelephonyCallback.CarrierNetworkListener { diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 5ca4d35d4c22..56241bf9e9a7 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -11403,7 +11403,7 @@ package android.telephony { 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 @RequiresPermission(android.Manifest.permission.READ_CALL_LOG) public static final int EVENT_CALL_STATE_CHANGED = 6; // 0x6 + 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(android.Manifest.permission.ACCESS_FINE_LOCATION) public static final int EVENT_CELL_LOCATION_CHANGED = 5; // 0x5 @@ -11415,6 +11415,7 @@ package android.telephony { field public static final int EVENT_DISPLAY_INFO_CHANGED = 21; // 0x15 field @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public static final int EVENT_EMERGENCY_NUMBER_LIST_CHANGED = 25; // 0x19 field @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE) public static final int EVENT_IMS_CALL_DISCONNECT_CAUSE_CHANGED = 28; // 0x1c + field @RequiresPermission(android.Manifest.permission.READ_CALL_LOG) public static final int EVENT_LEGACY_CALL_STATE_CHANGED = 36; // 0x24 field @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public static final int EVENT_MESSAGE_WAITING_INDICATOR_CHANGED = 3; // 0x3 field @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public static final int EVENT_OEM_HOOK_RAW = 15; // 0xf field @RequiresPermission(android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION) public static final int EVENT_OUTGOING_EMERGENCY_CALL = 29; // 0x1d diff --git a/core/java/android/telephony/PhoneStateListener.java b/core/java/android/telephony/PhoneStateListener.java index e37921ec03cc..bbe887f500a9 100644 --- a/core/java/android/telephony/PhoneStateListener.java +++ b/core/java/android/telephony/PhoneStateListener.java @@ -1326,7 +1326,7 @@ public class PhoneStateListener { () -> mExecutor.execute(() -> psl.onCellLocationChanged(location))); } - public void onCallStateChanged(int state, String incomingNumber) { + public void onLegacyCallStateChanged(int state, String incomingNumber) { PhoneStateListener psl = mPhoneStateListenerWeakRef.get(); if (psl == null) return; @@ -1334,6 +1334,10 @@ public class PhoneStateListener { () -> mExecutor.execute(() -> psl.onCallStateChanged(state, incomingNumber))); } + public void onCallStateChanged(int state) { + // Only used for the new TelephonyCallback class + } + public void onDataConnectionStateChanged(int state, int networkType) { PhoneStateListener psl = mPhoneStateListenerWeakRef.get(); if (psl == null) return; diff --git a/core/java/android/telephony/TelephonyCallback.java b/core/java/android/telephony/TelephonyCallback.java index a2584cae1b9c..2cadda25a9d3 100644 --- a/core/java/android/telephony/TelephonyCallback.java +++ b/core/java/android/telephony/TelephonyCallback.java @@ -20,11 +20,9 @@ import android.Manifest; import android.annotation.CallbackExecutor; import android.annotation.IntDef; import android.annotation.NonNull; -import android.annotation.Nullable; import android.annotation.RequiresPermission; import android.annotation.SystemApi; import android.compat.annotation.ChangeId; -import android.compat.annotation.UnsupportedAppUsage; import android.os.Binder; import android.os.Build; import android.telephony.emergency.EmergencyNumber; @@ -170,12 +168,15 @@ public class TelephonyCallback { /** * Event for changes to the device call state. - * + * <p> + * Handles callbacks to {@link CallStateListener#onCallStateChanged(int)}. + * <p> + * Note: This is different from the legacy {@link #EVENT_LEGACY_CALL_STATE_CHANGED} listener + * which can include the phone number of the caller. We purposely do not include the phone + * number as that information is not required for call state listeners going forward. * @hide - * @see CallStateListener#onCallStateChanged */ @SystemApi - @RequiresPermission(android.Manifest.permission.READ_CALL_LOG) public static final int EVENT_CALL_STATE_CHANGED = 6; /** @@ -556,6 +557,18 @@ public class TelephonyCallback { public static final int EVENT_ALLOWED_NETWORK_TYPE_LIST_CHANGED = 35; /** + * Event for changes to the legacy call state changed listener implemented by + * {@link PhoneStateListener#onCallStateChanged(int, String)}. This listener variant is similar + * to the new {@link CallStateListener#onCallStateChanged(int)} with the important distinction + * that it CAN provide the phone number associated with a call. + * + * @hide + */ + @SystemApi + @RequiresPermission(android.Manifest.permission.READ_CALL_LOG) + public static final int EVENT_LEGACY_CALL_STATE_CHANGED = 36; + + /** * @hide */ @IntDef(prefix = {"EVENT_"}, value = { @@ -593,7 +606,8 @@ public class TelephonyCallback { EVENT_BARRING_INFO_CHANGED, EVENT_PHYSICAL_CHANNEL_CONFIG_CHANGED, EVENT_DATA_ENABLED_CHANGED, - EVENT_ALLOWED_NETWORK_TYPE_LIST_CHANGED + EVENT_ALLOWED_NETWORK_TYPE_LIST_CHANGED, + EVENT_LEGACY_CALL_STATE_CHANGED }) @Retention(RetentionPolicy.SOURCE) public @interface TelephonyEvent { @@ -723,17 +737,9 @@ public class TelephonyCallback { * calling {@link TelephonyManager#getCallState()} from within this callback may return a * different state than the callback reports. * - * @param state call state - * @param phoneNumber call phone number. If application does not have - * {@link android.Manifest.permission#READ_CALL_LOG} permission or - * carrier - * privileges (see {@link TelephonyManager#hasCarrierPrivileges}), an - * empty string will be - * passed as an argument. + * @param state the current call state */ - @RequiresPermission(android.Manifest.permission.READ_CALL_LOG) - public void onCallStateChanged(@Annotation.CallState int state, - @Nullable String phoneNumber); + public void onCallStateChanged(@Annotation.CallState int state); } /** @@ -1426,13 +1432,17 @@ public class TelephonyCallback { () -> mExecutor.execute(() -> listener.onCellLocationChanged(location))); } - public void onCallStateChanged(int state, String incomingNumber) { + public void onLegacyCallStateChanged(int state, String incomingNumber) { + // Not used for TelephonyCallback; part of the AIDL which is used by both the legacy + // PhoneStateListener and TelephonyCallback. + } + + public void onCallStateChanged(int state) { CallStateListener listener = (CallStateListener) mTelephonyCallbackWeakRef.get(); if (listener == null) return; Binder.withCleanCallingIdentity( - () -> mExecutor.execute(() -> listener.onCallStateChanged(state, - incomingNumber))); + () -> mExecutor.execute(() -> listener.onCallStateChanged(state))); } public void onDataConnectionStateChanged(int state, int networkType) { diff --git a/core/java/android/telephony/TelephonyRegistryManager.java b/core/java/android/telephony/TelephonyRegistryManager.java index 459c6e94e4ac..9cda4ae79335 100644 --- a/core/java/android/telephony/TelephonyRegistryManager.java +++ b/core/java/android/telephony/TelephonyRegistryManager.java @@ -861,6 +861,7 @@ public class TelephonyRegistryManager { eventList.add(TelephonyCallback.EVENT_CELL_LOCATION_CHANGED); } + // Note: Legacy PhoneStateListeners use EVENT_LEGACY_CALL_STATE_CHANGED if (telephonyCallback instanceof TelephonyCallback.CallStateListener) { eventList.add(TelephonyCallback.EVENT_CALL_STATE_CHANGED); } @@ -1000,8 +1001,10 @@ public class TelephonyRegistryManager { eventList.add(TelephonyCallback.EVENT_CELL_LOCATION_CHANGED); } + // Note: Legacy call state listeners can get the phone number which is not provided in the + // new version in TelephonyCallback. if ((eventMask & PhoneStateListener.LISTEN_CALL_STATE) != 0) { - eventList.add(TelephonyCallback.EVENT_CALL_STATE_CHANGED); + eventList.add(TelephonyCallback.EVENT_LEGACY_CALL_STATE_CHANGED); } if ((eventMask & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) { diff --git a/core/java/com/android/internal/telephony/IPhoneStateListener.aidl b/core/java/com/android/internal/telephony/IPhoneStateListener.aidl index ee94ef8ddda3..85114e59cc2d 100644 --- a/core/java/com/android/internal/telephony/IPhoneStateListener.aidl +++ b/core/java/com/android/internal/telephony/IPhoneStateListener.aidl @@ -42,7 +42,8 @@ oneway interface IPhoneStateListener { // Uses CellIdentity which is Parcelable here; will convert to CellLocation in client. void onCellLocationChanged(in CellIdentity location); - void onCallStateChanged(int state, String incomingNumber); + void onLegacyCallStateChanged(int state, String incomingNumber); + void onCallStateChanged(int state); void onDataConnectionStateChanged(int state, int networkType); void onDataActivity(int direction); void onSignalStrengthsChanged(in SignalStrength signalStrength); diff --git a/services/core/java/com/android/server/TelephonyRegistry.java b/services/core/java/com/android/server/TelephonyRegistry.java index 978bd643f9b7..a9904ba0de91 100644 --- a/services/core/java/com/android/server/TelephonyRegistry.java +++ b/services/core/java/com/android/server/TelephonyRegistry.java @@ -964,14 +964,21 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { remove(r.binder); } } - if (events.contains(TelephonyCallback.EVENT_CALL_STATE_CHANGED)) { + if (events.contains(TelephonyCallback.EVENT_LEGACY_CALL_STATE_CHANGED)) { try { - r.callback.onCallStateChanged(mCallState[phoneId], + r.callback.onLegacyCallStateChanged(mCallState[phoneId], getCallIncomingNumber(r, phoneId)); } catch (RemoteException ex) { remove(r.binder); } } + if (events.contains(TelephonyCallback.EVENT_CALL_STATE_CHANGED)) { + try { + r.callback.onCallStateChanged(mCallState[phoneId]); + } catch (RemoteException ex) { + remove(r.binder); + } + } if (events.contains(TelephonyCallback.EVENT_DATA_CONNECTION_STATE_CHANGED)) { try { r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId], @@ -1306,13 +1313,24 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { synchronized (mRecords) { for (Record r : mRecords) { - if (r.matchTelephonyCallbackEvent(TelephonyCallback.EVENT_CALL_STATE_CHANGED) + if (r.matchTelephonyCallbackEvent(TelephonyCallback.EVENT_LEGACY_CALL_STATE_CHANGED) && (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) { try { // Ensure the listener has read call log permission; if they do not return // an empty phone number. + // This is ONLY for legacy onCallStateChanged in PhoneStateListener. String phoneNumberOrEmpty = r.canReadCallLog() ? phoneNumber : ""; - r.callback.onCallStateChanged(state, phoneNumberOrEmpty); + r.callback.onLegacyCallStateChanged(state, phoneNumberOrEmpty); + } catch (RemoteException ex) { + mRemoveList.add(r.binder); + } + } + + if (r.matchTelephonyCallbackEvent(TelephonyCallback.EVENT_CALL_STATE_CHANGED) + && (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) { + try { + // The new callback does NOT provide the phone number. + r.callback.onCallStateChanged(state); } catch (RemoteException ex) { mRemoveList.add(r.binder); } @@ -1341,12 +1359,25 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { mCallState[phoneId] = state; mCallIncomingNumber[phoneId] = incomingNumber; for (Record r : mRecords) { - if (r.matchTelephonyCallbackEvent(TelephonyCallback.EVENT_CALL_STATE_CHANGED) + if (r.matchTelephonyCallbackEvent( + TelephonyCallback.EVENT_LEGACY_CALL_STATE_CHANGED) && (r.subId == subId) && (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) { try { + // Only the legacy PhoneStateListener receives the phone number. String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId); - r.callback.onCallStateChanged(state, incomingNumberOrEmpty); + r.callback.onLegacyCallStateChanged(state, incomingNumberOrEmpty); + } catch (RemoteException ex) { + mRemoveList.add(r.binder); + } + } + if (r.matchTelephonyCallbackEvent(TelephonyCallback.EVENT_CALL_STATE_CHANGED) + && (r.subId == subId) + && (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) { + try { + // The phone number is not included in the new call state changed + // listener. + r.callback.onCallStateChanged(state); } catch (RemoteException ex) { mRemoveList.add(r.binder); } diff --git a/services/core/java/com/android/server/location/injector/SystemEmergencyHelper.java b/services/core/java/com/android/server/location/injector/SystemEmergencyHelper.java index dbd8dd9eff3b..aa3e5795b684 100644 --- a/services/core/java/com/android/server/location/injector/SystemEmergencyHelper.java +++ b/services/core/java/com/android/server/location/injector/SystemEmergencyHelper.java @@ -82,7 +82,7 @@ public class SystemEmergencyHelper extends EmergencyHelper { TelephonyCallback.CallStateListener{ @Override - public void onCallStateChanged(int state, String incomingNumber) { + public void onCallStateChanged(int state) { if (state == TelephonyManager.CALL_STATE_IDLE) { if (mIsInEmergencyCall) { mEmergencyCallEndRealtimeMs = SystemClock.elapsedRealtime(); |