Unable to enable the removable esim
When the user enable the removable esim, the settings select wrong slot(esim slot). The slot shold be the removable + esim slot and the UiccCardInfo's cardId is the same as the removable esim's cardId. Bug: 233170453 Bug: 233338345 Test: atest UiccSlotUtilTest Change-Id: Ibd324b781c84318c994e3742bb82e1d1393b94e4
This commit is contained in:
@@ -21,6 +21,8 @@ import android.app.PendingIntent;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.UiccCardInfo;
|
||||
import android.telephony.UiccPortInfo;
|
||||
import android.telephony.UiccSlotInfo;
|
||||
import android.telephony.UiccSlotMapping;
|
||||
import android.telephony.euicc.EuiccManager;
|
||||
import android.util.Log;
|
||||
@@ -28,6 +30,8 @@ import android.util.Log;
|
||||
import com.android.settings.SidecarFragment;
|
||||
import com.android.settings.network.telephony.EuiccOperationSidecar;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
@@ -44,6 +48,7 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
|
||||
private int mPort;
|
||||
private SubscriptionInfo mRemovedSubInfo;
|
||||
private boolean mIsDuringSimSlotMapping;
|
||||
private List<SubscriptionInfo> mActiveSubInfos;
|
||||
|
||||
/** Returns a SwitchToEuiccSubscriptionSidecar sidecar instance. */
|
||||
public static SwitchToEuiccSubscriptionSidecar get(FragmentManager fm) {
|
||||
@@ -87,6 +92,10 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
|
||||
setState(State.RUNNING, Substate.UNUSED);
|
||||
mCallbackIntent = createCallbackIntent();
|
||||
mSubId = subscriptionId;
|
||||
SubscriptionManager subscriptionManager = getContext().getSystemService(
|
||||
SubscriptionManager.class);
|
||||
mActiveSubInfos = SubscriptionUtil.getActiveSubscriptions(subscriptionManager);
|
||||
|
||||
int targetSlot = getTargetSlot();
|
||||
if (targetSlot < 0) {
|
||||
Log.d(TAG, "There is no esim, the TargetSlot is " + targetSlot);
|
||||
@@ -99,15 +108,29 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
|
||||
mPort = (port < 0) ? getTargetPortId(targetSlot, removedSubInfo) : port;
|
||||
mRemovedSubInfo = removedSubInfo;
|
||||
Log.d(TAG,
|
||||
String.format("set esim into the SubId%d Slot%d:Port%d",
|
||||
String.format("set esim into the SubId%d Physical Slot%d:Port%d",
|
||||
mSubId, targetSlot, mPort));
|
||||
|
||||
if (mTelephonyManager.isMultiSimEnabled() && removedSubInfo != null
|
||||
&& removedSubInfo.isEmbedded()) {
|
||||
// In DSDS mode+MEP, if the replaced esim is active, then it should be disabled esim
|
||||
// profile before changing SimSlotMapping process.
|
||||
// Use INVALID_SUBSCRIPTION_ID to disable the esim profile.
|
||||
// The SimSlotMapping is ready, then to execute activate/inactivate esim.
|
||||
if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||
// If the subId is INVALID_SUBSCRIPTION_ID, disable the esim (the default esim slot
|
||||
// which is selected by the framework).
|
||||
switchToSubscription();
|
||||
} else if ((mTelephonyManager.isMultiSimEnabled() && removedSubInfo != null
|
||||
&& removedSubInfo.isEmbedded())
|
||||
|| isEsimEnabledAtTargetSlotPort(targetSlot, mPort)) {
|
||||
// Case1: In DSDS mode+MEP, if the replaced esim is active, then the replaced esim
|
||||
// should be disabled before changing SimSlotMapping process.
|
||||
//
|
||||
// Case2: If the user enables the esimA on the target slot:port and the target
|
||||
// slot:port is active and there is an active esimB on target slot:port, then the
|
||||
// settings disables the esimB before the settings enables the esimA on the
|
||||
// target slot:port.
|
||||
//
|
||||
// Step:
|
||||
// 1. disables the replaced esim.
|
||||
// 2. switches the SimSlotMapping if the target slot port is not active.
|
||||
// 3. enables the target esim.
|
||||
// Note: Use INVALID_SUBSCRIPTION_ID to disable the esim profile.
|
||||
Log.d(TAG, "disable the enabled esim before the settings enables the target esim");
|
||||
mIsDuringSimSlotMapping = true;
|
||||
mEuiccManager.switchToSubscription(SubscriptionManager.INVALID_SUBSCRIPTION_ID, mPort,
|
||||
mCallbackIntent);
|
||||
@@ -117,8 +140,8 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
|
||||
}
|
||||
|
||||
private int getTargetPortId(int physicalEsimSlotIndex, SubscriptionInfo removedSubInfo) {
|
||||
if (!isMultipleEnabledProfilesSupported()) {
|
||||
Log.d(TAG, "The device is no MEP, port is 0");
|
||||
if (!isMultipleEnabledProfilesSupported(physicalEsimSlotIndex)) {
|
||||
Log.d(TAG, "The slotId" + physicalEsimSlotIndex + " is no MEP, port is 0");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -150,11 +173,12 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
|
||||
// port is 0.
|
||||
|
||||
int port = 0;
|
||||
SubscriptionManager subscriptionManager = getContext().getSystemService(
|
||||
SubscriptionManager.class);
|
||||
if(mActiveSubInfos == null){
|
||||
Log.d(TAG, "mActiveSubInfos is null.");
|
||||
return port;
|
||||
}
|
||||
List<SubscriptionInfo> activeEsimSubInfos =
|
||||
SubscriptionUtil.getActiveSubscriptions(subscriptionManager)
|
||||
.stream()
|
||||
mActiveSubInfos.stream()
|
||||
.filter(i -> i.isEmbedded())
|
||||
.sorted(Comparator.comparingInt(SubscriptionInfo::getPortIndex))
|
||||
.collect(Collectors.toList());
|
||||
@@ -167,7 +191,31 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
|
||||
}
|
||||
|
||||
private int getTargetSlot() {
|
||||
return UiccSlotUtil.getEsimSlotId(getContext());
|
||||
return UiccSlotUtil.getEsimSlotId(getContext(), mSubId);
|
||||
}
|
||||
|
||||
private boolean isEsimEnabledAtTargetSlotPort(int physicalSlotIndex, int portIndex) {
|
||||
int logicalSlotId = getLogicalSlotIndex(physicalSlotIndex, portIndex);
|
||||
if (logicalSlotId == SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
|
||||
return false;
|
||||
}
|
||||
return mActiveSubInfos != null
|
||||
&& mActiveSubInfos.stream()
|
||||
.anyMatch(i -> i.isEmbedded() && i.getSimSlotIndex() == logicalSlotId);
|
||||
}
|
||||
|
||||
private int getLogicalSlotIndex(int physicalSlotIndex, int portIndex) {
|
||||
ImmutableList<UiccSlotInfo> slotInfos = UiccSlotUtil.getSlotInfos(mTelephonyManager);
|
||||
if (slotInfos != null && physicalSlotIndex >= 0 && physicalSlotIndex < slotInfos.size()
|
||||
&& slotInfos.get(physicalSlotIndex) != null) {
|
||||
for (UiccPortInfo portInfo : slotInfos.get(physicalSlotIndex).getPorts()) {
|
||||
if (portInfo.getPortIndex() == portIndex) {
|
||||
return portInfo.getLogicalSlotIndex();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
|
||||
}
|
||||
|
||||
private void onSwitchSlotSidecarStateChange() {
|
||||
@@ -185,14 +233,15 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isMultipleEnabledProfilesSupported() {
|
||||
private boolean isMultipleEnabledProfilesSupported(int physicalEsimSlotIndex) {
|
||||
List<UiccCardInfo> cardInfos = mTelephonyManager.getUiccCardsInfo();
|
||||
if (cardInfos == null) {
|
||||
Log.w(TAG, "UICC cards info list is empty.");
|
||||
return false;
|
||||
}
|
||||
return cardInfos.stream().anyMatch(
|
||||
cardInfo -> cardInfo.isMultipleEnabledProfilesSupported());
|
||||
return cardInfos.stream()
|
||||
.anyMatch(cardInfo -> cardInfo.getPhysicalSlotIndex() == physicalEsimSlotIndex
|
||||
&& cardInfo.isMultipleEnabledProfilesSupported());
|
||||
}
|
||||
|
||||
private void switchToSubscription() {
|
||||
|
Reference in New Issue
Block a user