Always show disabled pSIMs in single-sim mode

In single-sim mode, you can have both an eSIM subscription and a pSIM
inserted into the device, and only one of them can be enabled. It turns
out that if the pSIM is the disabled one, we would not show it in the
settings UI; this CL fixes that.

It also fixes a somewhat related problem that I noticed while testing
this, that if you have only one subscription that happens to be
disabled, we were not showing the on/off switch at the top of the page,
which would leave you with no way to enable it.

Bug: 129864878
Test: make RunSettingsRoboTests
Change-Id: I4214ad34c59ac2df429772c066c51a9318f5baa7
This commit is contained in:
Antony Sargent
2019-04-23 10:55:51 -07:00
parent f263f489e2
commit bdd9eb3ba7
9 changed files with 197 additions and 31 deletions

View File

@@ -16,8 +16,15 @@
package com.android.settings.network;
import static android.telephony.UiccSlotInfo.CARD_STATE_INFO_PRESENT;
import static com.android.internal.util.CollectionUtils.emptyIfNull;
import android.content.Context;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.UiccSlotInfo;
import android.text.TextUtils;
import androidx.annotation.VisibleForTesting;
@@ -27,6 +34,7 @@ import java.util.Iterator;
import java.util.List;
public class SubscriptionUtil {
private static final String TAG = "SubscriptionUtil";
private static List<SubscriptionInfo> sAvailableResultsForTesting;
private static List<SubscriptionInfo> sActiveResultsForTesting;
@@ -44,21 +52,56 @@ public class SubscriptionUtil {
if (sActiveResultsForTesting != null) {
return sActiveResultsForTesting;
}
List<SubscriptionInfo> subscriptions = manager.getActiveSubscriptionInfoList(true);
final List<SubscriptionInfo> subscriptions = manager.getActiveSubscriptionInfoList(true);
if (subscriptions == null) {
return new ArrayList<>();
}
return subscriptions;
}
public static List<SubscriptionInfo> getAvailableSubscriptions(SubscriptionManager manager) {
private static boolean isInactiveInsertedPSim(UiccSlotInfo slotInfo) {
return !slotInfo.getIsEuicc() && !slotInfo.getIsActive() &&
slotInfo.getCardStateInfo() == CARD_STATE_INFO_PRESENT;
}
public static List<SubscriptionInfo> getAvailableSubscriptions(Context context) {
if (sAvailableResultsForTesting != null) {
return sAvailableResultsForTesting;
}
List<SubscriptionInfo> subscriptions = manager.getSelectableSubscriptionInfoList();
if (subscriptions == null) {
subscriptions = new ArrayList<>();
final SubscriptionManager subMgr = context.getSystemService(SubscriptionManager.class);
final TelephonyManager telMgr = context.getSystemService(TelephonyManager.class);
List<SubscriptionInfo> subscriptions =
new ArrayList<>(emptyIfNull(subMgr.getSelectableSubscriptionInfoList()));
// Look for inactive but present physical SIMs that are missing from the selectable list.
final List<UiccSlotInfo> missing = new ArrayList<>();
UiccSlotInfo[] slotsInfo = telMgr.getUiccSlotsInfo();
for (int i = 0; slotsInfo != null && i < slotsInfo.length; i++) {
final UiccSlotInfo slotInfo = slotsInfo[i];
if (isInactiveInsertedPSim(slotInfo)) {
final int index = slotInfo.getLogicalSlotIdx();
final String cardId = slotInfo.getCardId();
final boolean found = subscriptions.stream().anyMatch(info ->
index == info.getSimSlotIndex() && cardId.equals(info.getCardString()));
if (!found) {
missing.add(slotInfo);
}
}
}
if (!missing.isEmpty()) {
for (SubscriptionInfo info : subMgr.getAllSubscriptionInfoList()) {
for (UiccSlotInfo slotInfo : missing) {
if (info.getSimSlotIndex() == slotInfo.getLogicalSlotIdx() &&
info.getCardString().equals(slotInfo.getCardId())) {
subscriptions.add(info);
break;
}
}
}
}
// 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.