Search in sources :

Example 16 with UiccCardInfo

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;
}
Also used : ArrayList(java.util.ArrayList) UiccCardInfo(android.telephony.UiccCardInfo)

Example 17 with UiccCardInfo

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));
}
Also used : Message(android.os.Message) UiccCardInfo(android.telephony.UiccCardInfo) AsyncResult(android.os.AsyncResult) TelephonyTest(com.android.internal.telephony.TelephonyTest) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Example 18 with UiccCardInfo

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));
}
Also used : Message(android.os.Message) UiccCardInfo(android.telephony.UiccCardInfo) AsyncResult(android.os.AsyncResult) TelephonyTest(com.android.internal.telephony.TelephonyTest) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Example 19 with UiccCardInfo

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);
}
Also used : UiccAccessRule(android.telephony.UiccAccessRule) ArrayList(java.util.ArrayList) SubscriptionInfo(android.telephony.SubscriptionInfo) UiccCardInfo(android.telephony.UiccCardInfo)

Aggregations

UiccCardInfo (android.telephony.UiccCardInfo)19 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)10 UiThreadTest (androidx.test.annotation.UiThreadTest)9 HashMap (java.util.HashMap)8 AsyncResult (android.os.AsyncResult)3 Message (android.os.Message)3 SubscriptionInfo (android.telephony.SubscriptionInfo)3 TelephonyManager (android.telephony.TelephonyManager)3 SmallTest (androidx.test.filters.SmallTest)3 TelephonyTest (com.android.internal.telephony.TelephonyTest)3 Nullable (android.annotation.Nullable)1 PersistableBundle (android.os.PersistableBundle)1 SubscriptionManager (android.telephony.SubscriptionManager)1 UiccAccessRule (android.telephony.UiccAccessRule)1 UiccSlotInfo (android.telephony.UiccSlotInfo)1 VisibleForTesting (androidx.annotation.VisibleForTesting)1 Lifecycle (com.android.settingslib.core.lifecycle.Lifecycle)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Before (org.junit.Before)1