Loading src/java/com/android/internal/telephony/uicc/UiccController.java +21 −12 Original line number Original line Diff line number Diff line Loading @@ -713,21 +713,30 @@ public class UiccController extends Handler { boolean isEuicc = slot.isEuicc(); boolean isEuicc = slot.isEuicc(); String eid = null; String eid = null; UiccCard card = slot.getUiccCard(); UiccCard card = slot.getUiccCard(); if (card == null) { String iccid = null; continue; int cardId = UNINITIALIZED_CARD_ID; } String iccid = card.getIccId(); int cardId; boolean isRemovable = slot.isRemovable(); boolean isRemovable = slot.isRemovable(); // first we try to populate UiccCardInfo using the UiccCard, but if it doesn't exist // (e.g. the slot is for an inactive eUICC) then we try using the UiccSlot. if (card != null) { iccid = card.getIccId(); if (isEuicc) { if (isEuicc) { eid = card.getCardId(); eid = ((EuiccCard) card).getEid(); cardId = convertToPublicCardId(eid); cardId = convertToPublicCardId(eid); } else { } else { // leave eid null if the UICC is not embedded // leave eid null if the UICC is not embedded cardId = convertToPublicCardId(iccid); cardId = convertToPublicCardId(iccid); } } UiccCardInfo info = new UiccCardInfo(isEuicc, cardId, eid, iccid, slotIndex, } else { isRemovable); iccid = slot.getIccId(); // Fill in the fields we can if (!isEuicc && !TextUtils.isEmpty(iccid)) { cardId = convertToPublicCardId(iccid); } } UiccCardInfo info = new UiccCardInfo(isEuicc, cardId, eid, IccUtils.stripTrailingFs(iccid), slotIndex, isRemovable); infos.add(info); infos.add(info); } } return infos; return infos; Loading tests/telephonytests/src/com/android/internal/telephony/uicc/UiccControllerTest.java +49 −3 Original line number Original line Diff line number Diff line Loading @@ -337,7 +337,44 @@ public class UiccControllerTest extends TelephonyTest { false, // isEuicc false, // isEuicc 0, // cardId 0, // cardId null, // eid null, // eid ics.iccid, // iccid is unknown ics.iccid, // iccid 0, // slotIndex true); // isRemovable assertEquals(uiccCardInfo, mUiccControllerUT.getAllUiccCardInfos().get(0)); } @Test public void testIccidWithTrailingF() { // Give UiccController a real context so it can use shared preferences mUiccControllerUT.mContext = InstrumentationRegistry.getContext(); // Mock out UiccSlots mUiccControllerUT.mUiccSlots[0] = mMockSlot; doReturn(false).when(mMockSlot).isEuicc(); doReturn(mMockCard).when(mMockSlot).getUiccCard(); doReturn("ASDF1234").when(mMockCard).getCardId(); doReturn(true).when(mMockSlot).isRemovable(); doReturn("A1B2C3D4").when(mMockCard).getCardId(); doReturn("123451234567890F").when(mMockCard).getIccId(); doReturn(IccCardStatus.CardState.CARDSTATE_PRESENT).when(mMockCard).getCardState(); // 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 = "123451234567890F"; ics.physicalSlotIndex = 0; AsyncResult ar = new AsyncResult(null, ics, null); Message msg = Message.obtain(mUiccControllerUT, EVENT_GET_ICC_STATUS_DONE, ar); mUiccControllerUT.handleMessage(msg); // assert that the default cardId is the slot with the lowest slot index, even if inactive UiccCardInfo uiccCardInfo = new UiccCardInfo( false, // isEuicc 0, // cardId null, // eid IccUtils.stripTrailingFs(ics.iccid), //iccid without ending F 0, // slotIndex 0, // slotIndex true); // isRemovable true); // isRemovable assertEquals(uiccCardInfo, mUiccControllerUT.getAllUiccCardInfos().get(0)); assertEquals(uiccCardInfo, mUiccControllerUT.getAllUiccCardInfos().get(0)); Loading @@ -352,6 +389,8 @@ public class UiccControllerTest extends TelephonyTest { mUiccControllerUT.mUiccSlots[0] = mMockSlot; mUiccControllerUT.mUiccSlots[0] = mMockSlot; doReturn(true).when(mMockSlot).isEuicc(); doReturn(true).when(mMockSlot).isEuicc(); doReturn(null).when(mMockSlot).getUiccCard(); doReturn(null).when(mMockSlot).getUiccCard(); doReturn("123451234567890").when(mMockSlot).getIccId(); doReturn(false).when(mMockSlot).isRemovable(); // simulate card status loaded so that the UiccController sets the card ID // simulate card status loaded so that the UiccController sets the card ID IccCardStatus ics = new IccCardStatus(); IccCardStatus ics = new IccCardStatus(); Loading @@ -364,8 +403,15 @@ public class UiccControllerTest extends TelephonyTest { Message msg = Message.obtain(mUiccControllerUT, EVENT_GET_ICC_STATUS_DONE, ar); Message msg = Message.obtain(mUiccControllerUT, EVENT_GET_ICC_STATUS_DONE, ar); mUiccControllerUT.handleMessage(msg); mUiccControllerUT.handleMessage(msg); // assert that the getAllUiccCardInfos returns an empty list without crashing // assert that the getAllUiccCardInfos uses info from the UiccSlot when the card is null assertEquals(0, mUiccControllerUT.getAllUiccCardInfos().size()); UiccCardInfo uiccCardInfo = new UiccCardInfo( true, // isEuicc TelephonyManager.UNINITIALIZED_CARD_ID, // cardId null, // eid ics.iccid, // iccid 0, // slotIndex false); // isRemovable assertEquals(uiccCardInfo, mUiccControllerUT.getAllUiccCardInfos().get(0)); } } @Test @Test Loading Loading
src/java/com/android/internal/telephony/uicc/UiccController.java +21 −12 Original line number Original line Diff line number Diff line Loading @@ -713,21 +713,30 @@ public class UiccController extends Handler { boolean isEuicc = slot.isEuicc(); boolean isEuicc = slot.isEuicc(); String eid = null; String eid = null; UiccCard card = slot.getUiccCard(); UiccCard card = slot.getUiccCard(); if (card == null) { String iccid = null; continue; int cardId = UNINITIALIZED_CARD_ID; } String iccid = card.getIccId(); int cardId; boolean isRemovable = slot.isRemovable(); boolean isRemovable = slot.isRemovable(); // first we try to populate UiccCardInfo using the UiccCard, but if it doesn't exist // (e.g. the slot is for an inactive eUICC) then we try using the UiccSlot. if (card != null) { iccid = card.getIccId(); if (isEuicc) { if (isEuicc) { eid = card.getCardId(); eid = ((EuiccCard) card).getEid(); cardId = convertToPublicCardId(eid); cardId = convertToPublicCardId(eid); } else { } else { // leave eid null if the UICC is not embedded // leave eid null if the UICC is not embedded cardId = convertToPublicCardId(iccid); cardId = convertToPublicCardId(iccid); } } UiccCardInfo info = new UiccCardInfo(isEuicc, cardId, eid, iccid, slotIndex, } else { isRemovable); iccid = slot.getIccId(); // Fill in the fields we can if (!isEuicc && !TextUtils.isEmpty(iccid)) { cardId = convertToPublicCardId(iccid); } } UiccCardInfo info = new UiccCardInfo(isEuicc, cardId, eid, IccUtils.stripTrailingFs(iccid), slotIndex, isRemovable); infos.add(info); infos.add(info); } } return infos; return infos; Loading
tests/telephonytests/src/com/android/internal/telephony/uicc/UiccControllerTest.java +49 −3 Original line number Original line Diff line number Diff line Loading @@ -337,7 +337,44 @@ public class UiccControllerTest extends TelephonyTest { false, // isEuicc false, // isEuicc 0, // cardId 0, // cardId null, // eid null, // eid ics.iccid, // iccid is unknown ics.iccid, // iccid 0, // slotIndex true); // isRemovable assertEquals(uiccCardInfo, mUiccControllerUT.getAllUiccCardInfos().get(0)); } @Test public void testIccidWithTrailingF() { // Give UiccController a real context so it can use shared preferences mUiccControllerUT.mContext = InstrumentationRegistry.getContext(); // Mock out UiccSlots mUiccControllerUT.mUiccSlots[0] = mMockSlot; doReturn(false).when(mMockSlot).isEuicc(); doReturn(mMockCard).when(mMockSlot).getUiccCard(); doReturn("ASDF1234").when(mMockCard).getCardId(); doReturn(true).when(mMockSlot).isRemovable(); doReturn("A1B2C3D4").when(mMockCard).getCardId(); doReturn("123451234567890F").when(mMockCard).getIccId(); doReturn(IccCardStatus.CardState.CARDSTATE_PRESENT).when(mMockCard).getCardState(); // 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 = "123451234567890F"; ics.physicalSlotIndex = 0; AsyncResult ar = new AsyncResult(null, ics, null); Message msg = Message.obtain(mUiccControllerUT, EVENT_GET_ICC_STATUS_DONE, ar); mUiccControllerUT.handleMessage(msg); // assert that the default cardId is the slot with the lowest slot index, even if inactive UiccCardInfo uiccCardInfo = new UiccCardInfo( false, // isEuicc 0, // cardId null, // eid IccUtils.stripTrailingFs(ics.iccid), //iccid without ending F 0, // slotIndex 0, // slotIndex true); // isRemovable true); // isRemovable assertEquals(uiccCardInfo, mUiccControllerUT.getAllUiccCardInfos().get(0)); assertEquals(uiccCardInfo, mUiccControllerUT.getAllUiccCardInfos().get(0)); Loading @@ -352,6 +389,8 @@ public class UiccControllerTest extends TelephonyTest { mUiccControllerUT.mUiccSlots[0] = mMockSlot; mUiccControllerUT.mUiccSlots[0] = mMockSlot; doReturn(true).when(mMockSlot).isEuicc(); doReturn(true).when(mMockSlot).isEuicc(); doReturn(null).when(mMockSlot).getUiccCard(); doReturn(null).when(mMockSlot).getUiccCard(); doReturn("123451234567890").when(mMockSlot).getIccId(); doReturn(false).when(mMockSlot).isRemovable(); // simulate card status loaded so that the UiccController sets the card ID // simulate card status loaded so that the UiccController sets the card ID IccCardStatus ics = new IccCardStatus(); IccCardStatus ics = new IccCardStatus(); Loading @@ -364,8 +403,15 @@ public class UiccControllerTest extends TelephonyTest { Message msg = Message.obtain(mUiccControllerUT, EVENT_GET_ICC_STATUS_DONE, ar); Message msg = Message.obtain(mUiccControllerUT, EVENT_GET_ICC_STATUS_DONE, ar); mUiccControllerUT.handleMessage(msg); mUiccControllerUT.handleMessage(msg); // assert that the getAllUiccCardInfos returns an empty list without crashing // assert that the getAllUiccCardInfos uses info from the UiccSlot when the card is null assertEquals(0, mUiccControllerUT.getAllUiccCardInfos().size()); UiccCardInfo uiccCardInfo = new UiccCardInfo( true, // isEuicc TelephonyManager.UNINITIALIZED_CARD_ID, // cardId null, // eid ics.iccid, // iccid 0, // slotIndex false); // isRemovable assertEquals(uiccCardInfo, mUiccControllerUT.getAllUiccCardInfos().get(0)); } } @Test @Test Loading