Files
app_Settings/src/com/android/settings/network/helper/QuerySimSlotIndex.java
Bonian Chen a239a6c53a [Settings] Hide subscriptions not existed within device
For non-active subscriptions, the one inserted in slot
but turned off need to be visible to the user. However,
the one un-plugged need to be invisble.

Since SubscriptionUtil#getSelectableSubscriptionInfoList() didn't cover all the cases required. Create this one to fit into the criteria required here.

Note: subscriptions with same group UUID will be displayed seperately.

Bug: 191228344
Test: local
Change-Id: Ia68c23b007164b7520456cb6c7427ca142558b59
(cherry picked from commit 75f1450bbf)
(cherry picked from commit 0726f263a8)
2021-07-12 17:32:59 +08:00

87 lines
3.1 KiB
Java

/*
* Copyright (C) 2021 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.helper;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.UiccSlotInfo;
import java.util.Arrays;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicIntegerArray;
/**
* This is a Callable class which query slot index within device
*/
public class QuerySimSlotIndex implements Callable<AtomicIntegerArray> {
private static final String TAG = "QuerySimSlotIndex";
private TelephonyManager mTelephonyManager;
private boolean mDisabledSlotsIncluded;
private boolean mOnlySlotWithSim;
/**
* Constructor of class
* @param TelephonyManager
* @param disabledSlotsIncluded query both active and inactive slots when true,
* only query active slot when false.
* @param onlySlotWithSim query slot index with SIM available when true,
* include absent ones when false.
*/
public QuerySimSlotIndex(TelephonyManager telephonyManager,
boolean disabledSlotsIncluded, boolean onlySlotWithSim) {
mTelephonyManager = telephonyManager;
mDisabledSlotsIncluded = disabledSlotsIncluded;
mOnlySlotWithSim = onlySlotWithSim;
}
/**
* Implementation of Callable
* @return slot index in AtomicIntegerArray
*/
public AtomicIntegerArray call() {
UiccSlotInfo [] slotInfo = mTelephonyManager.getUiccSlotsInfo();
if (slotInfo == null) {
return new AtomicIntegerArray(0);
}
int slotIndexFilter = mOnlySlotWithSim ? 0 : SubscriptionManager.INVALID_SIM_SLOT_INDEX;
return new AtomicIntegerArray(Arrays.stream(slotInfo)
.filter(slot -> filterSlot(slot))
.mapToInt(slot -> mapToSlotIndex(slot))
.filter(slotIndex -> (slotIndex >= slotIndexFilter))
.toArray());
}
protected boolean filterSlot(UiccSlotInfo slotInfo) {
if (mDisabledSlotsIncluded) {
return true;
}
if (slotInfo == null) {
return false;
}
return slotInfo.getIsActive();
}
protected int mapToSlotIndex(UiccSlotInfo slotInfo) {
if (slotInfo == null) {
return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
}
if (slotInfo.getCardStateInfo() == UiccSlotInfo.CARD_STATE_INFO_ABSENT) {
return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
}
return slotInfo.getLogicalSlotIdx();
}
}