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

Commit f919aec7 authored by Xiangyu/Malcolm Chen's avatar Xiangyu/Malcolm Chen Committed by Android (Google) Code Review
Browse files

Merge "Add PhoneStateListener#onPreferredDataSubIdChanged"

parents 02575906 8b53afe6
Loading
Loading
Loading
Loading
+35 −0
Original line number Diff line number Diff line
@@ -213,6 +213,8 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {

    private PhoneCapability mPhoneCapability = null;

    private int mPreferredDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;

    private final LocalLog mLocalLog = new LocalLog(100);

    private PreciseDataConnectionState mPreciseDataConnectionState =
@@ -752,6 +754,13 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
                            remove(r.binder);
                        }
                    }
                    if ((events & PhoneStateListener.LISTEN_PREFERRED_DATA_SUBID_CHANGE) != 0) {
                        try {
                            r.callback.onPreferredDataSubIdChanged(mPreferredDataSubId);
                        } catch (RemoteException ex) {
                            remove(r.binder);
                        }
                    }
                }
            }
        } else {
@@ -1573,6 +1582,31 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
        }
    }

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

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

        synchronized (mRecords) {
            mPreferredDataSubId = preferredSubId;

            for (Record r : mRecords) {
                if (r.matchPhoneStateListenerEvent(
                        PhoneStateListener.LISTEN_PREFERRED_DATA_SUBID_CHANGE)) {
                    try {
                        r.callback.onPreferredDataSubIdChanged(preferredSubId);
                    } catch (RemoteException ex) {
                        mRemoveList.add(r.binder);
                    }
                }
            }
            handleRemoveListLocked();
        }
    }

    @Override
    public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
@@ -1610,6 +1644,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
            pw.println("mBackgroundCallState=" + mBackgroundCallState);
            pw.println("mVoLteServiceState=" + mVoLteServiceState);
            pw.println("mPhoneCapability=" + mPhoneCapability);
            pw.println("mPreferredDataSubId=" + mPreferredDataSubId);

            pw.decreaseIndent();

+30 −0
Original line number Diff line number Diff line
@@ -281,6 +281,16 @@ public class PhoneStateListener {
     */
    public static final int LISTEN_PHONE_CAPABILITY_CHANGE                 = 0x00200000;

    /**
     *  Listen for changes to preferred data subId.
     *  See {@link SubscriptionManager#setPreferredData(int)}
     *  for more details.
     *
     *  @see #onPreferredDataSubIdChanged
     *  @hide
     */
    public static final int LISTEN_PREFERRED_DATA_SUBID_CHANGE              = 0x00400000;

    /*
     * Subscription used to listen to the phone state changes
     * @hide
@@ -407,6 +417,9 @@ public class PhoneStateListener {
                        PhoneStateListener.this.onPhoneCapabilityChanged(
                                (PhoneCapability) msg.obj);
                        break;
                    case LISTEN_PREFERRED_DATA_SUBID_CHANGE:
                        PhoneStateListener.this.onPreferredDataSubIdChanged((int) msg.obj);
                        break;
                }
            }
        };
@@ -646,6 +659,18 @@ public class PhoneStateListener {
        // default implementation empty
    }

    /**
     * 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.
     * @hide
     */
    public void onPreferredDataSubIdChanged(int subId) {
        // default implementation empty
    }

    /**
     * Callback invoked when telephony has received notice from a carrier
     * app that a network action that could result in connectivity loss
@@ -777,6 +802,11 @@ public class PhoneStateListener {
        public void onPhoneCapabilityChanged(PhoneCapability capability) {
            send(LISTEN_PHONE_CAPABILITY_CHANGE, 0, 0, capability);
        }

        public void onPreferredDataSubIdChanged(int subId) {
            send(LISTEN_PREFERRED_DATA_SUBID_CHANGE, 0, 0, subId);
        }

    }

    /**
+4 −3
Original line number Diff line number Diff line
@@ -2157,10 +2157,11 @@ public class SubscriptionManager {
     * It's also usually what we set up internet connection on.
     *
     * PreferredData overwrites user setting of default data subscription. And it's used
     * by ANAS or carrier apps to switch primary and CBRS subscription dynamically in multi-SIM
     * devices.
     * by AlternativeNetworkAccessService or carrier apps to switch primary and CBRS
     * subscription dynamically in multi-SIM devices.
     *
     * @param slotId which slot is preferred to for cellular data.
     * @param slotId which slot is preferred to for cellular data. If it's INVALID, it means
     *               it's unset and defaultDataSubId is used to determine which modem is preferred.
     * @hide
     *
     */
+1 −0
Original line number Diff line number Diff line
@@ -52,5 +52,6 @@ oneway interface IPhoneStateListener {
    void onCarrierNetworkChange(in boolean active);
    void onUserMobileDataStateChanged(in boolean enabled);
    void onPhoneCapabilityChanged(in PhoneCapability capability);
    void onPreferredDataSubIdChanged(in int subId);
}
+1 −0
Original line number Diff line number Diff line
@@ -79,4 +79,5 @@ 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);
}