From 6f8cc6f0b6bf9d7469f44dfc6f08eddbde16b0b2 Mon Sep 17 00:00:00 2001 From: songferngwang Date: Tue, 14 May 2024 10:45:10 +0000 Subject: [PATCH] Fix search indexed the item from the invisible sim When search start to index and run to MobileNetworkSettings.java, the TelephonyBasePreferenceController will find which subId can be the "AVAILABLE" from the active subscriptionInfo list. This active subscriptionInfo list does not be filtered, so the search uses the invisibile sim's item for user. Bug: 335509130 Test: atest MobileNetworkUtilsTest (pass) Change-Id: I2840e7de344347643197592e125f5524d27a068e --- .../network/telephony/MobileNetworkUtils.java | 7 ++--- .../telephony/MobileNetworkUtilsTest.java | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/network/telephony/MobileNetworkUtils.java b/src/com/android/settings/network/telephony/MobileNetworkUtils.java index 603d915e98e..db95d701ce6 100644 --- a/src/com/android/settings/network/telephony/MobileNetworkUtils.java +++ b/src/com/android/settings/network/telephony/MobileNetworkUtils.java @@ -708,12 +708,13 @@ public class MobileNetworkUtils { return tm.getNetworkOperatorName(); } - private static int[] getActiveSubscriptionIdList(Context context) { + @VisibleForTesting + static int[] getActiveSubscriptionIdList(Context context) { final SubscriptionManager subscriptionManager = context.getSystemService( SubscriptionManager.class).createForAllUserProfiles(); final List subInfoList = - subscriptionManager.getActiveSubscriptionInfoList(); - if (subInfoList == null) { + SubscriptionUtil.getActiveSubscriptions(subscriptionManager); + if (subInfoList == null || subInfoList.isEmpty()) { return new int[0]; } int[] activeSubIds = new int[subInfoList.size()]; diff --git a/tests/unit/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java b/tests/unit/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java index 947ba75db66..570a3204b80 100644 --- a/tests/unit/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java +++ b/tests/unit/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java @@ -239,6 +239,33 @@ public class MobileNetworkUtilsTest { .isEqualTo(SubscriptionManager.INVALID_SUBSCRIPTION_ID); } + @Test + public void getActiveSubscriptionIdList_nonActive_returnEmptyArray() { + int[] expectedList = new int[0]; + when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(new ArrayList<>()); + + assertThat(MobileNetworkUtils.getActiveSubscriptionIdList(mContext)) + .isEqualTo(expectedList); + } + + @Test + public void getActiveSubscriptionIdList_normalCaseTwoActiveSims_returnValidSubId() { + int[] expectedList = {SUB_ID_1, SUB_ID_2}; + + assertThat(MobileNetworkUtils.getActiveSubscriptionIdList(mContext)) + .isEqualTo(expectedList); + } + + @Test + public void getActiveSubscriptionIdList_TwoActiveSimsAndOneIsNtn_returnOneSubId() { + int[] expectedList = {SUB_ID_2}; + when(mSubscriptionInfo1.isEmbedded()).thenReturn(true); + when(mSubscriptionInfo1.isOnlyNonTerrestrialNetwork()).thenReturn(true); + + assertThat(MobileNetworkUtils.getActiveSubscriptionIdList(mContext)) + .isEqualTo(expectedList); + } + @Test public void shouldDisplayNetworkSelectOptions_HideCarrierNetwork_returnFalse() { mCarrierConfig.putBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL,