Search in sources :

Example 11 with UiccCardInfo

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

the class SubscriptionUtil method getFirstRemovableSubscription.

/**
 * Returns the subscription on a removable sim card. The device does not need to be on removable
 * slot.
 */
@Nullable
public static SubscriptionInfo getFirstRemovableSubscription(Context context) {
    TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class);
    SubscriptionManager subscriptionManager = context.getSystemService(SubscriptionManager.class);
    List<UiccCardInfo> cardInfos = telephonyManager.getUiccCardsInfo();
    if (cardInfos == null) {
        Log.w(TAG, "UICC cards info list is empty.");
        return null;
    }
    List<SubscriptionInfo> allSubscriptions = subscriptionManager.getAllSubscriptionInfoList();
    if (allSubscriptions == null) {
        Log.w(TAG, "All subscription info list is empty.");
        return null;
    }
    for (UiccCardInfo cardInfo : cardInfos) {
        if (cardInfo == null) {
            Log.w(TAG, "Got null card.");
            continue;
        }
        if (!cardInfo.isRemovable() || cardInfo.getCardId() == TelephonyManager.UNSUPPORTED_CARD_ID) {
            Log.i(TAG, "Skip embedded card or invalid cardId on slot: " + cardInfo.getSlotIndex());
            continue;
        }
        Log.i(TAG, "Target removable cardId :" + cardInfo.getCardId());
        for (SubscriptionInfo subInfo : allSubscriptions) {
            // Match the removable card id with subscription card id.
            if (cardInfo.getCardId() == subInfo.getCardId()) {
                return subInfo;
            }
        }
    }
    return null;
}
Also used : TelephonyManager(android.telephony.TelephonyManager) SubscriptionInfo(android.telephony.SubscriptionInfo) SubscriptionManager(android.telephony.SubscriptionManager) UiccCardInfo(android.telephony.UiccCardInfo) Nullable(android.annotation.Nullable)

Example 12 with UiccCardInfo

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

the class SimStatusDialogControllerTest method setup.

@Before
@UiThreadTest
public void setup() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(ApplicationProvider.getApplicationContext());
    when(mDialog.getContext()).thenReturn(mContext);
    mLifecycle = new Lifecycle(mLifecycleOwner);
    mTelephonyManager = spy(mContext.getSystemService(TelephonyManager.class));
    mSubscriptionManager = spy(mContext.getSystemService(SubscriptionManager.class));
    doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfoForSimSlotIndex(anyInt());
    when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
    when(mContext.getSystemService(CarrierConfigManager.class)).thenReturn(mCarrierConfigManager);
    when(mContext.getSystemService(EuiccManager.class)).thenReturn(mEuiccManager);
    when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
    doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(anyInt());
    doReturn(2).when(mTelephonyManager).getCardIdForDefaultEuicc();
    doReturn(TelephonyManager.NETWORK_TYPE_LTE).when(mTelephonyManager).getDataNetworkType();
    mController = spy(new SimStatusDialogController(mDialog, mLifecycle, 0));
    // CellSignalStrength setup
    doReturn(0).when(mCellSignalStrengthCdma).getDbm();
    doReturn(0).when(mCellSignalStrengthCdma).getAsuLevel();
    doReturn(0).when(mCellSignalStrengthLte).getDbm();
    doReturn(0).when(mCellSignalStrengthLte).getAsuLevel();
    doReturn(0).when(mCellSignalStrengthWcdma).getDbm();
    doReturn(0).when(mCellSignalStrengthWcdma).getAsuLevel();
    doReturn(null).when(mSignalStrength).getCellSignalStrengths();
    doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(anyInt());
    when(mTelephonyManager.getActiveModemCount()).thenReturn(MAX_PHONE_COUNT_SINGLE_SIM);
    doReturn(new ArrayList<UiccCardInfo>()).when(mTelephonyManager).getUiccCardsInfo();
    doReturn(new HashMap<Integer, Integer>()).when(mTelephonyManager).getLogicalToPhysicalSlotMapping();
    when(mEuiccManager.isEnabled()).thenReturn(false);
    when(mEuiccManager.getEid()).thenReturn("");
    when(mEuiccManager.createForCardId(anyInt())).thenReturn(mEuiccManager);
    mPersistableBundle = new PersistableBundle();
    when(mCarrierConfigManager.getConfigForSubId(anyInt())).thenReturn(mPersistableBundle);
    mPersistableBundle.putBoolean(CarrierConfigManager.KEY_SHOW_SIGNAL_STRENGTH_IN_SIM_STATUS_BOOL, true);
    doReturn(mServiceState).when(mTelephonyManager).getServiceState();
    doReturn(mSignalStrength).when(mTelephonyManager).getSignalStrength();
}
Also used : PersistableBundle(android.os.PersistableBundle) Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) UiccCardInfo(android.telephony.UiccCardInfo) Before(org.junit.Before) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 13 with UiccCardInfo

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

