use of android.telephony.UiccCardInfo in project android_frameworks_opt_telephony by LineageOS.
the class UiccController method getAllUiccCardInfos.
/**
* 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];
if (slot == null)
continue;
boolean isEuicc = slot.isEuicc();
String eid = null;
UiccCard card = slot.getUiccCard();
String iccid = null;
int cardId = UNINITIALIZED_CARD_ID;
boolean isRemovable = slot.isRemovable();
// (e.g. the slot is for an inactive eUICC) then we try using the UiccSlot.
if (card != null) {
iccid = card.getIccId();
if (isEuicc) {
eid = ((EuiccCard) card).getEid();
cardId = convertToPublicCardId(eid);
} else {
// leave eid null if the UICC is not embedded
cardId = convertToPublicCardId(iccid);
}
} else {
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);
}
return infos;
}
use of android.telephony.UiccCardInfo in project android_frameworks_opt_telephony by LineageOS.
the class UiccControllerTest method testGetAllUiccCardInfos.
@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(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("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);
ics.setUniversalPinState(3);
ics.atr = "abcdef0123456789abcdef";
ics.iccid = "123451234567890";
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(// isEuicc
false, // cardId
0, // eid
null, // iccid
ics.iccid, // slotIndex
0, // isRemovable
true);
assertEquals(uiccCardInfo, mUiccControllerUT.getAllUiccCardInfos().get(0));
}
use of android.telephony.UiccCardInfo in project android_frameworks_opt_telephony by LineageOS.
the class UiccControllerTest method testGetAllUiccCardInfosNullCard.
@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();
doReturn("123451234567890").when(mMockSlot).getIccId();
doReturn(false).when(mMockSlot).isRemovable();
// simulate card status loaded so that the UiccController sets the card ID
IccCardStatus ics = new IccCardStatus();
ics.setCardState(1);
ics.setUniversalPinState(3);
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 uses info from the UiccSlot when the card is null
UiccCardInfo uiccCardInfo = new UiccCardInfo(// isEuicc
true, // cardId
TelephonyManager.UNINITIALIZED_CARD_ID, // eid
null, // iccid
ics.iccid, // slotIndex
0, // isRemovable
false);
assertEquals(uiccCardInfo, mUiccControllerUT.getAllUiccCardInfos().get(0));
}
use of android.telephony.UiccCardInfo in project android_frameworks_opt_telephony by LineageOS.
the class EuiccControllerTest method setCanManageSubscriptionOnTargetSim.
private void setCanManageSubscriptionOnTargetSim(boolean isTargetEuicc, boolean hasPrivileges) throws Exception {
UiccCardInfo cardInfo1 = new UiccCardInfo(isTargetEuicc, CARD_ID, "", "", 0, false);
UiccCardInfo cardInfo2 = new UiccCardInfo(true, /* isEuicc */
1, /* cardId */
"", "", 0, false);
ArrayList<UiccCardInfo> cardInfos = new ArrayList<>();
cardInfos.add(cardInfo1);
cardInfos.add(cardInfo2);
when(mTelephonyManager.getUiccCardsInfo()).thenReturn(cardInfos);
SubscriptionInfo subInfo1 = new SubscriptionInfo(0, "", 0, "", "", 0, 0, "", 0, null, "", "", "", true, /* isEmbedded */
hasPrivileges ? new UiccAccessRule[] { ACCESS_RULE } : null, "", CARD_ID, false, null, false, 0, 0, 0, null, null, true);
SubscriptionInfo subInfo2 = new SubscriptionInfo(0, "", 0, "", "", 0, 0, "", 0, null, "", "", "", true, /* isEmbedded */
hasPrivileges ? new UiccAccessRule[] { ACCESS_RULE } : null, "", 1, /* cardId */
false, null, false, 0, 0, 0, null, null, true);
when(mSubscriptionManager.canManageSubscription(subInfo1, PACKAGE_NAME)).thenReturn(hasPrivileges);
when(mSubscriptionManager.canManageSubscription(subInfo2, PACKAGE_NAME)).thenReturn(hasPrivileges);
ArrayList<SubscriptionInfo> subInfos = new ArrayList<>(Arrays.asList(subInfo1, subInfo2));
when(mSubscriptionManager.getActiveSubscriptionInfoList(anyBoolean())).thenReturn(subInfos);
}
Aggregations