From b82864c801609053ec86f3ffcaa6d406aef02acb Mon Sep 17 00:00:00 2001 From: Malcolm Chen Date: Tue, 26 Feb 2019 16:48:40 -0800 Subject: [PATCH] Only return one mobile subscription per group in Settings. Right now getSelectableSubscriptionInfoList returns all subscriptions that are visible and available. But we should only show one per subscription group. So updating getSelectableSubscriptionInfoList to make sure of it. Bug: 126438122 Test: manual - group Fi primary subscriptions and make sure only one Fi subscription is shown in Settings UI. Change-Id: I867296b4f8efbdf2e9885ef34dd45806fa0abbca Merged-In: I867296b4f8efbdf2e9885ef34dd45806fa0abbca --- .../telephony/SubscriptionManager.java | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index 1301246f8574b..1662d6e33cf70 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -69,8 +69,10 @@ import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; @@ -2908,8 +2910,33 @@ public class SubscriptionManager { if (availableList == null) { return null; } else { - return availableList.stream().filter(subInfo -> !shouldHideSubscription(subInfo)) - .collect(Collectors.toList()); + // Multiple subscriptions in a group should only have one representative. + // It should be the current active primary subscription if any, or any + // primary subscription. + List selectableList = new ArrayList<>(); + Map groupMap = new HashMap<>(); + + for (SubscriptionInfo info : availableList) { + // Opportunistic subscriptions are considered invisible + // to users so they should never be returned. + if (isInvisibleSubscription(info)) continue; + + String groupUuid = info.getGroupUuid(); + if (groupUuid == null) { + // Doesn't belong to any group. Add in the list. + selectableList.add(info); + } else if (!groupMap.containsKey(groupUuid) + || (groupMap.get(groupUuid).getSimSlotIndex() == INVALID_SIM_SLOT_INDEX + && info.getSimSlotIndex() != INVALID_SIM_SLOT_INDEX)) { + // If it belongs to a group that has never been recorded or it's the current + // active subscription, add it in the list. + selectableList.remove(groupMap.get(groupUuid)); + selectableList.add(info); + groupMap.put(groupUuid, info); + } + + } + return selectableList; } }