Search in sources :

Example 1 with UiccCardInfo

use of android.telephony.UiccCardInfo in project android_frameworks_opt_telephony by LineageOS.

the class UiccControllerTest method testIccidWithTrailingF.

@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);
    ics.setUniversalPinState(3);
    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(// isEuicc
    false, // cardId
    0, // eid
    null, // iccid without ending F
    IccUtils.stripTrailingFs(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 2 with UiccCardInfo

use of android.telephony.UiccCardInfo in project android_frameworks_opt_telephony by LineageOS.

the class EuiccController method canManageSubscriptionOnTargetSim.

// For a multi-active subscriptions phone, checks whether the caller can manage subscription on
// the target SIM with the given cardId. The caller can only manage subscription on the target
// SIM if it can manage the active subscription on the target SIM or there is no active
// subscription on the target SIM, and the caller can manage any active subscription on any
// other SIM. The target SIM should be an eUICC.
// For a single-active subscription phone, checks whether the caller can manage any active
// embedded subscription.
private boolean canManageSubscriptionOnTargetSim(int cardId, String callingPackage) {
    List<SubscriptionInfo> subInfoList = mSubscriptionManager.getActiveSubscriptionInfoList(false);
    // No active subscription on any SIM.
    if (subInfoList == null || subInfoList.size() == 0) {
        return false;
    }
    // below check pass. That's the best we can do here.
    if (supportMultiActiveSlots()) {
        // The target card should be an eUICC.
        List<UiccCardInfo> cardInfos = mTelephonyManager.getUiccCardsInfo();
        if (cardInfos == null || cardInfos.isEmpty()) {
            return false;
        }
        boolean isEuicc = false;
        for (UiccCardInfo info : cardInfos) {
            if (info != null && info.getCardId() == cardId && info.isEuicc()) {
                isEuicc = true;
                break;
            }
        }
        if (!isEuicc) {
            Log.i(TAG, "The target SIM is not an eUICC.");
            return false;
        }
        // return true directly.
        for (SubscriptionInfo subInfo : subInfoList) {
            // subInfo.isEmbedded() can only be true for the target SIM.
            if (subInfo.isEmbedded() && subInfo.getCardId() == cardId) {
                return mSubscriptionManager.canManageSubscription(subInfo, callingPackage);
            }
        }
        // manage any active subscription on any other SIM.
        return mTelephonyManager.checkCarrierPrivilegesForPackageAnyPhone(callingPackage) == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
    } else {
        for (SubscriptionInfo subInfo : subInfoList) {
            if (subInfo.isEmbedded() && mSubscriptionManager.canManageSubscription(subInfo, callingPackage)) {
                return true;
            }
        }
        return false;
    }
}
Also used : SubscriptionInfo(android.telephony.SubscriptionInfo) UiccCardInfo(android.telephony.UiccCardInfo)

Example 3 with UiccCardInfo

use of android.telephony.UiccCardInfo in project android_frameworks_opt_telephony by LineageOS.

the class EuiccConnector method getSlotIdFromCardId.

/**
 * Gets the slot ID from the card ID.
 */
private int getSlotIdFromCardId(int cardId) {
    if (cardId == TelephonyManager.UNSUPPORTED_CARD_ID || cardId == TelephonyManager.UNINITIALIZED_CARD_ID) {
        return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
    }
    TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
    List<UiccCardInfo> infos = tm.getUiccCardsInfo();
    if (infos == null || infos.size() == 0) {
        return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
    }
    int slotId = SubscriptionManager.INVALID_SIM_SLOT_INDEX;
    for (UiccCardInfo info : infos) {
        if (info.getCardId() == cardId) {
            slotId = info.getSlotIndex();
        }
    }
    return slotId;
}
Also used : TelephonyManager(android.telephony.TelephonyManager) UiccCardInfo(android.telephony.UiccCardInfo)

Example 4 with UiccCardInfo

use of android.telephony.UiccCardInfo in project android_packages_apps_Settings by omnirom.

the class SimStatusDialogControllerTest method initialize_updateEid_shouldSetEidInSingleSimModeWithEnabledEuicc.

@Test
public void initialize_updateEid_shouldSetEidInSingleSimModeWithEnabledEuicc() {
    when(mTelephonyManager.getActiveModemCount()).thenReturn(MAX_PHONE_COUNT_SINGLE_SIM);
    ArrayList<UiccCardInfo> uiccCardInfos = new ArrayList<>();
    UiccCardInfo uiccCardInfo = new UiccCardInfo(// isEuicc (eUICC slot is selected)
    true, // cardId
    0, // eid (not used)
    TEST_EID_FROM_CARD, // iccid
    null, // slotIndex
    0, // isRemovable
    false);
    uiccCardInfos.add(uiccCardInfo);
    when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos);
    Map<Integer, Integer> slotMapping = new HashMap<>();
    slotMapping.put(0, 0);
    when(mTelephonyManager.getLogicalToPhysicalSlotMapping()).thenReturn(slotMapping);
    when(mEuiccManager.isEnabled()).thenReturn(true);
    when(mEuiccManager.getEid()).thenReturn(TEST_EID_FROM_MANAGER);
    when(mEuiccManager.createForCardId(anyInt())).thenThrow(new RuntimeException("EID shall be retrieved from the default eUICC manager"));
    doNothing().when(mController).requestForUpdateEid();
    mController.updateEid(mController.getEid(0));
    mController.initialize();
    // Set EID retrieved from the default eUICC manager in Single SIM mode.
    verify(mDialog).setText(EID_INFO_VALUE_ID, TEST_EID_FROM_MANAGER);
    verify(mDialog, never()).removeSettingFromScreen(eq(EID_INFO_VALUE_ID));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UiccCardInfo(android.telephony.UiccCardInfo) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 5 with UiccCardInfo

use of android.telephony.UiccCardInfo in project android_packages_apps_Settings by omnirom.

the class SimStatusDialogControllerTest method initialize_updateEid_shouldSetEidFromManager.

@Test
public void initialize_updateEid_shouldSetEidFromManager() {
    when(mTelephonyManager.getActiveModemCount()).thenReturn(MAX_PHONE_COUNT_DUAL_SIM);
    ArrayList<UiccCardInfo> uiccCardInfos = new ArrayList<>();
    UiccCardInfo uiccCardInfo1 = new UiccCardInfo(// isEuicc
    false, // cardId
    0, // eid
    null, // iccid
    "123451234567890", // slotIndex
    0, // isRemovable
    true);
    uiccCardInfos.add(uiccCardInfo1);
    UiccCardInfo uiccCardInfo2 = new UiccCardInfo(// isEuicc
    true, // cardId
    1, // eid (unavailable)
    null, // iccid
    null, // slotIndex
    1, // isRemovable
    false);
    uiccCardInfos.add(uiccCardInfo2);
    when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos);
    Map<Integer, Integer> slotMapping = new HashMap<>();
    slotMapping.put(0, 1);
    slotMapping.put(1, 0);
    when(mTelephonyManager.getLogicalToPhysicalSlotMapping()).thenReturn(slotMapping);
    when(mEuiccManager.isEnabled()).thenReturn(true);
    when(mEuiccManager.getEid()).thenReturn(TEST_EID_FROM_MANAGER);
    when(mEuiccManager.createForCardId(0)).thenThrow(new RuntimeException("Unexpected card ID was specified"));
    when(mEuiccManager.createForCardId(1)).thenReturn(mEuiccManager);
    doNothing().when(mController).requestForUpdateEid();
    mController.updateEid(mController.getEid(0));
    mController.initialize();
    // Set EID retrieved from the manager associated with the card which cannot provide EID.
    verify(mDialog).setText(EID_INFO_VALUE_ID, TEST_EID_FROM_MANAGER);
    verify(mDialog, never()).removeSettingFromScreen(eq(EID_INFO_VALUE_ID));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UiccCardInfo(android.telephony.UiccCardInfo) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest)

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