Loading src/java/com/android/internal/telephony/uicc/UiccController.java +25 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import android.preference.PreferenceManager; import android.telephony.CarrierConfigManager; import android.telephony.Rlog; import android.telephony.TelephonyManager; import android.telephony.UiccCardInfo; import android.text.TextUtils; import android.util.LocalLog; Loading Loading @@ -590,6 +591,30 @@ public class UiccController extends Handler { } } /** * Returns the UiccCardInfo of all currently inserted UICCs and embedded eUICCs. */ public ArrayList<UiccCardInfo> getAllUiccCardInfos() { ArrayList<UiccCardInfo> infos = new ArrayList<>(); for (int slotIndex = 0; slotIndex < mUiccSlots.length; slotIndex++) { final UiccSlot slot = mUiccSlots[slotIndex]; boolean isEuicc = slot.isEuicc(); String eid = null; String iccid = slot.getUiccCard().getIccId(); int cardId = INVALID_CARD_ID; if (isEuicc) { eid = slot.getUiccCard().getCardId(); cardId = convertToPublicCardId(eid); } else { // leave eid null if the UICC is not embedded cardId = convertToPublicCardId(iccid); } UiccCardInfo info = new UiccCardInfo(isEuicc, cardId, eid, iccid, slotIndex); infos.add(info); } return infos; } /** * Get the card ID of the default eUICC. */ Loading tests/telephonytests/src/com/android/internal/telephony/uicc/UiccControllerTest.java +38 −3 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import android.os.Handler; import android.os.HandlerThread; import android.os.Message; import android.telephony.TelephonyManager; import android.telephony.UiccCardInfo; import androidx.test.InstrumentationRegistry; import androidx.test.filters.SmallTest; Loading Loading @@ -223,7 +224,7 @@ public class UiccControllerTest extends TelephonyTest { doReturn("A1B2C3D4").when(mMockCard).getCardId(); doReturn(IccCardStatus.CardState.CARDSTATE_PRESENT).when(mMockCard).getCardState(); // simulate card status loaded // simulate card status loaded so that the UiccController sets the card ID IccCardStatus ics = new IccCardStatus(); ics.setCardState(1 /* present */); ics.setUniversalPinState(3 /* disabled */); Loading @@ -247,7 +248,7 @@ public class UiccControllerTest extends TelephonyTest { mUiccControllerUT.mUiccSlots[0] = mMockSlot; doReturn(true).when(mMockSlot).isEuicc(); // simulate slot status loaded // simulate slot status loaded so that the UiccController sets the card ID IccSlotStatus iss = new IccSlotStatus(); iss.setSlotState(1 /* active */); iss.eid = "ABADACB"; Loading @@ -270,7 +271,7 @@ public class UiccControllerTest extends TelephonyTest { mUiccControllerUT.mUiccSlots[0] = mMockSlot; doReturn(true).when(mMockSlot).isEuicc(); // simulate slot status loaded // simulate slot status loaded so that the UiccController sets the card ID IccSlotStatus iss = new IccSlotStatus(); iss.setSlotState(1 /* active */); iss.eid = "ABADACB"; Loading @@ -284,4 +285,38 @@ public class UiccControllerTest extends TelephonyTest { assertEquals(mUiccControllerUT.convertToPublicCardId(iss.eid), mUiccControllerUT.getCardIdForDefaultEuicc()); } @Test public void testGetAllUiccCardInfos() { // 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(mMockCard).when(mMockSlot).getUiccCard(); doReturn("A1B2C3D4").when(mMockCard).getCardId(); doReturn("123451234567890").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 = "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 default cardId is the slot with the lowest slot index, even if inactive UiccCardInfo uiccCardInfo = new UiccCardInfo( true, // isEuicc 0, // cardId ics.eid, // eid ics.iccid, // iccid is unknown 0); // slotIndex assertEquals(uiccCardInfo, mUiccControllerUT.getAllUiccCardInfos().get(0)); } } Loading
src/java/com/android/internal/telephony/uicc/UiccController.java +25 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import android.preference.PreferenceManager; import android.telephony.CarrierConfigManager; import android.telephony.Rlog; import android.telephony.TelephonyManager; import android.telephony.UiccCardInfo; import android.text.TextUtils; import android.util.LocalLog; Loading Loading @@ -590,6 +591,30 @@ public class UiccController extends Handler { } } /** * Returns the UiccCardInfo of all currently inserted UICCs and embedded eUICCs. */ public ArrayList<UiccCardInfo> getAllUiccCardInfos() { ArrayList<UiccCardInfo> infos = new ArrayList<>(); for (int slotIndex = 0; slotIndex < mUiccSlots.length; slotIndex++) { final UiccSlot slot = mUiccSlots[slotIndex]; boolean isEuicc = slot.isEuicc(); String eid = null; String iccid = slot.getUiccCard().getIccId(); int cardId = INVALID_CARD_ID; if (isEuicc) { eid = slot.getUiccCard().getCardId(); cardId = convertToPublicCardId(eid); } else { // leave eid null if the UICC is not embedded cardId = convertToPublicCardId(iccid); } UiccCardInfo info = new UiccCardInfo(isEuicc, cardId, eid, iccid, slotIndex); infos.add(info); } return infos; } /** * Get the card ID of the default eUICC. */ Loading
tests/telephonytests/src/com/android/internal/telephony/uicc/UiccControllerTest.java +38 −3 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import android.os.Handler; import android.os.HandlerThread; import android.os.Message; import android.telephony.TelephonyManager; import android.telephony.UiccCardInfo; import androidx.test.InstrumentationRegistry; import androidx.test.filters.SmallTest; Loading Loading @@ -223,7 +224,7 @@ public class UiccControllerTest extends TelephonyTest { doReturn("A1B2C3D4").when(mMockCard).getCardId(); doReturn(IccCardStatus.CardState.CARDSTATE_PRESENT).when(mMockCard).getCardState(); // simulate card status loaded // simulate card status loaded so that the UiccController sets the card ID IccCardStatus ics = new IccCardStatus(); ics.setCardState(1 /* present */); ics.setUniversalPinState(3 /* disabled */); Loading @@ -247,7 +248,7 @@ public class UiccControllerTest extends TelephonyTest { mUiccControllerUT.mUiccSlots[0] = mMockSlot; doReturn(true).when(mMockSlot).isEuicc(); // simulate slot status loaded // simulate slot status loaded so that the UiccController sets the card ID IccSlotStatus iss = new IccSlotStatus(); iss.setSlotState(1 /* active */); iss.eid = "ABADACB"; Loading @@ -270,7 +271,7 @@ public class UiccControllerTest extends TelephonyTest { mUiccControllerUT.mUiccSlots[0] = mMockSlot; doReturn(true).when(mMockSlot).isEuicc(); // simulate slot status loaded // simulate slot status loaded so that the UiccController sets the card ID IccSlotStatus iss = new IccSlotStatus(); iss.setSlotState(1 /* active */); iss.eid = "ABADACB"; Loading @@ -284,4 +285,38 @@ public class UiccControllerTest extends TelephonyTest { assertEquals(mUiccControllerUT.convertToPublicCardId(iss.eid), mUiccControllerUT.getCardIdForDefaultEuicc()); } @Test public void testGetAllUiccCardInfos() { // 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(mMockCard).when(mMockSlot).getUiccCard(); doReturn("A1B2C3D4").when(mMockCard).getCardId(); doReturn("123451234567890").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 = "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 default cardId is the slot with the lowest slot index, even if inactive UiccCardInfo uiccCardInfo = new UiccCardInfo( true, // isEuicc 0, // cardId ics.eid, // eid ics.iccid, // iccid is unknown 0); // slotIndex assertEquals(uiccCardInfo, mUiccControllerUT.getAllUiccCardInfos().get(0)); } }