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

Commit 3462728d authored by Malcolm Chen's avatar Malcolm Chen Committed by Xiangyu/Malcolm Chen
Browse files

Fix issue that after reboot we might ask to select default data again.

There's a race condtion that MultiSimSettingController handles subInfo
change before it's firstly initialized during boot up. Which could
result in it believes user inserted new SIM cards and ask user to select
default data SIM again.

Bug: 134955658
Test: manual - multiple reboots and make sure no dialog is popped up.
Change-Id: Id204f3578b1c8a2a585789494915c7de0112c480
Merged-In: Id204f3578b1c8a2a585789494915c7de0112c480
parent 8f81cc0f
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -110,6 +110,14 @@ public class MultiSimSettingController extends Handler {
    /** The singleton instance. */
    private static MultiSimSettingController sInstance = null;

    // This will be set true when handling EVENT_ALL_SUBSCRIPTIONS_LOADED. The reason of keeping
    // a local variable instead of calling SubscriptionInfoUpdater#isSubInfoInitialized is, there
    // might be a race condition that we receive EVENT_SUBSCRIPTION_INFO_CHANGED first, then
    // EVENT_ALL_SUBSCRIPTIONS_LOADED. And calling SubscriptionInfoUpdater#isSubInfoInitialized
    // will make us handle EVENT_SUBSCRIPTION_INFO_CHANGED unexpectedly and causing us to believe
    // the SIMs are newly inserted instead of being initialized.
    private boolean mSubInfoInitialized = false;

    /**
     * Return the singleton or create one if not existed.
     */
@@ -252,6 +260,7 @@ public class MultiSimSettingController extends Handler {
     */
    private void onAllSubscriptionsLoaded() {
        if (DBG) log("onAllSubscriptionsLoaded");
        mSubInfoInitialized = true;
        updateDefaults(/*init*/ true);
        disableDataForNonDefaultNonOpportunisticSubscriptions();
        deactivateGroupedOpportunisticSubscriptionIfNeeded();
@@ -264,7 +273,7 @@ public class MultiSimSettingController extends Handler {
     */
    private void onSubscriptionsChanged() {
        if (DBG) log("onSubscriptionsChanged");
        if (!SubscriptionInfoUpdater.isSubInfoInitialized()) return;
        if (!mSubInfoInitialized) return;
        updateDefaults(/*init*/ false);
        disableDataForNonDefaultNonOpportunisticSubscriptions();
        deactivateGroupedOpportunisticSubscriptionIfNeeded();
@@ -349,7 +358,7 @@ public class MultiSimSettingController extends Handler {
    private void updateDefaults(boolean init) {
        if (DBG) log("updateDefaults");

        if (!SubscriptionInfoUpdater.isSubInfoInitialized()) return;
        if (!mSubInfoInitialized) return;

        List<SubscriptionInfo> activeSubInfos = mSubController
                .getActiveSubscriptionInfoList(mContext.getOpPackageName());
@@ -545,7 +554,7 @@ public class MultiSimSettingController extends Handler {
    }

    private void disableDataForNonDefaultNonOpportunisticSubscriptions() {
        if (!SubscriptionInfoUpdater.isSubInfoInitialized()) return;
        if (!mSubInfoInitialized) return;

        int defaultDataSub = mSubController.getDefaultDataSubId();

+0 −2
Original line number Diff line number Diff line
@@ -177,14 +177,12 @@ public class MultiSimSettingControllerTest extends TelephonyTest {
        doReturn(infoList).when(mSubControllerMock).getActiveSubscriptionInfoList(anyString());

        // Mark subscription ready as false. The below sub info change should be ignored.
        replaceInstance(SubscriptionInfoUpdater.class, "sIsSubInfoInitialized", null, false);
        mMultiSimSettingControllerUT.notifySubscriptionInfoChanged();
        waitABit();
        verify(mSubControllerMock, never()).setDefaultDataSubId(anyInt());
        verify(mSubControllerMock, never()).setDefaultVoiceSubId(anyInt());
        verify(mSubControllerMock, never()).setDefaultSmsSubId(anyInt());

        replaceInstance(SubscriptionInfoUpdater.class, "sIsSubInfoInitialized", null, true);
        mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded();
        waitABit();