the class SimStatusDialogControllerTest method initialize_updateEid_shouldSetEidFromCard.

@Test
public void initialize_updateEid_shouldSetEidFromCard() {
    when(mTelephonyManager.getActiveModemCount()).thenReturn(MAX_PHONE_COUNT_DUAL_SIM);
    ArrayList<UiccCardInfo> uiccCardInfos = new ArrayList<>();
    UiccCardInfo uiccCardInfo1 = new UiccCardInfo(// isEuicc
    true, // cardId
    0, // eid
    TEST_EID_FROM_CARD, // iccid
    null, // slotIndex
    0, // isRemovable
    false);
    uiccCardInfos.add(uiccCardInfo1);
    UiccCardInfo uiccCardInfo2 = new UiccCardInfo(// isEuicc
    false, // cardId
    1, // eid
    null, // iccid
    "123451234567890", // slotIndex
    1, // isRemovable
    true);
    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);
    when(mEuiccManager.createForCardId(0)).thenReturn(mEuiccManager);
    doNothing().when(mController).requestForUpdateEid();
    mController.updateEid(mController.getEid(0));
    mController.initialize();
    // Set EID retrieved from the card.
    verify(mDialog).setText(EID_INFO_VALUE_ID, TEST_EID_FROM_CARD);
    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 14 with UiccCardInfo

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

the class SimStatusDialogControllerTest method initialize_updateEid_shouldNotSetEidInSingleSimMode.

@Test
public void initialize_updateEid_shouldNotSetEidInSingleSimMode() {
    when(mTelephonyManager.getActiveModemCount()).thenReturn(MAX_PHONE_COUNT_SINGLE_SIM);
    ArrayList<UiccCardInfo> uiccCardInfos = new ArrayList<>();
    UiccCardInfo uiccCardInfo = new UiccCardInfo(// isEuicc
    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(null);
    doNothing().when(mController).requestForUpdateEid();
    mController.updateEid(mController.getEid(0));
    mController.initialize();
    // Keep 'Not available' if the default eUICC manager cannot provide EID in Single SIM mode.
    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 15 with UiccCardInfo

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

the class SimStatusDialogControllerTest method initialize_updateEid_shouldRemoveEidInSingleSimMode.

@Test
public void initialize_updateEid_shouldRemoveEidInSingleSimMode() {
    when(mTelephonyManager.getActiveModemCount()).thenReturn(MAX_PHONE_COUNT_SINGLE_SIM);
    ArrayList<UiccCardInfo> uiccCardInfos = new ArrayList<>();
    UiccCardInfo uiccCardInfo = new UiccCardInfo(// isEuicc
    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(false);
    when(mEuiccManager.getEid()).thenReturn(null);
    doNothing().when(mController).requestForUpdateEid();
    mController.updateEid(mController.getEid(0));
    mController.initialize();
    // Remove EID if the default eUICC manager indicates that eSIM is not enabled.
    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)

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