Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 95674c6c authored by Tyler Gunn's avatar Tyler Gunn
Browse files

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
parent 86234a6e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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 {
+2 −1
Original line number Diff line number Diff line
@@ -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
+5 −1
Original line number Diff line number Diff line
@@ -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;
+29 −19
Original line number Diff line number Diff line
@@ -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) {
+4 −1
Original line number Diff line number Diff line
@@ -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) {
Loading