[MEP]The Esim's PhysicalSlotIndex is wrong

Using the getUiccSlotInfo API to get the PhysicalSlotIndex of esim

Bug: 215302360
Test: atest UiccSlotUtilTest
Change-Id: Ic43d6c4a3209d24673769b71b9a148e780ee81ab
This commit is contained in:
SongFerngWang
2022-01-27 17:31:40 +08:00
parent 0042654d60
commit 28bed8ec9f
3 changed files with 234 additions and 9 deletions

View File

@@ -37,7 +37,6 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
private static final String TAG = "SwitchToEuiccSidecar";
private static final String ACTION_SWITCH_TO_SUBSCRIPTION =
"com.android.settings.network.SWITCH_TO_SUBSCRIPTION";
private static final int ESIM_SLOT_ID = 1;
private PendingIntent mCallbackIntent;
private int mSubId;
@@ -92,11 +91,20 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
setState(State.RUNNING, Substate.UNUSED);
mCallbackIntent = createCallbackIntent();
mSubId = subscriptionId;
int targetSlot = getTargetSlot();
if (targetSlot < 0) {
Log.d(TAG, "There is no esim, the TargetSlot is " + targetSlot);
setState(State.ERROR, Substate.UNUSED);
return;
}
// To check whether the esim slot's port is active. If yes, skip setSlotMapping. If no,
// set this slot+port into setSimSlotMapping.
mPort = (port < 0) ? getTargetPortId(removedSubInfo) : port;
mPort = (port < 0) ? getTargetPortId(removedSubInfo, targetSlot) : port;
mRemovedSubInfo = removedSubInfo;
Log.i(TAG, "The SubId is " + mSubId + ". The port is " + mPort);
Log.d(TAG,
String.format("set esim into the Slot%d SubId%d:Port%d",
targetSlot, mSubId, mPort));
if (mTelephonyManager.isMultiSimEnabled() && removedSubInfo != null
&& removedSubInfo.isEmbedded()) {
@@ -108,11 +116,11 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
mEuiccManager.switchToSubscription(SubscriptionManager.INVALID_SUBSCRIPTION_ID, mPort,
mCallbackIntent);
} else {
mSwitchSlotSidecar.runSwitchToEuiccSlot(getTargetSlot(), mPort, removedSubInfo);
mSwitchSlotSidecar.runSwitchToEuiccSlot(targetSlot, mPort, removedSubInfo);
}
}
private int getTargetPortId(SubscriptionInfo removedSubInfo) {
private int getTargetPortId(SubscriptionInfo removedSubInfo, int targetSlot) {
if (!mTelephonyManager.isMultiSimEnabled() || !isMultipleEnabledProfilesSupported()) {
// In the 'SS mode' or 'DSDS+no MEP', the port is 0.
return 0;
@@ -124,16 +132,19 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
return removedSubInfo.getPortIndex();
}
// In DSDS+MEP mode, the removedSubInfo is psim or is null, it means the this esim need
// In DSDS+MEP mode, the removedSubInfo is psim or is null, it means this esim needs
// another port in the esim slot.
// To find another esim's port and value is from 0;
// To find another esim's port and value is from 0.
// For example:
// 1) If there is no enabled esim and the user add new esim. This new esim's port is 0.
// 2) If there is one enabled esim and the user add new esim. This new esim's port is 1.
int port = 0;
Collection<UiccSlotMapping> uiccSlotMappings = mTelephonyManager.getSimSlotMapping();
for (UiccSlotMapping uiccSlotMapping :
uiccSlotMappings.stream()
.filter(
uiccSlotMapping -> uiccSlotMapping.getPhysicalSlotIndex()
== getTargetSlot())
== targetSlot)
.collect(Collectors.toList())) {
if (uiccSlotMapping.getPortIndex() == port) {
port++;
@@ -143,7 +154,7 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
}
private int getTargetSlot() {
return ESIM_SLOT_ID;
return UiccSlotUtil.getEsimSlotId(getContext());
}
private void onSwitchSlotSidecarStateChange() {

View File

@@ -36,6 +36,7 @@ import java.util.Collection;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// ToDo: to do the refactor for renaming
public class UiccSlotUtil {
@@ -174,6 +175,28 @@ public class UiccSlotUtil {
performSwitchToSlot(telMgr, newUiccSlotMappings, context);
}
/**
* @param context the application context.
* @return the esim slot. If the value is -1, there is not the esim.
*/
public static int getEsimSlotId(Context context) {
TelephonyManager telMgr = context.getSystemService(TelephonyManager.class);
ImmutableList<UiccSlotInfo> slotInfos = UiccSlotUtil.getSlotInfos(telMgr);
int firstEsimSlot = IntStream.range(0, slotInfos.size())
.filter(
index -> {
UiccSlotInfo slotInfo = slotInfos.get(index);
if (slotInfo == null) {
return false;
}
return !slotInfo.isRemovable();
})
.findFirst().orElse(-1);
Log.i(TAG, "firstEsimSlot: " + firstEsimSlot);
return firstEsimSlot;
}
private static boolean isTargetSlotActive(Collection<UiccSlotMapping> uiccSlotMappings,
int slotId, int port) {
return uiccSlotMappings.stream()