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

Commit 3a4b9f20 authored by Sarah Chin's avatar Sarah Chin
Browse files

Reset SIM loaded flag on radio unavailable

The flag is set to true when SIMs are loaded, but not set to false when
the radio is unavailable (modem reboot or modem crash).
This causes a race condition where we think SIMs are loaded and ready
to query, but they actually aren't yet.

Test: atest MultiSimSettingControllerTest
Bug: 187184692
Change-Id: Ide8ea1d46131c8be55d7453437a3c1a6e23b4b5d
parent c0825e3f
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -82,6 +82,8 @@ public class MultiSimSettingController extends Handler {
    private static final int EVENT_DEFAULT_DATA_SUBSCRIPTION_CHANGED = 6;
    private static final int EVENT_CARRIER_CONFIG_CHANGED            = 7;
    private static final int EVENT_MULTI_SIM_CONFIG_CHANGED          = 8;
    @VisibleForTesting
    public static final int EVENT_RADIO_STATE_CHANGED                = 9;

    @Retention(RetentionPolicy.SOURCE)
    @IntDef(prefix = {"PRIMARY_SUB_"},
@@ -294,6 +296,16 @@ public class MultiSimSettingController extends Handler {
            case EVENT_MULTI_SIM_CONFIG_CHANGED:
                int activeModems = (int) ((AsyncResult) msg.obj).result;
                onMultiSimConfigChanged(activeModems);
                break;
            case EVENT_RADIO_STATE_CHANGED:
                for (Phone phone : PhoneFactory.getPhones()) {
                    if (phone.mCi.getRadioState() == TelephonyManager.RADIO_POWER_UNAVAILABLE) {
                        if (DBG) log("Radio unavailable. Clearing sub info initialized flag.");
                        mSubInfoInitialized = false;
                        break;
                    }
                }
                break;
        }
    }

@@ -335,6 +347,9 @@ public class MultiSimSettingController extends Handler {
    private void onAllSubscriptionsLoaded() {
        if (DBG) log("onAllSubscriptionsLoaded");
        mSubInfoInitialized = true;
        for (Phone phone : PhoneFactory.getPhones()) {
            phone.mCi.registerForRadioStateChanged(this, EVENT_RADIO_STATE_CHANGED, null);
        }
        reEvaluateAll();
    }

@@ -424,6 +439,9 @@ public class MultiSimSettingController extends Handler {
        for (int phoneId = activeModems; phoneId < mCarrierConfigLoadedSubIds.length; phoneId++) {
            mCarrierConfigLoadedSubIds[phoneId] = INVALID_SUBSCRIPTION_ID;
        }
        for (Phone phone : PhoneFactory.getPhones()) {
            phone.mCi.registerForRadioStateChanged(this, EVENT_RADIO_STATE_CHANGED, null);
        }
    }

    /**
+49 −1
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import android.telephony.TelephonyManager;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;

import androidx.test.InstrumentationRegistry;

import com.android.internal.telephony.dataconnection.DataEnabledSettings;
@@ -63,6 +64,7 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
@@ -133,6 +135,8 @@ public class MultiSimSettingControllerTest extends TelephonyTest {
        doReturn(true).when(mSubControllerMock).isOpportunistic(5);
        doReturn(1).when(mPhoneMock1).getSubId();
        doReturn(2).when(mPhoneMock2).getSubId();
        mPhoneMock1.mCi = mSimulatedCommands;
        mPhoneMock2.mCi = mSimulatedCommands;
        List<SubscriptionInfo> infoList = Arrays.asList(mSubInfo1, mSubInfo2);
        doReturn(infoList).when(mSubControllerMock)
                .getActiveSubscriptionInfoList(anyString(), nullable(String.class));
@@ -164,7 +168,7 @@ public class MultiSimSettingControllerTest extends TelephonyTest {

    @Test
    @SmallTest
    public void testTestSubInfoChangeBeforeAllSubReady() throws Exception {
    public void testSubInfoChangeBeforeAllSubReady() throws Exception {
        doReturn(SubscriptionManager.INVALID_SUBSCRIPTION_ID).when(mSubControllerMock)
                .getDefaultDataSubId();
        doReturn(SubscriptionManager.INVALID_SUBSCRIPTION_ID).when(mSubControllerMock)
@@ -199,6 +203,50 @@ public class MultiSimSettingControllerTest extends TelephonyTest {
        verifyDismissIntentSent();
    }

    @Test
    public void testSubInfoChangeAfterRadioUnavailable() throws Exception {
        mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded();
        mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1);
        mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1, 2);
        processAllMessages();

        // Notify radio unavailable.
        replaceInstance(BaseCommands.class, "mState", mSimulatedCommands,
                TelephonyManager.RADIO_POWER_UNAVAILABLE);
        mMultiSimSettingControllerUT.obtainMessage(
                MultiSimSettingController.EVENT_RADIO_STATE_CHANGED).sendToTarget();

        // Mark all subs as inactive.
        doReturn(false).when(mSubControllerMock).isActiveSubId(1);
        doReturn(false).when(mSubControllerMock).isActiveSubId(2);
        doReturn(SubscriptionManager.INVALID_PHONE_INDEX).when(mSubControllerMock).getPhoneId(1);
        doReturn(SubscriptionManager.INVALID_PHONE_INDEX).when(mSubControllerMock).getPhoneId(2);
        doReturn(SubscriptionManager.INVALID_SUBSCRIPTION_ID).when(mPhoneMock1).getSubId();
        doReturn(SubscriptionManager.INVALID_SUBSCRIPTION_ID).when(mPhoneMock2).getSubId();
        List<SubscriptionInfo> infoList = new ArrayList<>();
        doReturn(infoList).when(mSubControllerMock).getActiveSubscriptionInfoList(anyString(),
                nullable(String.class));
        doReturn(new int[]{}).when(mSubControllerMock).getActiveSubIdList(anyBoolean());
        clearInvocations(mSubControllerMock);

        // The below sub info change should be ignored.
        mMultiSimSettingControllerUT.notifySubscriptionInfoChanged();
        processAllMessages();
        verify(mSubControllerMock, never()).setDefaultDataSubId(anyInt());
        verify(mSubControllerMock, never()).setDefaultVoiceSubId(anyInt());
        verify(mSubControllerMock, never()).setDefaultSmsSubId(anyInt());

        // Send all sub ready notification
        mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded();
        processAllMessages();

        // Everything should be set to invalid since nothing is active.
        verify(mSubControllerMock).setDefaultDataSubId(SubscriptionManager.INVALID_SUBSCRIPTION_ID);
        verify(mSubControllerMock)
                .setDefaultVoiceSubId(SubscriptionManager.INVALID_SUBSCRIPTION_ID);
        verify(mSubControllerMock).setDefaultSmsSubId(SubscriptionManager.INVALID_SUBSCRIPTION_ID);
    }

    @Test
    @SmallTest
    public void testSingleActiveDsds() throws Exception {