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

Commit c427812e authored by Matt Pietal's avatar Matt Pietal
Browse files

Clear invalid SIM slot data when INVALID SUBSCRIPTION received

SysUI has historically indexed by subscriptionId. In this case,
a valid subscription id, followed by an invalid id, followed again
by a valid subscription id, failed to send an update as both
pieces of information were kept for the same slotId. Only 1
entry per slotId should exist.

Fixes: 368163390
Test: atest KeyguardUpdateMonitorTest
Flag: EXEMPT bugfix
Change-Id: I35cd3abde77fb4dc940aa39b3c456735d0e2eee6
parent f47daae4
Loading
Loading
Loading
Loading
+24 −16
Original line number Diff line number Diff line
@@ -3372,6 +3372,20 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        }
    }

    /**
     * Removes all valid subscription info from the map for the given slotId.
     */
    private void invalidateSlot(int slotId) {
        Iterator<Map.Entry<Integer, SimData>> iter = mSimDatas.entrySet().iterator();
        while (iter.hasNext()) {
            SimData data = iter.next().getValue();
            if (data.slotId == slotId && SubscriptionManager.isValidSubscriptionId(data.subId)) {
                mSimLogger.logInvalidSubId(data.subId);
                iter.remove();
            }
        }
    }

    /**
     * Handle {@link #MSG_SIM_STATE_CHANGE}
     */
@@ -3380,29 +3394,18 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        Assert.isMainThread();
        mSimLogger.logSimState(subId, slotId, state);

        boolean becameAbsent = false;
        boolean becameAbsent = ABSENT_SIM_STATE_LIST.contains(state);
        if (!SubscriptionManager.isValidSubscriptionId(subId)) {
            mSimLogger.w("invalid subId in handleSimStateChange()");
            /* Only handle No SIM(ABSENT) and Card Error(CARD_IO_ERROR) due to
             * handleServiceStateChange() handle other case */
            if (state == TelephonyManager.SIM_STATE_ABSENT) {
            if (state == TelephonyManager.SIM_STATE_ABSENT
                    || state == TelephonyManager.SIM_STATE_CARD_IO_ERROR) {
                updateTelephonyCapable(true);
                // Even though the subscription is not valid anymore, we need to notify that the
                // SIM card was removed so we can update the UI.
                becameAbsent = true;
                for (SimData data : mSimDatas.values()) {
                    // Set the SIM state of all SimData associated with that slot to ABSENT se we
                    // do not move back into PIN/PUK locked and not detect the change below.
                    if (data.slotId == slotId) {
                        data.simState = TelephonyManager.SIM_STATE_ABSENT;
                    }
                }
            } else if (state == TelephonyManager.SIM_STATE_CARD_IO_ERROR) {
                updateTelephonyCapable(true);
            }
            }

        becameAbsent |= ABSENT_SIM_STATE_LIST.contains(state);
            invalidateSlot(slotId);
        }

        // TODO(b/327476182): Preserve SIM_STATE_CARD_IO_ERROR sims in a separate data source.
        SimData data = mSimDatas.get(subId);
@@ -3874,6 +3877,11 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
    private boolean refreshSimState(int subId, int slotId) {
        int state = mTelephonyManager.getSimState(slotId);
        SimData data = mSimDatas.get(subId);

        if (!SubscriptionManager.isValidSubscriptionId(subId)) {
            invalidateSlot(slotId);
        }

        final boolean changed;
        if (data == null) {
            data = new SimData(state, slotId, subId);
+30 −0
Original line number Diff line number Diff line
@@ -2236,6 +2236,36 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
                TelephonyManager.SIM_STATE_NOT_READY);
    }

    @Test
    public void testOnSimStateChanged_LockedToNotReadyToLocked() {
        int validSubId = 10;
        int slotId = 0;

        KeyguardUpdateMonitorCallback keyguardUpdateMonitorCallback = spy(
                KeyguardUpdateMonitorCallback.class);
        mKeyguardUpdateMonitor.registerCallback(keyguardUpdateMonitorCallback);
        // Initially locked
        mKeyguardUpdateMonitor.handleSimStateChange(validSubId, slotId,
                TelephonyManager.SIM_STATE_PIN_REQUIRED);
        verify(keyguardUpdateMonitorCallback).onSimStateChanged(validSubId, slotId,
                TelephonyManager.SIM_STATE_PIN_REQUIRED);

        reset(keyguardUpdateMonitorCallback);
        // Not ready, with invalid sub id
        mKeyguardUpdateMonitor.handleSimStateChange(SubscriptionManager.INVALID_SUBSCRIPTION_ID,
                slotId, TelephonyManager.SIM_STATE_NOT_READY);
        verify(keyguardUpdateMonitorCallback).onSimStateChanged(
                SubscriptionManager.INVALID_SUBSCRIPTION_ID, slotId,
                TelephonyManager.SIM_STATE_NOT_READY);

        reset(keyguardUpdateMonitorCallback);
        // Back to PIN required, which notifies listeners
        mKeyguardUpdateMonitor.handleSimStateChange(validSubId, slotId,
                TelephonyManager.SIM_STATE_PIN_REQUIRED);
        verify(keyguardUpdateMonitorCallback).onSimStateChanged(validSubId, slotId,
                TelephonyManager.SIM_STATE_PIN_REQUIRED);
    }

    @Test
    public void onAuthEnrollmentChangesCallbacksAreNotified() {
        KeyguardUpdateMonitorCallback callback = mock(KeyguardUpdateMonitorCallback.class);