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

Commit db859e7e authored by Malcolm Chen's avatar Malcolm Chen Committed by Nazanin Bakhshi
Browse files

Rename PREFERRED_DATA_SUBID_CHANGE to ACTIVE_DATA_SUB_CHANGE

Redefine a PhoneStateListener event so that it reflects which
subscription is currently being used for Internet data. It could
be default user data subscription or currently active opportunistic
subscription.

Bug: 124260187
Test: unittest
Change-Id: Icb90b5bd93845c29157cafddcd53335728638ec2
Merged-In: Icb90b5bd93845c29157cafddcd53335728638ec2
parent 10c573ff
Loading
Loading
Loading
Loading
+13 −18
Original line number Diff line number Diff line
@@ -238,6 +238,8 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {

    private PhoneCapability mPhoneCapability = null;

    private int mActiveDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;

    @TelephonyManager.RadioPowerState
    private int mRadioPowerState = TelephonyManager.RADIO_POWER_UNAVAILABLE;

@@ -258,7 +260,8 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
    static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
                PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR
                        | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR
                        | PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST;
                        | PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST
                        | PhoneStateListener.LISTEN_ACTIVE_DATA_SUBID_CHANGE;

    static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
                PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
@@ -818,9 +821,9 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
                            remove(r.binder);
                        }
                    }
                    if ((events & PhoneStateListener.LISTEN_PREFERRED_DATA_SUBID_CHANGE) != 0) {
                    if ((events & PhoneStateListener.LISTEN_ACTIVE_DATA_SUBID_CHANGE) != 0) {
                        try {
                            r.callback.onPreferredDataSubIdChanged(mPreferredDataSubId);
                            r.callback.onActiveDataSubIdChanged(mActiveDataSubId);
                        } catch (RemoteException ex) {
                            remove(r.binder);
                        }
@@ -1740,23 +1743,23 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
        }
    }

    public void notifyPreferredDataSubIdChanged(int preferredSubId) {
        if (!checkNotifyPermission("notifyPreferredDataSubIdChanged()")) {
    public void notifyActiveDataSubIdChanged(int activeDataSubId) {
        if (!checkNotifyPermission("notifyActiveDataSubIdChanged()")) {
            return;
        }

        if (VDBG) {
            log("notifyPreferredDataSubIdChanged: preferredSubId=" + preferredSubId);
            log("notifyActiveDataSubIdChanged: activeDataSubId=" + activeDataSubId);
        }

        synchronized (mRecords) {
            mPreferredDataSubId = preferredSubId;
            mActiveDataSubId = activeDataSubId;

            for (Record r : mRecords) {
                if (r.matchPhoneStateListenerEvent(
                        PhoneStateListener.LISTEN_PREFERRED_DATA_SUBID_CHANGE)) {
                        PhoneStateListener.LISTEN_ACTIVE_DATA_SUBID_CHANGE)) {
                    try {
                        r.callback.onPreferredDataSubIdChanged(preferredSubId);
                        r.callback.onActiveDataSubIdChanged(activeDataSubId);
                    } catch (RemoteException ex) {
                        mRemoveList.add(r.binder);
                    }
@@ -1893,7 +1896,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
            pw.println("mBackgroundCallState=" + mBackgroundCallState);
            pw.println("mSrvccState=" + mSrvccState);
            pw.println("mPhoneCapability=" + mPhoneCapability);
            pw.println("mPreferredDataSubId=" + mPreferredDataSubId);
            pw.println("mActiveDataSubId=" + mActiveDataSubId);
            pw.println("mRadioPowerState=" + mRadioPowerState);
            pw.println("mEmergencyNumberList=" + mEmergencyNumberList);
            pw.println("mCallQuality=" + mCallQuality);
@@ -2165,14 +2168,6 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
                    android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
        }

        if ((events & PhoneStateListener.LISTEN_PREFERRED_DATA_SUBID_CHANGE) != 0) {
            // It can have either READ_PHONE_STATE or READ_PRIVILEGED_PHONE_STATE.
            TelephonyPermissions.checkReadPhoneState(mContext,
                    SubscriptionManager.INVALID_SUBSCRIPTION_ID, Binder.getCallingPid(),
                    Binder.getCallingUid(), callingPackage, "listen to "
                            + "LISTEN_PREFERRED_DATA_SUBID_CHANGE");
        }

        if ((events & PhoneStateListener.LISTEN_CALL_DISCONNECT_CAUSES) != 0) {
            mContext.enforceCallingOrSelfPermission(
                    android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
+16 −13
Original line number Diff line number Diff line
@@ -292,14 +292,17 @@ public class PhoneStateListener {
    public static final int LISTEN_PHONE_CAPABILITY_CHANGE                 = 0x00200000;

    /**
     *  Listen for changes to preferred data subId.
     *  See {@link SubscriptionManager#setPreferredDataSubId(int)}
     *  for more details.
     *  Listen for changes to active data subId. Active data subscription
     *  is whichever is being used for Internet data. For most of the case, it's
     *  default data subscription but it could be others. For example, when data is
     *  switched to opportunistic subscription, that becomes the active data sub.
     *
     *  @see #onPreferredDataSubIdChanged
     *  Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE
     *  READ_PHONE_STATE}
     *  @see #onActiveDataSubIdChanged
     *  @hide
     */
    public static final int LISTEN_PREFERRED_DATA_SUBID_CHANGE              = 0x00400000;
    public static final int LISTEN_ACTIVE_DATA_SUBID_CHANGE               = 0x00400000;

    /**
     *  Listen for changes to the radio power state.
@@ -704,14 +707,14 @@ public class PhoneStateListener {
    }

    /**
     * Callback invoked when preferred data subId changes. Requires
     * the READ_PRIVILEGED_PHONE_STATE permission.
     * @param subId the new preferred data subId. If it's INVALID_SUBSCRIPTION_ID,
     *              it means it's unset and defaultDataSub is used to determine which
     *              modem is preferred.
     * Callback invoked when active data subId changes. Requires
     * the READ_PHONE_STATE permission.
     * @param subId current data subId used for Internet data. It will be default data subscription
     *              most cases. And it could be other subscriptions for example opportunistic
     *              subscription if data is switched onto it.
     * @hide
     */
    public void onPreferredDataSubIdChanged(int subId) {
    public void onActiveDataSubIdChanged(int subId) {
        // default implementation empty
    }

@@ -995,12 +998,12 @@ public class PhoneStateListener {
                    () -> mExecutor.execute(() -> psl.onCallAttributesChanged(callAttributes)));
        }

        public void onPreferredDataSubIdChanged(int subId) {
        public void onActiveDataSubIdChanged(int subId) {
            PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
            if (psl == null) return;

            Binder.withCleanCallingIdentity(
                    () -> mExecutor.execute(() -> psl.onPreferredDataSubIdChanged(subId)));
                    () -> mExecutor.execute(() -> psl.onActiveDataSubIdChanged(subId)));
        }

        public void onImsCallDisconnectCauseChanged(ImsReasonInfo disconnectCause) {
+1 −1
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ oneway interface IPhoneStateListener {
    void onCarrierNetworkChange(in boolean active);
    void onUserMobileDataStateChanged(in boolean enabled);
    void onPhoneCapabilityChanged(in PhoneCapability capability);
    void onPreferredDataSubIdChanged(in int subId);
    void onActiveDataSubIdChanged(in int subId);
    void onRadioPowerStateChanged(in int state);
    void onCallAttributesChanged(in CallAttributes callAttributes);
    void onEmergencyNumberListChanged(in Map emergencyNumberList);
+1 −1
Original line number Diff line number Diff line
@@ -85,7 +85,7 @@ interface ITelephonyRegistry {
    void notifyCarrierNetworkChange(in boolean active);
    void notifyUserMobileDataStateChangedForPhoneId(in int phoneId, in int subId, in boolean state);
    void notifyPhoneCapabilityChanged(in PhoneCapability capability);
    void notifyPreferredDataSubIdChanged(int preferredSubId);
    void notifyActiveDataSubIdChanged(int activeDataSubId);
    void notifyRadioPowerStateChanged(in int state);
    void notifyEmergencyNumberList();
    void notifyCallQualityChanged(in CallQuality callQuality, int phoneId, int callNetworkType);