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

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

Make sure to obtain correct subId in carrier config change.

MultiSimSettingController sometimes receives carrier config chagne
without correct subId in it. While we debug the root cause, we add
an additional check to make sure we get the subId if missing.

Bug: 153860050
Test: unittest
Change-Id: I1dffd41fa373f0b29559c933cc8c5aaa1e3b2478
parent e64775e8
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -342,6 +342,22 @@ public class MultiSimSettingController extends Handler {
            return;
        }

        // b/153860050 Occasionally we receive carrier config change broadcast without subId
        // being specified in it. So here we do additional check to make sur we don't miss the
        // subId.
        if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
            int[] subIds = mSubController.getSubId(phoneId);
            if (!ArrayUtils.isEmpty(subIds)) {
                CarrierConfigManager cm = (CarrierConfigManager) mContext.getSystemService(
                        mContext.CARRIER_CONFIG_SERVICE);
                if (cm != null && cm.getConfigForSubId(subIds[0]) != null) {
                    loge("onCarrierConfigChanged with invalid subId while subd "
                            + subIds[0] + " is active and its config is loaded");
                    subId = subIds[0];
                }
            }
        }

        mCarrierConfigLoadedSubIds[phoneId] = subId;
        reEvaluateAll();
    }
+2 −0
Original line number Diff line number Diff line
@@ -334,6 +334,8 @@ public class SubscriptionInfoUpdater extends Handler {

            case EVENT_MULTI_SIM_CONFIG_CHANGED:
                onMultiSimConfigChanged();
                break;

            default:
                logd("Unknown msg:" + msg.what);
        }
+32 −0
Original line number Diff line number Diff line
@@ -38,7 +38,9 @@ import static org.mockito.Mockito.verify;

import android.content.Intent;
import android.os.ParcelUuid;
import android.os.PersistableBundle;
import android.provider.Settings;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
@@ -621,4 +623,34 @@ public class MultiSimSettingControllerTest extends TelephonyTest {
        // Shouldn't mark sub 2 as default data, as sub 2 is in active.
        verify(mSubControllerMock, never()).setDefaultDataSubId(2);
    }

    @Test
    @SmallTest
    // b/146446143
    public void testCarrierConfigChangeWithInvalidSubId_shouldAlwaysTryToGetSubId()
            throws Exception {
        doReturn(true).when(mPhoneMock1).isUserDataEnabled();
        doReturn(true).when(mPhoneMock2).isUserDataEnabled();
        mMultiSimSettingControllerUT.notifyAllSubscriptionLoaded();
        processAllMessages();
        mMultiSimSettingControllerUT.notifyCarrierConfigChanged(0, 1);
        // Notify carrier config change on phone1 without specifying subId.
        mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1,
                SubscriptionManager.INVALID_SUBSCRIPTION_ID);
        processAllMessages();
        // Nothing should happen as carrier config is not ready for sub 2.
        verify(mDataEnabledSettingsMock2, never()).setUserDataEnabled(false);

        // Still notify carrier config without specifying subId2, but this time subController
        // and CarrierConfigManager have subId 2 active and ready.
        doReturn(new int[] {2}).when(mSubControllerMock).getSubId(1);
        CarrierConfigManager cm = (CarrierConfigManager) mContext.getSystemService(
                mContext.CARRIER_CONFIG_SERVICE);
        doReturn(new PersistableBundle()).when(cm).getConfigForSubId(2);
        mMultiSimSettingControllerUT.notifyCarrierConfigChanged(1,
                SubscriptionManager.INVALID_SUBSCRIPTION_ID);
        processAllMessages();
        // This time user data should be disabled on phone1.
        verify(mDataEnabledSettingsMock2).setUserDataEnabled(false);
    }
}