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

Commit 4a5ebd60 authored by Jordan Liu's avatar Jordan Liu
Browse files

Send placeholder OOS ServiceState when subId goes invalid

When subId for a phone becomes -1, we would like to leave service
state listeners in a correct terminal state, so broadcast a placeholder
OOS state to the phone's old subId.

Bug: 162395073
Test: manually remove SIM and verify notification on previous subId
Change-Id: Id0e150dacbd762a2e5e801d200241334d10a504d
Merged-In: Id0e150dacbd762a2e5e801d200241334d10a504d
(cherry picked from commit 0721b86e)
parent 500ca09c
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -72,11 +72,14 @@ public class DefaultPhoneNotifier implements PhoneNotifier {

    @Override
    public void notifyServiceState(Phone sender) {
        ServiceState ss = sender.getServiceState();
        notifyServiceStateForSubId(sender, sender.getServiceState(), sender.getSubId());
    }

    @Override
    public void notifyServiceStateForSubId(Phone sender, ServiceState ss, int subId) {
        int phoneId = sender.getPhoneId();
        int subId = sender.getSubId();

        Rlog.d(LOG_TAG, "notifyServiceState: mRegistryMgr=" + mTelephonyRegistryMgr + " ss="
        Rlog.d(LOG_TAG, "notifyServiceStateForSubId: mRegistryMgr=" + mTelephonyRegistryMgr + " ss="
                + ss + " sender=" + sender + " phondId=" + phoneId + " subId=" + subId);
        if (ss == null) {
            ss = new ServiceState();
+4 −0
Original line number Diff line number Diff line
@@ -838,6 +838,10 @@ public class GsmCdmaPhone extends Phone {
        super.notifyServiceStateChangedP(ss);
    }

    void notifyServiceStateChangedForSubId(ServiceState ss, int subId) {
        super.notifyServiceStateChangedPForSubId(ss, subId);
    }

    /**
     * Notify that the cell location has changed.
     *
+11 −0
Original line number Diff line number Diff line
@@ -1699,6 +1699,17 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
        mNotifier.notifyServiceState(this);
    }

    /**
     * Version of notifyServiceStateChangedP which allows us to specify the subId. This is used when
     * we send out a final ServiceState update when a phone's subId becomes invalid.
     */
    protected void notifyServiceStateChangedPForSubId(ServiceState ss, int subId) {
        AsyncResult ar = new AsyncResult(null, ss, null);
        mServiceStateRegistrants.notifyRegistrants(ar);

        mNotifier.notifyServiceStateForSubId(this, ss, subId);
    }

    /**
     * If this is a simulated phone interface, returns a SimulatedRadioControl.
     * @return SimulatedRadioControl if this is a simulated interface;
+12 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.telephony.CellIdentity;
import android.telephony.CellInfo;
import android.telephony.PhoneCapability;
import android.telephony.PreciseDataConnectionState;
import android.telephony.ServiceState;
import android.telephony.TelephonyDisplayInfo;
import android.telephony.emergency.EmergencyNumber;
import android.telephony.ims.ImsReasonInfo;
@@ -40,8 +41,19 @@ public interface PhoneNotifier {

    void notifyPhoneState(Phone sender);

    /**
     * Notify registrants of the given phone's current ServiceState.
     */
    void notifyServiceState(Phone sender);

    /**
     * Notify registrants with a given ServiceState. Passing in the subId allows us to
     * send a final ServiceState update when the subId for the sender phone becomes invalid
     * @param sender
     * @param subId
     */
    void notifyServiceStateForSubId(Phone sender, ServiceState ss, int subId);

    /**
     * Notify registrants of the current CellLocation.
     *
+18 −3
Original line number Diff line number Diff line
@@ -159,6 +159,10 @@ public class ServiceStateTracker extends Handler {
    public ServiceState mSS;
    @UnsupportedAppUsage
    private ServiceState mNewSS;
    // A placeholder service state which will always be out of service. This is broadcast to
    // listeners when the subscription ID for a phone becomes invalid so that they get a final
    // state update.
    private final ServiceState mOutOfServiceSS;

    // This is the minimum interval at which CellInfo requests will be serviced by the modem.
    // Any requests that arrive within MinInterval of the previous reuqest will simply receive the
@@ -394,9 +398,17 @@ public class ServiceStateTracker extends Handler {
            // which seems desirable.
            mPhone.updateVoiceMail();

            if (!SubscriptionManager.isValidSubscriptionId(mSubId)) {
                if (SubscriptionManager.isValidSubscriptionId(mPrevSubId)) {
                    // just went from valid to invalid subId, so notify phone state listeners
                    // with final broadcast
                    mPhone.notifyServiceStateChangedForSubId(mOutOfServiceSS,
                            ServiceStateTracker.this.mPrevSubId);
                }
                // If the new subscription ID isn't valid, then we don't need to do all the
                // UI updating, so we're done.
            if (!SubscriptionManager.isValidSubscriptionId(mSubId)) return;
                return;
            }

            Context context = mPhone.getContext();

@@ -641,6 +653,9 @@ public class ServiceStateTracker extends Handler {
                .isVoiceCapable();
        mUiccController = UiccController.getInstance();

        mOutOfServiceSS = new ServiceState();
        mOutOfServiceSS.setStateOutOfService();

        mUiccController.registerForIccChanged(this, EVENT_ICC_CHANGED, null);
        mCi.setOnSignalStrengthUpdate(this, EVENT_SIGNAL_STRENGTH_UPDATE, null);
        mCi.registerForCellInfoList(this, EVENT_UNSOL_CELL_INFO_LIST, null);