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

Commit b908f9c5 authored by Malcolm Chen's avatar Malcolm Chen
Browse files

Do not consider SIM state for inactive SIM/modem slot.

ActiveModemCount could be smaller than max SIM slot in single SIM mode
mode. In this case, do not consider mSimErrorState for inactive slots.

Bug: 142514392
Test: manual and unittest
Change-Id: Ieff64f7c2e7bf4db7d603d3824dc6fea71e3f6cd
parent 9ed48d41
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -169,12 +169,15 @@ public class CarrierTextController {
        mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        mSeparator = separator;
        mWakefulnessLifecycle = Dependency.get(WakefulnessLifecycle.class);
        mSimSlotsNumber = ((TelephonyManager) context.getSystemService(
                Context.TELEPHONY_SERVICE)).getSupportedModemCount();
        mSimSlotsNumber = getTelephonyManager().getSupportedModemCount();
        mSimErrorState = new boolean[mSimSlotsNumber];
        mMainHandler = Dependency.get(Dependency.MAIN_HANDLER);
    }

    private TelephonyManager getTelephonyManager() {
        return (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
    }

    /**
     * Checks if there are faulty cards. Adds the text depending on the slot of the card
     *
@@ -190,7 +193,7 @@ public class CarrierTextController {
        CharSequence carrierTextForSimIOError = getCarrierTextForSimState(
                IccCardConstants.State.CARD_IO_ERROR, carrier);
        // mSimErrorState has the state of each sim indexed by slotID.
        for (int index = 0; index < mSimErrorState.length; index++) {
        for (int index = 0; index < getTelephonyManager().getActiveModemCount(); index++) {
            if (!mSimErrorState[index]) {
                continue;
            }
@@ -223,8 +226,7 @@ public class CarrierTextController {
     * @param callback Callback to provide text updates
     */
    public void setListening(CarrierTextCallback callback) {
        TelephonyManager telephonyManager = ((TelephonyManager) mContext
                .getSystemService(Context.TELEPHONY_SERVICE));
        TelephonyManager telephonyManager = getTelephonyManager();
        if (callback != null) {
            mCarrierTextCallback = callback;
            // TODO(b/140034799)
+10 −0
Original line number Diff line number Diff line
@@ -145,6 +145,7 @@ public class CarrierTextControllerTest extends SysuiTestCase {
        mCarrierTextCallbackInfo = new CarrierTextController.CarrierTextCallbackInfo("",
                new CharSequence[]{}, false, new int[]{});
        when(mTelephonyManager.getSupportedModemCount()).thenReturn(3);
        when(mTelephonyManager.getActiveModemCount()).thenReturn(3);

        mCarrierTextController = new CarrierTextController(mContext, SEPARATOR, true, true);
        // This should not start listening on any of the real dependencies but will test that
@@ -216,6 +217,15 @@ public class CarrierTextControllerTest extends SysuiTestCase {
        // There's only one subscription in the list
        assertEquals(1, captor.getValue().listOfCarriers.length);
        assertEquals(TEST_CARRIER, captor.getValue().listOfCarriers[0]);

        // Now it becomes single SIM active mode.
        reset(mCarrierTextCallback);
        when(mTelephonyManager.getActiveModemCount()).thenReturn(1);
        // Update carrier text. It should ignore error state of subId 3 in inactive slotId.
        mCarrierTextController.updateCarrierText();
        mTestableLooper.processAllMessages();
        verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
        assertEquals("TEST_CARRIER", captor.getValue().carrierText);
    }

    @Test