From 650b048749cb5c4ae603e1eb3482a62f770503ac Mon Sep 17 00:00:00 2001 From: SongFerngWang Date: Wed, 9 Feb 2022 16:06:18 +0800 Subject: [PATCH] [MEP] Inserting a pSIM while user has 2 esims, showing the MEP dialog Inserting a pSIM while user has 2 esims already active, the UI shows MEP dialog Bug: 218451733 Test: manual test. To fake the MEP condition, and then checking the UI Change-Id: I48fa3d483873315d7e05b39369085c48af779522 Merged-In: I48fa3d483873315d7e05b39369085c48af779522 --- .../sim/receivers/SimSlotChangeHandler.java | 76 +++++++++++++++++-- 1 file changed, 69 insertions(+), 7 deletions(-) diff --git a/src/com/android/settings/sim/receivers/SimSlotChangeHandler.java b/src/com/android/settings/sim/receivers/SimSlotChangeHandler.java index 8c8964f798c..61241d01a56 100644 --- a/src/com/android/settings/sim/receivers/SimSlotChangeHandler.java +++ b/src/com/android/settings/sim/receivers/SimSlotChangeHandler.java @@ -26,12 +26,14 @@ import android.provider.Settings; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; +import android.telephony.UiccCardInfo; import android.telephony.UiccSlotInfo; import android.util.Log; import com.android.settings.network.SubscriptionUtil; import com.android.settings.network.UiccSlotUtil; import com.android.settings.network.UiccSlotsException; +import com.android.settings.network.telephony.ToggleSubscriptionDialogActivity; import com.android.settings.sim.ChooseSimActivity; import com.android.settings.sim.DsdsDialogActivity; import com.android.settings.sim.SimActivationNotifier; @@ -40,6 +42,7 @@ import com.android.settings.sim.SwitchToEsimConfirmDialogActivity; import com.google.common.collect.ImmutableList; +import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -83,8 +86,8 @@ public class SimSlotChangeHandler { throw new IllegalStateException("Cannot be called from main thread."); } - if (mTelMgr.getActiveModemCount() > 1) { - Log.i(TAG, "The device is already in DSDS mode. Do nothing."); + if (mTelMgr.getActiveModemCount() > 1 && !isMultipleEnabledProfilesSupported()) { + Log.i(TAG, "The device is already in DSDS mode and no MEP. Do nothing."); return; } @@ -96,17 +99,30 @@ public class SimSlotChangeHandler { int lastRemovableSlotState = getLastRemovableSimSlotState(mContext); int currentRemovableSlotState = removableSlotInfo.getCardStateInfo(); + boolean isRemovableSimInserted = + lastRemovableSlotState == UiccSlotInfo.CARD_STATE_INFO_ABSENT + && currentRemovableSlotState == UiccSlotInfo.CARD_STATE_INFO_PRESENT; + boolean isRemovableSimRemoved = + lastRemovableSlotState == UiccSlotInfo.CARD_STATE_INFO_PRESENT + && currentRemovableSlotState == UiccSlotInfo.CARD_STATE_INFO_ABSENT; // Sets the current removable slot state. setRemovableSimSlotState(mContext, currentRemovableSlotState); - if (lastRemovableSlotState == UiccSlotInfo.CARD_STATE_INFO_ABSENT - && currentRemovableSlotState == UiccSlotInfo.CARD_STATE_INFO_PRESENT) { + if (mTelMgr.getActiveModemCount() > 1 && isMultipleEnabledProfilesSupported()) { + if(!isRemovableSimInserted) { + Log.i(TAG, "Removable Sim is not inserted in DSDS mode and MEP. Do nothing."); + return; + } + handleRemovableSimInsertUnderDsdsMep(removableSlotInfo); + return; + } + + if (isRemovableSimInserted) { handleSimInsert(removableSlotInfo); return; } - if (lastRemovableSlotState == UiccSlotInfo.CARD_STATE_INFO_PRESENT - && currentRemovableSlotState == UiccSlotInfo.CARD_STATE_INFO_ABSENT) { + if (isRemovableSimRemoved) { handleSimRemove(removableSlotInfo); return; } @@ -232,6 +248,23 @@ public class SimSlotChangeHandler { startChooseSimActivity(false); } + private void handleRemovableSimInsertUnderDsdsMep(UiccSlotInfo removableSlotInfo) { + Log.i(TAG, "Handle Removable SIM inserted under DSDS+Mep."); + + if (removableSlotInfo.getPorts().stream().findFirst().get().isActive()) { + Log.i(TAG, "The removable slot is already active. Do nothing. removableSlotInfo: " + + removableSlotInfo); + return; + } + + List subscriptionInfos = getAvailableRemovableSubscription(); + if (subscriptionInfos == null && subscriptionInfos.get(0) != null) { + Log.e(TAG, "Unable to find the removable subscriptionInfo. Do nothing."); + return; + } + startSimConfirmDialogActivity(subscriptionInfos.get(0).getSubscriptionId()); + } + private int getLastRemovableSimSlotState(Context context) { final SharedPreferences prefs = context.getSharedPreferences(EUICC_PREFS, MODE_PRIVATE); return prefs.getInt(KEY_REMOVABLE_SLOT_STATE, UiccSlotInfo.CARD_STATE_INFO_ABSENT); @@ -261,7 +294,6 @@ public class SimSlotChangeHandler { } for (UiccSlotInfo slotInfo : slotInfos) { if (slotInfo != null && slotInfo.isRemovable()) { - return slotInfo; } } @@ -297,6 +329,16 @@ public class SimSlotChangeHandler { .collect(Collectors.toList())); } + protected List getAvailableRemovableSubscription() { + List subList = new ArrayList<>(); + for (SubscriptionInfo info : SubscriptionUtil.getAvailableSubscriptions(mContext)) { + if (!info.isEmbedded()) { + subList.add(info); + } + } + return subList; + } + private void startChooseSimActivity(boolean psimInserted) { Intent intent = ChooseSimActivity.getIntent(mContext); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); @@ -317,5 +359,25 @@ public class SimSlotChangeHandler { mContext.startActivity(intent); } + private void startSimConfirmDialogActivity(int subId) { + if (!SubscriptionManager.isUsableSubscriptionId(subId)) { + Log.i(TAG, "Unable to enable subscription due to invalid subscription ID."); + return; + } + Intent intent = ToggleSubscriptionDialogActivity.getIntent(mContext, subId, true); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + mContext.startActivity(intent); + } + + private boolean isMultipleEnabledProfilesSupported() { + List cardInfos = mTelMgr.getUiccCardsInfo(); + if (cardInfos == null) { + Log.w(TAG, "UICC cards info list is empty."); + return false; + } + return cardInfos.stream().anyMatch( + cardInfo -> cardInfo.isMultipleEnabledProfilesSupported()); + } + private SimSlotChangeHandler() {} }