From 506c3df5b922db2d951043cfce1328bb1408a418 Mon Sep 17 00:00:00 2001 From: SongFerngWang Date: Fri, 11 Mar 2022 02:58:55 +0800 Subject: [PATCH] [MEP] sort the simSlotMapping by logcal slot id The modem assign the simSlotMapping like UiccSlotMapping[ (mPortIndex=0, mPhysicalSlotIndex=0, mLogicalSlotIndex=1), UiccSlotMapping (mPortIndex=1, mPhysicalSlotIndex=0, mLogicalSlotIndex=0)]. The settings replace the first one UiccSlotMapping when user insert psim and the both of esim profile are not enabled. It is not correct. The root cause is that the settings did not sort the simSlotMapping by logcal slot id. Bug: 223662007 Test: atest UiccSlotUtilTest (PASS) Change-Id: I6871db6c2d8d7b9f3cb334bb5cd2c7978b5b3b85 --- .../settings/network/UiccSlotUtil.java | 1 + .../settings/network/UiccSlotUtilTest.java | 54 +++++++++++++++++-- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/network/UiccSlotUtil.java b/src/com/android/settings/network/UiccSlotUtil.java index 9a157d6ea05..8fdc3700dd6 100644 --- a/src/com/android/settings/network/UiccSlotUtil.java +++ b/src/com/android/settings/network/UiccSlotUtil.java @@ -369,6 +369,7 @@ public class UiccSlotUtil { } return true; }) + .sorted(Comparator.comparingInt(UiccSlotMapping::getLogicalSlotIndex)) .mapToInt(uiccSlotMapping -> uiccSlotMapping.getLogicalSlotIndex()) .findFirst() .orElse(INVALID_LOGICAL_SLOT_ID); diff --git a/tests/unit/src/com/android/settings/network/UiccSlotUtilTest.java b/tests/unit/src/com/android/settings/network/UiccSlotUtilTest.java index cc9bdfc62e0..2cf984558be 100644 --- a/tests/unit/src/com/android/settings/network/UiccSlotUtilTest.java +++ b/tests/unit/src/com/android/settings/network/UiccSlotUtilTest.java @@ -454,7 +454,7 @@ public class UiccSlotUtilTest { @Test public void getExcludedLogicalSlotIndex_oneEsimAndFromDualPortsAToPsimAndPort0_logicalSlot1() { // There is only one enabled esimPort0 before user enables the psim. - Collection uiccSlotMappings = createUiccSlotMappingPsimAndPort1(); + Collection uiccSlotMappings = createUiccSlotMappingDualPortsA(); Collection activeSubscriptionInfoList = createActiveSubscriptionInfoListOneSim(0, 0); SubscriptionInfo removedSubInfo = null; @@ -469,7 +469,7 @@ public class UiccSlotUtilTest { @Test public void getExcludedLogicalSlotIndex_oneEsimAndFromDualPortsBToPsimAndPort1_logicalSlot1() { // There is only one enabled esimPort1 before user enables the psim. - Collection uiccSlotMappings = createUiccSlotMappingPsimAndPort1(); + Collection uiccSlotMappings = createUiccSlotMappingDualPortsB(); Collection activeSubscriptionInfoList = createActiveSubscriptionInfoListOneSim(0, 1); SubscriptionInfo removedSubInfo = null; @@ -484,7 +484,7 @@ public class UiccSlotUtilTest { @Test public void getExcludedLogicalSlotIndex_oneEsimAndFromDualPortsBToPsimAndPort0_logicalSlot0() { // There is only one enabled esimPort0 before user enables the psim. - Collection uiccSlotMappings = createUiccSlotMappingPsimAndPort1(); + Collection uiccSlotMappings = createUiccSlotMappingDualPortsB(); Collection activeSubscriptionInfoList = createActiveSubscriptionInfoListOneSim(1, 0); SubscriptionInfo removedSubInfo = null; @@ -552,6 +552,48 @@ public class UiccSlotUtilTest { assertThat(testExcludedLogicalSlotIndex).isEqualTo(verifyExcludedLogicalSlotIndex); } + @Test + public void getExcludedLogicalSlotIndex_noEsimAndFromDualPortsAToPsimAndPort1_logicalSlot0() { + // There is no profiles enabled on either esim port before user enables the psim. + Collection uiccSlotMappings = createUiccSlotMappingDualPortsA(); + Collection activeSubscriptionInfoList = new ArrayList<>(); + SubscriptionInfo removedSubInfo = null; + int verifyExcludedLogicalSlotIndex = 0; + + int testExcludedLogicalSlotIndex = UiccSlotUtil.getExcludedLogicalSlotIndex( + uiccSlotMappings, activeSubscriptionInfoList, removedSubInfo, true); + + assertThat(testExcludedLogicalSlotIndex).isEqualTo(verifyExcludedLogicalSlotIndex); + } + + @Test + public void getExcludedLogicalSlotIndex_noEsimAndFromDualPortsBToPsimAndPort0_logicalSlot0() { + // There is no profiles enabled on either esim port before user enables the psim. + Collection uiccSlotMappings = createUiccSlotMappingDualPortsB(); + Collection activeSubscriptionInfoList = new ArrayList<>(); + SubscriptionInfo removedSubInfo = null; + int verifyExcludedLogicalSlotIndex = 0; + + int testExcludedLogicalSlotIndex = UiccSlotUtil.getExcludedLogicalSlotIndex( + uiccSlotMappings, activeSubscriptionInfoList, removedSubInfo, true); + + assertThat(testExcludedLogicalSlotIndex).isEqualTo(verifyExcludedLogicalSlotIndex); + } + + @Test + public void getExcludedLogicalSlotIndex_noEsimNoOrdingFromDualPortsBToPsimAndPort1_logical0() { + // There is no profiles enabled on either esim port before user enables the psim. + Collection uiccSlotMappings = createUiccSlotMappingDualPortsBNoOrding(); + Collection activeSubscriptionInfoList = new ArrayList<>(); + SubscriptionInfo removedSubInfo = null; + int verifyExcludedLogicalSlotIndex = 0; + + int testExcludedLogicalSlotIndex = UiccSlotUtil.getExcludedLogicalSlotIndex( + uiccSlotMappings, activeSubscriptionInfoList, removedSubInfo, true); + + assertThat(testExcludedLogicalSlotIndex).isEqualTo(verifyExcludedLogicalSlotIndex); + } + private void compareTwoUiccSlotMappings(Collection testUiccSlotMappings, Collection verifyUiccSlotMappings) { assertThat(testUiccSlotMappings.size()).isEqualTo(verifyUiccSlotMappings.size()); @@ -656,7 +698,13 @@ public class UiccSlotUtilTest { return slotMap; } + private List createUiccSlotMappingDualPortsBNoOrding() { + List slotMap = new ArrayList<>(); + slotMap.add(new UiccSlotMapping(0, ESIM_PHYSICAL_SLOT, 1)); + slotMap.add(new UiccSlotMapping(1, ESIM_PHYSICAL_SLOT, 0)); + return slotMap; + } /** * The "oneSimSlotDevice" has below cases * 1) The device is one psim slot and no esim slot