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));
}
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;
}
}
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;
}
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));
}
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));
}
Aggregations