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

Commit 6b46264c authored by chen xu's avatar chen xu
Browse files

only set PhoneStateListener subId for sdk target >=Q

subId from PhoneStateListener is deprecated from Q. And we should
only set subId for informational purpose for Q+ only.
Do not change the legacy behaviour for apps target on preQ SDK level

Bug: 131863032
Test: atest CtsTelephonyTestCases:PhoneStateListenerTest#testOnUnRegisterFollowedByRegister
Change-Id: Iff1758f9645e74690094207d92b5989553b27b25
parent a9ac86f6
Loading
Loading
Loading
Loading
+10 −14
Original line number Original line Diff line number Diff line
@@ -4897,24 +4897,20 @@ public class TelephonyManager {
            boolean notifyNow = (getITelephony() != null);
            boolean notifyNow = (getITelephony() != null);
            ITelephonyRegistry registry = getTelephonyRegistry();
            ITelephonyRegistry registry = getTelephonyRegistry();
            if (registry != null) {
            if (registry != null) {
                int subId;
                // subId from PhoneStateListener is deprecated Q on forward, use the subId from
                // subId from phonestatelistner is deprecated Q on forward, use the subId from
                // TelephonyManager instance. keep using subId from PhoneStateListener for pre-Q.
                // TelephonyManager instance.
                int subId = mSubId;
                if (VMRuntime.getRuntime().getTargetSdkVersion() >= Build.VERSION_CODES.Q
                if (VMRuntime.getRuntime().getTargetSdkVersion() >= Build.VERSION_CODES.Q) {
                        || listener.mSubId == null) {
                    // since mSubId in PhoneStateListener is deprecated from Q on forward, this is
                    subId = mSubId;
                    // the only place to set mSubId and its for "informational" only.
                } else {
                    //  TODO: remove this once we completely get rid of mSubId in PhoneStateListener
                    listener.mSubId = (events == PhoneStateListener.LISTEN_NONE)
                            ? SubscriptionManager.INVALID_SUBSCRIPTION_ID : subId;
                } else if (listener.mSubId != null) {
                    subId = listener.mSubId;
                    subId = listener.mSubId;
                }
                }

                registry.listenForSubscriber(subId, getOpPackageName(),
                registry.listenForSubscriber(subId, getOpPackageName(),
                        listener.callback, events, notifyNow);
                        listener.callback, events, notifyNow);
                // TODO: remove this once we remove PhoneStateListener constructor with subId.
                if (events == PhoneStateListener.LISTEN_NONE) {
                    listener.mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
                } else {
                    listener.mSubId = subId;
                }
            } else {
            } else {
                Rlog.w(TAG, "telephony registry not ready.");
                Rlog.w(TAG, "telephony registry not ready.");
            }
            }