From f554e16f45ef9ca186f03be079b070bb269bd7f9 Mon Sep 17 00:00:00 2001 From: songferngwang Date: Tue, 25 Jun 2024 09:32:26 +0000 Subject: [PATCH] Add more condition to avoid to open the SimOnboardingActivity when the user inserts the psim, showing the sim onboarding for the user to setup the sim switching or the default data subscription in DSDS. Will show dialog for below cases. 1. the psim slot is not active. 2. there are one or more active sim. Bug: 348524643 Test: verify the UI Flag: EXEMPT bugfix Change-Id: I3c782fa2486fde25ac15a69b48ba2f07f90572bd --- .../sim/receivers/SimSlotChangeHandler.java | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/com/android/settings/sim/receivers/SimSlotChangeHandler.java b/src/com/android/settings/sim/receivers/SimSlotChangeHandler.java index 8f934d7e887..9394af16945 100644 --- a/src/com/android/settings/sim/receivers/SimSlotChangeHandler.java +++ b/src/com/android/settings/sim/receivers/SimSlotChangeHandler.java @@ -28,6 +28,7 @@ import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.telephony.UiccCardInfo; +import android.telephony.UiccPortInfo; import android.telephony.UiccSlotInfo; import android.util.Log; @@ -91,10 +92,10 @@ public class SimSlotChangeHandler { Log.e(TAG, "Unable to find the removable slot. Do nothing."); return; } - + Log.i(TAG, "The removableSlotInfo: " + removableSlotInfo); int lastRemovableSlotState = getLastRemovableSimSlotState(mContext); int currentRemovableSlotState = removableSlotInfo.getCardStateInfo(); - Log.i(TAG, + Log.d(TAG, "lastRemovableSlotState: " + lastRemovableSlotState + ",currentRemovableSlotState: " + currentRemovableSlotState); boolean isRemovableSimInserted = @@ -115,8 +116,12 @@ public class SimSlotChangeHandler { if (Flags.isDualSimOnboardingEnabled()) { // ForNewUi, when the user inserts the psim, showing the sim onboarding for the user - // to setup the sim switching or the default data subscription. - handleRemovableSimInsertWhenDsds(); + // to setup the sim switching or the default data subscription in DSDS. + // Will show dialog for below case. + // 1. the psim slot is not active. + // 2. there are one or more active sim. + handleRemovableSimInsertWhenDsds(removableSlotInfo); + return; } else if (!isMultipleEnabledProfilesSupported()) { Log.d(TAG, "The device is already in DSDS mode and no MEP. Do nothing."); return; @@ -124,8 +129,6 @@ public class SimSlotChangeHandler { handleRemovableSimInsertUnderDsdsMep(removableSlotInfo); return; } - Log.d(TAG, "the device is already in DSDS mode and have the DDS. Do nothing."); - return; } if (isRemovableSimInserted) { @@ -258,15 +261,29 @@ public class SimSlotChangeHandler { startChooseSimActivity(false); } - private void handleRemovableSimInsertWhenDsds() { + private boolean hasOtherActiveSubInfo(int psimSubId) { + List activeSubs = SubscriptionUtil.getActiveSubscriptions(mSubMgr); + return activeSubs.stream() + .anyMatch(subscriptionInfo -> subscriptionInfo.getSubscriptionId() != psimSubId); + } + + private boolean hasAnyPortActiveInSlot(UiccSlotInfo removableSlotInfo) { + return removableSlotInfo.getPorts().stream().anyMatch(UiccPortInfo::isActive); + } + + private void handleRemovableSimInsertWhenDsds(UiccSlotInfo removableSlotInfo) { + Log.i(TAG, "ForNewUi: Handle Removable SIM inserted"); List subscriptionInfos = getAvailableRemovableSubscription(); if (subscriptionInfos.isEmpty()) { Log.e(TAG, "Unable to find the removable subscriptionInfo. Do nothing."); return; } - Log.d(TAG, "ForNewUi and getAvailableRemovableSubscription:" - + subscriptionInfos); - startSimConfirmDialogActivity(subscriptionInfos.get(0).getSubscriptionId()); + Log.d(TAG, "getAvailableRemovableSubscription:" + subscriptionInfos); + int psimSubId = subscriptionInfos.get(0).getSubscriptionId(); + if (!hasAnyPortActiveInSlot(removableSlotInfo) || hasOtherActiveSubInfo(psimSubId)) { + Log.d(TAG, "ForNewUi Start Setup flow"); + startSimConfirmDialogActivity(psimSubId); + } } private void handleRemovableSimInsertUnderDsdsMep(UiccSlotInfo removableSlotInfo) {