Search in sources :

Example 6 with UiccCardInfo

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

the class SimStatusDialogControllerTest method initialize_updateEid_shouldRemoveEid.

@Test
public void initialize_updateEid_shouldRemoveEid() {
    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
    TEST_EID_FROM_CARD, // iccid
    null, // slotIndex
    1, // isRemovable
    false);
    uiccCardInfos.add(uiccCardInfo2);
    when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos);
    Map<Integer, Integer> slotMapping = new HashMap<>();
    slotMapping.put(0, 0);
    slotMapping.put(1, 1);
    when(mTelephonyManager.getLogicalToPhysicalSlotMapping()).thenReturn(slotMapping);
    when(mEuiccManager.isEnabled()).thenReturn(true);
    when(mEuiccManager.getEid()).thenReturn(TEST_EID_FROM_MANAGER);
    doNothing().when(mController).requestForUpdateEid();
    mController.updateEid(mController.getEid(0));
    mController.initialize();
    // Remove EID if the card is not eUICC.
    verify(mDialog, never()).setText(eq(EID_INFO_VALUE_ID), any());
    verify(mDialog).removeSettingFromScreen(eq(EID_INFO_LABEL_ID));
    verify(mDialog).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 7 with UiccCardInfo

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

the class SimStatusDialogControllerTest method initialize_updateEid_shouldSetEidInSingleSimModeWithDisabledEuicc.

@Test
public void initialize_updateEid_shouldSetEidInSingleSimModeWithDisabledEuicc() {
    when(mTelephonyManager.getActiveModemCount()).thenReturn(MAX_PHONE_COUNT_SINGLE_SIM);
    ArrayList<UiccCardInfo> uiccCardInfos = new ArrayList<>();
    UiccCardInfo uiccCardInfo = new UiccCardInfo(// isEuicc (eUICC slot is not selected)
    false, // cardId
    0, // eid
    null, // iccid
    "123451234567890", // slotIndex
    0, // isRemovable
    true);
    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 8 with UiccCardInfo

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

the class SimStatusDialogControllerTest method initialize_updateEid_shouldNotSetEid.

@Test
public void initialize_updateEid_shouldNotSetEid() {
    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(null);
    doNothing().when(mController).requestForUpdateEid();
    mController.updateEid(mController.getEid(0));
    mController.initialize();
    // Keep 'Not available' if neither the card nor the associated manager can provide EID.
    verify(mDialog, never()).setText(eq(EID_INFO_VALUE_ID), any());
    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 9 with UiccCardInfo

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

the class SimSlotChangeReceiver method isSimSlotStateValid.

// Checks whether the SIM slot state is valid for slot change event.
private boolean isSimSlotStateValid(Context context) {
    final TelephonyManager telMgr = context.getSystemService(TelephonyManager.class);
    UiccSlotInfo[] slotInfos = telMgr.getUiccSlotsInfo();
    if (slotInfos == null) {
        Log.e(TAG, "slotInfos is null. Unable to get slot infos.");
        return false;
    }
    boolean isAllCardStringsEmpty = true;
    for (int i = 0; i < slotInfos.length; i++) {
        UiccSlotInfo slotInfo = slotInfos[i];
        if (slotInfo == null) {
            return false;
        }
        // RESTRICTED.
        if (slotInfo.getCardStateInfo() == UiccSlotInfo.CARD_STATE_INFO_ERROR || slotInfo.getCardStateInfo() == UiccSlotInfo.CARD_STATE_INFO_RESTRICTED) {
            Log.i(TAG, "The SIM state is in an error. Drop the event. SIM info: " + slotInfo);
            return false;
        }
        UiccCardInfo cardInfo = findUiccCardInfoBySlot(telMgr, i);
        if (cardInfo == null) {
            continue;
        }
        if (!TextUtils.isEmpty(slotInfo.getCardId()) || !TextUtils.isEmpty(cardInfo.getIccId())) {
            isAllCardStringsEmpty = false;
        }
    }
    // between SIM slots switch the slot status is not stable at this moment.
    if (isAllCardStringsEmpty) {
        Log.i(TAG, "All UICC card strings are empty. Drop this event.");
        return false;
    }
    return true;
}
Also used : TelephonyManager(android.telephony.TelephonyManager) UiccSlotInfo(android.telephony.UiccSlotInfo) UiccCardInfo(android.telephony.UiccCardInfo)

Example 10 with UiccCardInfo

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

the class SimStatusDialogController method getEid.

@VisibleForTesting
protected AtomicReference<String> getEid(int slotIndex) {
    boolean shouldHaveEid = false;
    String eid = null;
    if (mTelephonyManager.getActiveModemCount() > MAX_PHONE_COUNT_SINGLE_SIM) {
        // Get EID per-SIM in multi-SIM mode
        final Map<Integer, Integer> mapping = mTelephonyManager.getLogicalToPhysicalSlotMapping();
        final int pSlotId = mapping.getOrDefault(slotIndex, SubscriptionManager.INVALID_SIM_SLOT_INDEX);
        if (pSlotId != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
            final List<UiccCardInfo> infos = mTelephonyManager.getUiccCardsInfo();
            for (UiccCardInfo info : infos) {
                if (info.getSlotIndex() == pSlotId) {
                    if (info.isEuicc()) {
                        shouldHaveEid = true;
                        eid = info.getEid();
                        if (TextUtils.isEmpty(eid)) {
                            eid = mEuiccManager.createForCardId(info.getCardId()).getEid();
                        }
                    }
                    break;
                }
            }
        }
    } else if (mEuiccManager.isEnabled()) {
        // Get EID of default eSIM in single-SIM mode
        shouldHaveEid = true;
        eid = mEuiccManager.getEid();
    }
    if ((!shouldHaveEid) && (eid == null)) {
        return null;
    }
    return new AtomicReference<String>(eid);
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) UiccCardInfo(android.telephony.UiccCardInfo) VisibleForTesting(androidx.annotation.VisibleForTesting)

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