From 62163de58551c744e51e4cfe50690302f458cc05 Mon Sep 17 00:00:00 2001 From: songferngwang Date: Wed, 19 Mar 2025 10:30:50 +0000 Subject: [PATCH] Using current esim port of active esim slot If there is no active esim and the active esim slot, then enabling esim uses the active esim slot's port. Bug: 394758842 Test: manual test Flag: EXEMPT bugfix Change-Id: Icd478a92662584d433e16b129da98204e9e2f5f3 --- .../SwitchToEuiccSubscriptionSidecar.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/network/SwitchToEuiccSubscriptionSidecar.java b/src/com/android/settings/network/SwitchToEuiccSubscriptionSidecar.java index 8f6c32a976d..4a19e6287f6 100644 --- a/src/com/android/settings/network/SwitchToEuiccSubscriptionSidecar.java +++ b/src/com/android/settings/network/SwitchToEuiccSubscriptionSidecar.java @@ -143,12 +143,14 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar { return 0; } + Collection uiccSlotMappings = mTelephonyManager.getSimSlotMapping(); + Log.d(TAG, "The UiccSlotMapping: " + uiccSlotMappings); if (!mTelephonyManager.isMultiSimEnabled()) { // In the 'SS mode' // If there is the esim slot is active, the port is from the current esim slot. // If there is no esim slot in device, then the esim's port is 0. - Collection uiccSlotMappings = mTelephonyManager.getSimSlotMapping(); - Log.d(TAG, "In SS mode, the UiccSlotMapping: " + uiccSlotMappings); + Log.d(TAG, "In SS mode, to find the active esim slot's port." + + "If no active esim slot, the port is 0"); return uiccSlotMappings.stream() .filter(i -> i.getPhysicalSlotIndex() == physicalEsimSlotIndex) .mapToInt(i -> i.getPortIndex()) @@ -164,7 +166,8 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar { // In DSDS+MEP mode, the removedSubInfo is psim or is null, it means this esim needs // a new corresponding port in the esim slot. // For example: - // 1) If there is no enabled esim and the user add new esim. This new esim's port is 0. + // 1) If there is no enabled esim and the user add new esim. This new esim's port is + // active esim slot's port. // 2) If there is one enabled esim in port0 and the user add new esim. This new esim's // port is 1. // 3) If there is one enabled esim in port1 and the user add new esim. This new esim's @@ -180,6 +183,20 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar { .filter(i -> i.isEmbedded()) .sorted(Comparator.comparingInt(SubscriptionInfo::getPortIndex)) .collect(Collectors.toList()); + + // In DSDS+MEP mode, if there is the active esim slot and no active esim at that slot, + // then using this active esim slot's port. + // If there is no esim slot in device, then the esim's port is 0. + if (activeEsimSubInfos.isEmpty()) { + Log.d(TAG, "In DSDS+MEP mode, no active esim. return the active esim slot's port." + + "If no active esim slot, the port is 0"); + return uiccSlotMappings.stream() + .filter(i -> i.getPhysicalSlotIndex() == physicalEsimSlotIndex) + .mapToInt(i -> i.getPortIndex()) + .sorted() + .findFirst().orElse(0); + } + for (SubscriptionInfo subscriptionInfo : activeEsimSubInfos) { if (subscriptionInfo.getPortIndex() == port) { port++;