Remove phone number from the "new" CallStateListener.
When the legacy PhoneStateListener was migrated to the new TelephonyCallback class, the onCallStateChanged listener was copied over as is. This CL removes the phone number parameter from the new listener. Under the hood, both the old PhoneStateListener and the new one use the same IPhoneStateListener.aidl file, so the onCallStateChanged method for the legacy listener is changed to onLegacyCallStateListener. Test: See CTS test CL; added a bunch of CTS tests for this. Fixes: 165831812 Change-Id: Ia67968b5235954b606c6bd2890cc6f46c468e041
This commit is contained in:
@@ -42056,7 +42056,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 {
|
||||
|
||||
@@ -11437,7 +11437,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
|
||||
@@ -11449,6 +11449,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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
@@ -555,6 +556,18 @@ public class TelephonyCallback {
|
||||
@RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
|
||||
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
|
||||
*/
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -964,10 +964,17 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
|
||||
remove(r.binder);
|
||||
}
|
||||
}
|
||||
if (events.contains(TelephonyCallback.EVENT_LEGACY_CALL_STATE_CHANGED)) {
|
||||
try {
|
||||
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],
|
||||
getCallIncomingNumber(r, phoneId));
|
||||
r.callback.onCallStateChanged(mCallState[phoneId]);
|
||||
} catch (RemoteException ex) {
|
||||
remove(r.binder);
|
||||
}
|
||||
@@ -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_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.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 {
|
||||
String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
|
||||
r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
|
||||
// The phone number is not included in the new call state changed
|
||||
// listener.
|
||||
r.callback.onCallStateChanged(state);
|
||||
} catch (RemoteException ex) {
|
||||
mRemoveList.add(r.binder);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user