eSIM deprecated API test Refactoring

Test: build
Bug: 159354974
Change-Id: Iedeb90f186ab9f82894e2fecef86d339c8989542
This commit is contained in:
sandeepjs
2021-09-30 09:09:59 +00:00
parent 666d0984d4
commit 40ffe69a3e
8 changed files with 165 additions and 55 deletions

View File

@@ -631,7 +631,7 @@ public class SimStatusDialogController implements LifecycleObserver {
final List<UiccCardInfo> infos = mTelephonyManager.getUiccCardsInfo(); final List<UiccCardInfo> infos = mTelephonyManager.getUiccCardsInfo();
for (UiccCardInfo info : infos) { for (UiccCardInfo info : infos) {
if (info.getSlotIndex() == pSlotId) { if (info.getPhysicalSlotIndex() == pSlotId) {
if (info.isEuicc()) { if (info.isEuicc()) {
shouldHaveEid = true; shouldHaveEid = true;
eid = info.getEid(); eid = info.getEid();

View File

@@ -24,6 +24,7 @@ import android.content.IntentFilter;
import android.provider.Settings; import android.provider.Settings;
import android.telephony.CarrierConfigManager; import android.telephony.CarrierConfigManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.telephony.UiccPortInfo;
import android.telephony.UiccSlotInfo; import android.telephony.UiccSlotInfo;
import android.util.ArraySet; import android.util.ArraySet;
import android.util.Log; import android.util.Log;
@@ -62,23 +63,23 @@ public class EnableMultiSimSidecar extends AsyncTaskSidecar<Void, Boolean> {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
int readySimsCount = getReadySimsCount(); int readySimsCount = getReadySimsCount();
int activeSlotsCount = getActiveSlotsCount(); int activePortsCount = getActivePortsCount();
// If the number of ready SIM count and active slots equal to the number of SIMs // If the number of ready SIM count and active ports equal to the number of SIMs
// need to be activated, the device is successfully switched to multiple active // need to be activated, the device is successfully switched to multiple active
// SIM mode. // SIM mode.
if (readySimsCount == mNumOfActiveSim && activeSlotsCount == mNumOfActiveSim) { if (readySimsCount == mNumOfActiveSim && activePortsCount == mNumOfActiveSim) {
Log.i( Log.i(
TAG, TAG,
String.format("%d slots are active and ready.", mNumOfActiveSim)); String.format("%d ports are active and ready.", mNumOfActiveSim));
mSimCardStateChangedLatch.countDown(); mSimCardStateChangedLatch.countDown();
return; return;
} }
Log.i( Log.i(
TAG, TAG,
String.format( String.format(
"%d slots are active and %d SIMs are ready. Keep waiting until" "%d ports are active and %d SIMs are ready. Keep waiting until"
+ " timeout.", + " timeout.",
activeSlotsCount, readySimsCount)); activePortsCount, readySimsCount));
} }
}; };
@@ -162,19 +163,22 @@ public class EnableMultiSimSidecar extends AsyncTaskSidecar<Void, Boolean> {
return readyCardsCount; return readyCardsCount;
} }
// Get active slots count from {@code TelephonyManager#getUiccSlotsInfo}. // Get active port count from {@code TelephonyManager#getUiccSlotsInfo}.
private int getActiveSlotsCount() { private int getActivePortsCount() {
UiccSlotInfo[] slotsInfo = mTelephonyManager.getUiccSlotsInfo(); UiccSlotInfo[] slotsInfo = mTelephonyManager.getUiccSlotsInfo();
if (slotsInfo == null) { if (slotsInfo == null) {
return 0; return 0;
} }
int activeSlots = 0; int activePorts = 0;
for (UiccSlotInfo slotInfo : slotsInfo) { for (UiccSlotInfo slotInfo : slotsInfo) {
if (slotInfo != null && slotInfo.getIsActive()) { for (UiccPortInfo portInfo : slotInfo.getPorts()) {
activeSlots++; if (slotInfo != null && portInfo.isActive()) {
activePorts++;
}
} }
} }
return activeSlots; return activePorts;
} }
/** Returns a list of active removable logical slot ids. */ /** Returns a list of active removable logical slot ids. */
@@ -185,8 +189,10 @@ public class EnableMultiSimSidecar extends AsyncTaskSidecar<Void, Boolean> {
} }
Set<Integer> activeRemovableLogicalSlotIds = new ArraySet<>(); Set<Integer> activeRemovableLogicalSlotIds = new ArraySet<>();
for (UiccSlotInfo info : infos) { for (UiccSlotInfo info : infos) {
if (info != null && info.getIsActive() && info.isRemovable()) { for (UiccPortInfo portInfo :info.getPorts()) {
activeRemovableLogicalSlotIds.add(info.getLogicalSlotIdx()); if (info != null && portInfo.isActive() && info.isRemovable()) {
activeRemovableLogicalSlotIds.add(portInfo.getLogicalSlotIndex());
}
} }
} }
return activeRemovableLogicalSlotIds; return activeRemovableLogicalSlotIds;

View File

@@ -87,8 +87,8 @@ public class SubscriptionUtil {
if (slotInfo == null) { if (slotInfo == null) {
return false; return false;
} }
return !slotInfo.getIsEuicc() && !slotInfo.getIsActive() && return !slotInfo.getIsEuicc() && !slotInfo.getPorts().stream().findFirst().get()
slotInfo.getCardStateInfo() == CARD_STATE_INFO_PRESENT; .isActive() && slotInfo.getCardStateInfo() == CARD_STATE_INFO_PRESENT;
} }
/** /**
@@ -179,7 +179,8 @@ public class SubscriptionUtil {
// verify if subscription is inserted within slot // verify if subscription is inserted within slot
for (UiccSlotInfo slotInfo : slotsInfo) { for (UiccSlotInfo slotInfo : slotsInfo) {
if ((slotInfo != null) && (!slotInfo.getIsEuicc()) if ((slotInfo != null) && (!slotInfo.getIsEuicc())
&& (slotInfo.getLogicalSlotIdx() == subInfo.getSimSlotIndex())) { && (slotInfo.getPorts().stream().findFirst().get().getLogicalSlotIndex()
== subInfo.getSimSlotIndex())) {
return true; return true;
} }
} }
@@ -576,7 +577,7 @@ public class SubscriptionUtil {
if (!cardInfo.isRemovable() if (!cardInfo.isRemovable()
|| cardInfo.getCardId() == TelephonyManager.UNSUPPORTED_CARD_ID) { || cardInfo.getCardId() == TelephonyManager.UNSUPPORTED_CARD_ID) {
Log.i(TAG, "Skip embedded card or invalid cardId on slot: " Log.i(TAG, "Skip embedded card or invalid cardId on slot: "
+ cardInfo.getSlotIndex()); + cardInfo.getPhysicalSlotIndex());
continue; continue;
} }
Log.i(TAG, "Target removable cardId :" + cardInfo.getCardId()); Log.i(TAG, "Target removable cardId :" + cardInfo.getCardId());

View File

@@ -96,7 +96,7 @@ public class UiccSlotUtil {
if (slotId == INVALID_PHYSICAL_SLOT_ID) { if (slotId == INVALID_PHYSICAL_SLOT_ID) {
for (int i = 0; i < slots.length; i++) { for (int i = 0; i < slots.length; i++) {
if (slots[i].isRemovable() if (slots[i].isRemovable()
&& !slots[i].getIsActive() && !slots[i].getPorts().stream().findFirst().get().isActive()
&& slots[i].getCardStateInfo() != UiccSlotInfo.CARD_STATE_INFO_ERROR && slots[i].getCardStateInfo() != UiccSlotInfo.CARD_STATE_INFO_ERROR
&& slots[i].getCardStateInfo() != UiccSlotInfo.CARD_STATE_INFO_RESTRICTED) { && slots[i].getCardStateInfo() != UiccSlotInfo.CARD_STATE_INFO_RESTRICTED) {
performSwitchToRemovableSlot(i, context); performSwitchToRemovableSlot(i, context);
@@ -107,7 +107,7 @@ public class UiccSlotUtil {
if (slotId >= slots.length || !slots[slotId].isRemovable()) { if (slotId >= slots.length || !slots[slotId].isRemovable()) {
throw new UiccSlotsException("The given slotId is not a removable slot: " + slotId); throw new UiccSlotsException("The given slotId is not a removable slot: " + slotId);
} }
if (!slots[slotId].getIsActive()) { if (!slots[slotId].getPorts().stream().findFirst().get().isActive()) {
performSwitchToRemovableSlot(slotId, context); performSwitchToRemovableSlot(slotId, context);
} }
} }

View File

@@ -484,7 +484,8 @@ public class ToggleSubscriptionDialogActivity extends SubscriptionActionDialogAc
slot -> slot ->
slot != null slot != null
&& slot.isRemovable() && slot.isRemovable()
&& slot.getIsActive() && slot.getPorts().stream().anyMatch(
port -> port.isActive())
&& slot.getCardStateInfo() && slot.getCardStateInfo()
== UiccSlotInfo.CARD_STATE_INFO_PRESENT); == UiccSlotInfo.CARD_STATE_INFO_PRESENT);
if (mIsEsimOperation && isRemovableSimEnabled) { if (mIsEsimOperation && isRemovableSimEnabled) {
@@ -498,7 +499,7 @@ public class ToggleSubscriptionDialogActivity extends SubscriptionActionDialogAc
Log.i( Log.i(
TAG, TAG,
"Removable SIM operation and eSIM profile is enabled. DSDS condition" "Removable SIM operation and eSIM profile is enabled. DSDS condition"
+ " satisfied."); + " satisfied.");
return true; return true;
} }
Log.i(TAG, "DSDS condition not satisfied."); Log.i(TAG, "DSDS condition not satisfied.");

View File

@@ -164,14 +164,12 @@ public class SimSlotChangeHandler {
private void handleSimInsert(UiccSlotInfo removableSlotInfo) { private void handleSimInsert(UiccSlotInfo removableSlotInfo) {
Log.i(TAG, "Handle SIM inserted."); Log.i(TAG, "Handle SIM inserted.");
if (!isSuwFinished(mContext)) { if (!isSuwFinished(mContext)) {
Log.i(TAG, "Still in SUW. Handle SIM insertion after SUW is finished"); Log.i(TAG, "Still in SUW. Handle SIM insertion after SUW is finished");
setSuwRemovableSlotAction(mContext, LAST_USER_ACTION_IN_SUW_INSERT); setSuwRemovableSlotAction(mContext, LAST_USER_ACTION_IN_SUW_INSERT);
return; return;
} }
if (removableSlotInfo.getPorts().stream().findFirst().get().isActive()) {
if (removableSlotInfo.getIsActive()) {
Log.i(TAG, "The removable slot is already active. Do nothing."); Log.i(TAG, "The removable slot is already active. Do nothing.");
return; return;
} }
@@ -213,7 +211,8 @@ public class SimSlotChangeHandler {
List<SubscriptionInfo> groupedEmbeddedSubscriptions = getGroupedEmbeddedSubscriptions(); List<SubscriptionInfo> groupedEmbeddedSubscriptions = getGroupedEmbeddedSubscriptions();
if (groupedEmbeddedSubscriptions.size() == 0 || !removableSlotInfo.getIsActive()) { if (groupedEmbeddedSubscriptions.size() == 0 || !removableSlotInfo.getPorts().stream()
.findFirst().get().isActive()) {
Log.i(TAG, "eSIM slot is active or no subscriptions exist. Do nothing."); Log.i(TAG, "eSIM slot is active or no subscriptions exist. Do nothing.");
return; return;
} }

View File

@@ -20,6 +20,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.telephony.UiccCardInfo; import android.telephony.UiccCardInfo;
import android.telephony.UiccPortInfo;
import android.telephony.UiccSlotInfo; import android.telephony.UiccSlotInfo;
import android.telephony.euicc.EuiccManager; import android.telephony.euicc.EuiccManager;
import android.text.TextUtils; import android.text.TextUtils;
@@ -116,9 +117,11 @@ public class SimSlotChangeReceiver extends BroadcastReceiver {
if (cardInfo == null) { if (cardInfo == null) {
continue; continue;
} }
if (!TextUtils.isEmpty(slotInfo.getCardId()) for (UiccPortInfo portInfo : cardInfo.getPorts()) {
|| !TextUtils.isEmpty(cardInfo.getIccId())) { if (!TextUtils.isEmpty(slotInfo.getCardId())
isAllCardStringsEmpty = false; || !TextUtils.isEmpty(portInfo.getIccId())) {
isAllCardStringsEmpty = false;
}
} }
} }
@@ -139,7 +142,7 @@ public class SimSlotChangeReceiver extends BroadcastReceiver {
return null; return null;
} }
return cardInfos.stream() return cardInfos.stream()
.filter(info -> info.getSlotIndex() == physicalSlotIndex) .filter(info -> info.getPhysicalSlotIndex() == physicalSlotIndex)
.findFirst() .findFirst()
.orElse(null); .orElse(null);
} }

View File

@@ -54,6 +54,7 @@ import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.telephony.UiccCardInfo; import android.telephony.UiccCardInfo;
import android.telephony.UiccPortInfo;
import android.telephony.euicc.EuiccManager; import android.telephony.euicc.EuiccManager;
import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleOwner;
@@ -73,6 +74,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -387,17 +389,34 @@ public class SimStatusDialogControllerTest {
false, // isEuicc false, // isEuicc
0, // cardId 0, // cardId
null, // eid null, // eid
"123451234567890", // iccid
0, // slotIndex 0, // slotIndex
true); // isRemovable true, // isRemovable
false, // isMultipleEnabledProfileSupported
Collections.singletonList(
new UiccPortInfo(
"123451234567890", // iccId
0, // portIdx
0, // logicalSlotIdx
true // isActive
)
));
uiccCardInfos.add(uiccCardInfo1); uiccCardInfos.add(uiccCardInfo1);
UiccCardInfo uiccCardInfo2 = new UiccCardInfo( UiccCardInfo uiccCardInfo2 = new UiccCardInfo(
true, // isEuicc true, // isEuicc
1, // cardId 1, // cardId
null, // eid (unavailable) null, // eid (unavailable)
null, // iccid
1, // slotIndex 1, // slotIndex
false); // isRemovable false, // isRemovable
false,
Collections.singletonList(
new UiccPortInfo(
null, // iccId
1, // portIdx
1, // logicalSlotIdx
true // isActive
)
)
);
uiccCardInfos.add(uiccCardInfo2); uiccCardInfos.add(uiccCardInfo2);
when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos); when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos);
@@ -427,17 +446,31 @@ public class SimStatusDialogControllerTest {
true, // isEuicc true, // isEuicc
0, // cardId 0, // cardId
TEST_EID_FROM_CARD, // eid TEST_EID_FROM_CARD, // eid
null, // iccid
0, // slotIndex 0, // slotIndex
false); // isRemovable false, // isRemovable
false,
Collections.singletonList(new UiccPortInfo(
null, // iccId
0, // portIdx
0, // logicalSlotIdx
true // isActive
)));
uiccCardInfos.add(uiccCardInfo1); uiccCardInfos.add(uiccCardInfo1);
UiccCardInfo uiccCardInfo2 = new UiccCardInfo( UiccCardInfo uiccCardInfo2 = new UiccCardInfo(
false, // isEuicc false, // isEuicc
1, // cardId 1, // cardId
null, // eid null, // eid
"123451234567890", // iccid
1, // slotIndex 1, // slotIndex
true); // isRemovable true, // isRemovable
false, // isMultipleEnabledProfileSupported
Collections.singletonList(
new UiccPortInfo(
"123451234567890", // iccId
1, // portIdx
1, // logicalSlotIdx
true // isActive
)
));
uiccCardInfos.add(uiccCardInfo2); uiccCardInfos.add(uiccCardInfo2);
when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos); when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos);
@@ -468,17 +501,34 @@ public class SimStatusDialogControllerTest {
false, // isEuicc false, // isEuicc
0, // cardId 0, // cardId
null, // eid null, // eid
"123451234567890", // iccid
0, // slotIndex 0, // slotIndex
true); // isRemovable true, // isRemovable
false, // isMultipleEnabledProfileSupported
Collections.singletonList(
new UiccPortInfo(
"123451234567890", // iccId
1, // portIdx
1, // logicalSlotIdx
true // isActive
)
));
uiccCardInfos.add(uiccCardInfo1); uiccCardInfos.add(uiccCardInfo1);
UiccCardInfo uiccCardInfo2 = new UiccCardInfo( UiccCardInfo uiccCardInfo2 = new UiccCardInfo(
true, // isEuicc true, // isEuicc
1, // cardId 1, // cardId
null, // eid (unavailable) null, // eid (unavailable)
null, // iccid
1, // slotIndex 1, // slotIndex
false); // isRemovable false, // isRemovable
false, // isMultipleEnabledProfileSupported
Collections.singletonList(
new UiccPortInfo(
null, // iccId
1, // portIdx
1, // logicalSlotIdx
true // isActive
)
)
);
uiccCardInfos.add(uiccCardInfo2); uiccCardInfos.add(uiccCardInfo2);
when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos); when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos);
@@ -511,17 +561,33 @@ public class SimStatusDialogControllerTest {
false, // isEuicc false, // isEuicc
0, // cardId 0, // cardId
null, // eid null, // eid
"123451234567890", // iccid
0, // slotIndex 0, // slotIndex
true); // isRemovable true, // isRemovable
false, // isMultipleEnabledProfileSupported
Collections.singletonList(
new UiccPortInfo(
"123451234567890", // iccId
0, // portIdx
0, // logicalSlotIdx
true // isActive
)
));
uiccCardInfos.add(uiccCardInfo1); uiccCardInfos.add(uiccCardInfo1);
UiccCardInfo uiccCardInfo2 = new UiccCardInfo( UiccCardInfo uiccCardInfo2 = new UiccCardInfo(
true, // isEuicc true, // isEuicc
1, // cardId 1, // cardId
TEST_EID_FROM_CARD, // eid TEST_EID_FROM_CARD, // eid
null, // iccid
1, // slotIndex 1, // slotIndex
false); // isRemovable false, // isRemovable
false, // isMultipleEnabledProfileSupported
Collections.singletonList(
new UiccPortInfo(
null, // iccId
1, // portIdx
1, // logicalSlotIdx
true // isActive
)
));
uiccCardInfos.add(uiccCardInfo2); uiccCardInfos.add(uiccCardInfo2);
when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos); when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos);
@@ -552,9 +618,17 @@ public class SimStatusDialogControllerTest {
true, // isEuicc true, // isEuicc
0, // cardId 0, // cardId
TEST_EID_FROM_CARD, // eid (not used) TEST_EID_FROM_CARD, // eid (not used)
null, // iccid
0, // slotIndex 0, // slotIndex
false); // isRemovable false, // isRemovable
false, // isMultipleEnabledProfileSupported
Collections.singletonList(
new UiccPortInfo(
null, // iccId
0, // portIdx
0, // logicalSlotIdx
true // isActive
)
));
uiccCardInfos.add(uiccCardInfo); uiccCardInfos.add(uiccCardInfo);
when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos); when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos);
@@ -583,9 +657,18 @@ public class SimStatusDialogControllerTest {
true, // isEuicc (eUICC slot is selected) true, // isEuicc (eUICC slot is selected)
0, // cardId 0, // cardId
TEST_EID_FROM_CARD, // eid (not used) TEST_EID_FROM_CARD, // eid (not used)
null, // iccid
0, // slotIndex 0, // slotIndex
false); // isRemovable false, // isRemovable
false, // isMultipleEnabledProfileSupported
Collections.singletonList(
new UiccPortInfo(
null, // iccId
0, // portIdx
0, // logicalSlotIdx
true // isActive
)
)
);
uiccCardInfos.add(uiccCardInfo); uiccCardInfos.add(uiccCardInfo);
when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos); when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos);
@@ -616,9 +699,18 @@ public class SimStatusDialogControllerTest {
false, // isEuicc (eUICC slot is not selected) false, // isEuicc (eUICC slot is not selected)
0, // cardId 0, // cardId
null, // eid null, // eid
"123451234567890", // iccid
0, // slotIndex 0, // slotIndex
true); // isRemovable true, // isRemovable
false, // isMultipleEnabledProfileSupported
Collections.singletonList(
new UiccPortInfo(
"123451234567890", // iccId
0, // portIdx
0, // logicalSlotIdx
true // isActive
)
));
uiccCardInfos.add(uiccCardInfo); uiccCardInfos.add(uiccCardInfo);
when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos); when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos);
@@ -649,9 +741,17 @@ public class SimStatusDialogControllerTest {
false, // isEuicc false, // isEuicc
0, // cardId 0, // cardId
null, // eid null, // eid
"123451234567890", // iccid
0, // slotIndex 0, // slotIndex
true); // isRemovable true, // isRemovable
false, //isMultipleEnabledProfileSupported
Collections.singletonList(
new UiccPortInfo(
"123451234567890", // iccId
0, // portIdx
0, // logicalSlotIdx
true // isActive
)
));
uiccCardInfos.add(uiccCardInfo); uiccCardInfos.add(uiccCardInfo);
when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos); when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos);