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

Commit b66615d8 authored by Jordan Liu's avatar Jordan Liu
Browse files

Check that UiccCard is not null

Test: UiccControllerTest
Bug: 122366240
Change-Id: Ia669f6a15ce01699b9da0eaf113c8caa92721cff
parent 805b5ca6
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -600,10 +600,14 @@ public class UiccController extends Handler {
            final UiccSlot slot = mUiccSlots[slotIndex];
            boolean isEuicc = slot.isEuicc();
            String eid = null;
            String iccid = slot.getUiccCard().getIccId();
            UiccCard card = slot.getUiccCard();
            if (card == null) {
                continue;
            }
            String iccid = card.getIccId();
            int cardId = INVALID_CARD_ID;
            if (isEuicc) {
                eid = slot.getUiccCard().getCardId();
                eid = card.getCardId();
                cardId = convertToPublicCardId(eid);
            } else {
                // leave eid null if the UICC is not embedded
+25 −0
Original line number Diff line number Diff line
@@ -319,4 +319,29 @@ public class UiccControllerTest extends TelephonyTest {
                0);        // slotIndex
        assertEquals(uiccCardInfo, mUiccControllerUT.getAllUiccCardInfos().get(0));
    }

    @Test
    public void testGetAllUiccCardInfosNullCard() {
        // Give UiccController a real context so it can use shared preferences
        mUiccControllerUT.mContext = InstrumentationRegistry.getContext();

        // Mock out UiccSlots
        mUiccControllerUT.mUiccSlots[0] = mMockSlot;
        doReturn(true).when(mMockSlot).isEuicc();
        doReturn(null).when(mMockSlot).getUiccCard();

        // simulate card status loaded so that the UiccController sets the card ID
        IccCardStatus ics = new IccCardStatus();
        ics.setCardState(1 /* present */);
        ics.setUniversalPinState(3 /* disabled */);
        ics.atr = "abcdef0123456789abcdef";
        ics.iccid = "123451234567890";
        ics.eid = "A1B2C3D4";
        AsyncResult ar = new AsyncResult(null, ics, null);
        Message msg = Message.obtain(mUiccControllerUT, EVENT_GET_ICC_STATUS_DONE, ar);
        mUiccControllerUT.handleMessage(msg);

        // assert that the getAllUiccCardInfos returns an empty list without crashing
        assertEquals(0, mUiccControllerUT.getAllUiccCardInfos().size());
    }
}