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

Commit 6b3c1a5d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Make sure to obtain correct subId in carrier config change." into rvc-dev

parents 7eb4d167 b2dae220
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -346,6 +346,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
@@ -335,6 +335,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);
    }
}