Files
packages_apps_Settings/src/com/android/settings/network/SubscriptionUtil.java
Antony Sargent 4646fe8e63 Use active instead of available subscriptions in 2 places
In a couple of places we were showing DSDS UI using the list of
*available* subscriptions instead of the list of *active* ones. This
difference is relevant for instance if you have multiple eSIM profiles -
in typical hardware only one of those can be active at one time. This CL
fixes that problem in two places:

1) The header at the top of the Network & internet page

2) The ListPreference's on the mobile network detail page for selecting
   the default subscription for Calls / SMS.

Fixes: 129673046
Test: make RunSettingsRoboTests
Change-Id: I891c856bdd4516286fcee1067684d9161ceaca80
2019-04-08 16:22:55 -07:00

74 lines
2.7 KiB
Java

/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.network;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.text.TextUtils;
import androidx.annotation.VisibleForTesting;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class SubscriptionUtil {
private static List<SubscriptionInfo> sAvailableResultsForTesting;
private static List<SubscriptionInfo> sActiveResultsForTesting;
@VisibleForTesting
public static void setAvailableSubscriptionsForTesting(List<SubscriptionInfo> results) {
sAvailableResultsForTesting = results;
}
@VisibleForTesting
public static void setActiveSubscriptionsForTesting(List<SubscriptionInfo> results) {
sActiveResultsForTesting = results;
}
public static List<SubscriptionInfo> getActiveSubscriptions(SubscriptionManager manager) {
if (sActiveResultsForTesting != null) {
return sActiveResultsForTesting;
}
List<SubscriptionInfo> subscriptions = manager.getActiveSubscriptionInfoList(true);
if (subscriptions == null) {
return new ArrayList<>();
}
return subscriptions;
}
public static List<SubscriptionInfo> getAvailableSubscriptions(SubscriptionManager manager) {
if (sAvailableResultsForTesting != null) {
return sAvailableResultsForTesting;
}
List<SubscriptionInfo> subscriptions = manager.getSelectableSubscriptionInfoList();
if (subscriptions == null) {
subscriptions = new ArrayList<>();
}
// With some carriers such as Google Fi which provide a sort of virtual service that spans
// across multiple underlying networks, we end up with subscription entries for the
// underlying networks that need to be hidden from the user in the UI.
for (Iterator<SubscriptionInfo> iter = subscriptions.iterator(); iter.hasNext(); ) {
SubscriptionInfo info = iter.next();
if (TextUtils.isEmpty(info.getMncString())) {
iter.remove();
}
}
return subscriptions;
}
}