Merge "Update dream summary when dream suppressed by bedtime mode" into tm-qpr-dev
diff --git a/src/com/android/settings/network/UiccSlotUtil.java b/src/com/android/settings/network/UiccSlotUtil.java
index 7d8295b..7b52680 100644
--- a/src/com/android/settings/network/UiccSlotUtil.java
+++ b/src/com/android/settings/network/UiccSlotUtil.java
@@ -28,7 +28,6 @@
import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.telephony.uicc.UiccController;
import com.android.settingslib.utils.ThreadUtils;
import com.google.common.collect.ImmutableList;
@@ -273,6 +272,7 @@
if (slotId == INVALID_PHYSICAL_SLOT_ID) {
for (int i = 0; i < slots.length; i++) {
if (slots[i].isRemovable()
+ && !slots[i].getIsEuicc()
&& !slots[i].getPorts().stream().findFirst().get().isActive()
&& slots[i].getCardStateInfo() != UiccSlotInfo.CARD_STATE_INFO_ERROR
&& slots[i].getCardStateInfo() != UiccSlotInfo.CARD_STATE_INFO_RESTRICTED) {
@@ -413,4 +413,29 @@
.findFirst()
.orElse(INVALID_LOGICAL_SLOT_ID);
}
+
+ /**
+ * Return whether the removable psim is enabled.
+ *
+ * @param telMgr is a TelephonyManager.
+ * @return whether the removable psim is enabled.
+ */
+ public static boolean isRemovableSimEnabled(TelephonyManager telMgr) {
+ if (telMgr == null) {
+ return false;
+ }
+ ImmutableList<UiccSlotInfo> slotInfos = UiccSlotUtil.getSlotInfos(telMgr);
+ boolean isRemovableSimEnabled =
+ slotInfos.stream()
+ .anyMatch(
+ slot -> slot != null
+ && slot.isRemovable()
+ && !slot.getIsEuicc()
+ && slot.getPorts().stream().anyMatch(
+ port -> port.isActive())
+ && slot.getCardStateInfo()
+ == UiccSlotInfo.CARD_STATE_INFO_PRESENT);
+ Log.i(TAG, "isRemovableSimEnabled: " + isRemovableSimEnabled);
+ return isRemovableSimEnabled;
+ }
}
diff --git a/src/com/android/settings/network/telephony/ToggleSubscriptionDialogActivity.java b/src/com/android/settings/network/telephony/ToggleSubscriptionDialogActivity.java
index a878cb3..6fa803d 100644
--- a/src/com/android/settings/network/telephony/ToggleSubscriptionDialogActivity.java
+++ b/src/com/android/settings/network/telephony/ToggleSubscriptionDialogActivity.java
@@ -24,7 +24,6 @@
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.UiccCardInfo;
-import android.telephony.UiccSlotInfo;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
@@ -39,8 +38,6 @@
import com.android.settings.network.UiccSlotUtil;
import com.android.settings.sim.SimActivationNotifier;
-import com.google.common.collect.ImmutableList;
-
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@@ -586,18 +583,7 @@
}
private boolean isRemovableSimEnabled() {
- ImmutableList<UiccSlotInfo> slotInfos = UiccSlotUtil.getSlotInfos(mTelMgr);
- boolean isRemovableSimEnabled =
- slotInfos.stream()
- .anyMatch(
- slot -> slot != null
- && slot.isRemovable()
- && slot.getPorts().stream().anyMatch(
- port -> port.isActive())
- && slot.getCardStateInfo()
- == UiccSlotInfo.CARD_STATE_INFO_PRESENT);
- Log.i(TAG, "isRemovableSimEnabled: " + isRemovableSimEnabled);
- return isRemovableSimEnabled;
+ return UiccSlotUtil.isRemovableSimEnabled(mTelMgr);
}
private boolean isMultipleEnabledProfilesSupported() {
diff --git a/tests/unit/src/com/android/settings/network/UiccSlotUtilTest.java b/tests/unit/src/com/android/settings/network/UiccSlotUtilTest.java
index 526fc0c..887f300 100644
--- a/tests/unit/src/com/android/settings/network/UiccSlotUtilTest.java
+++ b/tests/unit/src/com/android/settings/network/UiccSlotUtilTest.java
@@ -632,6 +632,106 @@
assertThat(testExcludedLogicalSlotIndex).isEqualTo(verifyExcludedLogicalSlotIndex);
}
+ @Test
+ public void isRemovableSimEnabled_noPsim_returnsFalse() {
+ when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
+ oneSimSlotDeviceActiveEsim());
+
+ boolean testSlot = UiccSlotUtil.isRemovableSimEnabled(mTelephonyManager);
+
+ assertThat(testSlot).isFalse();
+ }
+
+ @Test
+ public void isRemovableSimEnabled_activeRemovableEsimAndInactivePsim_returnsFalse() {
+ when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
+ twoSimSlotsDeviceActiveRemovableEsimInactivePsim());
+
+ boolean testSlot = UiccSlotUtil.isRemovableSimEnabled(mTelephonyManager);
+
+ assertThat(testSlot).isFalse();
+ }
+
+ @Test
+ public void isRemovableSimEnabled_activeRemovableEsimAndActivePsim_returnsTrue() {
+ when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
+ twoSimSlotsDeviceActivePsimActiveRemovableEsim());
+
+ boolean testSlot = UiccSlotUtil.isRemovableSimEnabled(mTelephonyManager);
+
+ assertThat(testSlot).isTrue();
+ }
+
+ @Test
+ public void isRemovableSimEnabled_inactiveRemovableEsimAndActivePsim_returnsTrue() {
+ when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
+ twoSimSlotsDeviceInactiveRemovableEsimActivePsim());
+
+ boolean testSlot = UiccSlotUtil.isRemovableSimEnabled(mTelephonyManager);
+
+ assertThat(testSlot).isTrue();
+ }
+
+ @Test
+ public void isRemovableSimEnabled_twoActiveRemovableEsimsAndInactivePsim_returnsFalse() {
+ when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
+ twoSimSlotsDeviceTwoActiveRemovableEsimsInactivePsim());
+
+ boolean testSlot = UiccSlotUtil.isRemovableSimEnabled(mTelephonyManager);
+
+ assertThat(testSlot).isFalse();
+ }
+
+ @Test
+ public void isRemovableSimEnabled_oneActiveOneInactiveRemovableEsimActivePsim_returnsTrue() {
+ when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
+ twoSimSlotsDeviceOneActiveOneInactiveRemovableEsimsActivePsim());
+
+ boolean testSlot = UiccSlotUtil.isRemovableSimEnabled(mTelephonyManager);
+
+ assertThat(testSlot).isTrue();
+ }
+
+ @Test
+ public void isRemovableSimEnabled_activePsim_returnsTrue() {
+ when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
+ oneSimSlotDeviceActivePsim());
+
+ boolean testSlot = UiccSlotUtil.isRemovableSimEnabled(mTelephonyManager);
+
+ assertThat(testSlot).isTrue();
+ }
+
+ @Test
+ public void isRemovableSimEnabled_inactivePsim_returnsFalse() {
+ when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
+ oneSimSlotDeviceinactivePsim());
+
+ boolean testSlot = UiccSlotUtil.isRemovableSimEnabled(mTelephonyManager);
+
+ assertThat(testSlot).isFalse();
+ }
+
+ @Test
+ public void isRemovableSimEnabled_activeEsimAndActivePsim_returnsTrue() {
+ when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
+ twoSimSlotsDeviceActivePsimActiveEsim());
+
+ boolean testSlot = UiccSlotUtil.isRemovableSimEnabled(mTelephonyManager);
+
+ assertThat(testSlot).isTrue();
+ }
+
+ @Test
+ public void isRemovableSimEnabled_activeEsimAndInactivePsim_returnsFalse() {
+ when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
+ twoSimSlotsDeviceInactivePsimActiveEsim());
+
+ boolean testSlot = UiccSlotUtil.isRemovableSimEnabled(mTelephonyManager);
+
+ assertThat(testSlot).isFalse();
+ }
+
private void compareTwoUiccSlotMappings(Collection<UiccSlotMapping> testUiccSlotMappings,
Collection<UiccSlotMapping> verifyUiccSlotMappings) {
assertThat(testUiccSlotMappings.size()).isEqualTo(verifyUiccSlotMappings.size());
@@ -786,6 +886,10 @@
return new UiccSlotInfo[]{createUiccSlotInfo(true, false, 1, true)};
}
+ private UiccSlotInfo[] oneSimSlotDeviceinactivePsim() {
+ return new UiccSlotInfo[]{createUiccSlotInfo(false, true, -1, false)};
+ }
+
private UiccSlotInfo[] twoSimSlotsDeviceActivePsimActiveEsim() {
return new UiccSlotInfo[]{
createUiccSlotInfo(false, true, 0, true),
@@ -804,6 +908,30 @@
createUiccSlotInfo(true, true, 1, true)};
}
+ private UiccSlotInfo[] twoSimSlotsDeviceActiveRemovableEsimInactivePsim() {
+ return new UiccSlotInfo[]{
+ createUiccSlotInfo(true, true, 0, true),
+ createUiccSlotInfo(false, true, -1, false)};
+ }
+
+ private UiccSlotInfo[] twoSimSlotsDeviceInactiveRemovableEsimActivePsim() {
+ return new UiccSlotInfo[]{
+ createUiccSlotInfo(true, true, -1, false),
+ createUiccSlotInfo(false, true, 0, true)};
+ }
+
+ private UiccSlotInfo[] twoSimSlotsDeviceTwoActiveRemovableEsimsInactivePsim() {
+ return new UiccSlotInfo[]{
+ createUiccSlotInfoForRemovableEsimMep(0, true, 1, true),
+ createUiccSlotInfo(false, true, -1, false)};
+ }
+
+ private UiccSlotInfo[] twoSimSlotsDeviceOneActiveOneInactiveRemovableEsimsActivePsim() {
+ return new UiccSlotInfo[]{
+ createUiccSlotInfoForRemovableEsimMep(1, true, -1, false),
+ createUiccSlotInfo(false, true, 0, true)};
+ }
+
private UiccSlotInfo[] twoSimSlotsDeviceActiveEsimActivePsim() {
return new UiccSlotInfo[]{
createUiccSlotInfo(true, false, 0, true),
@@ -866,4 +994,20 @@
logicalSlotIdx2 /* logicalSlotIdx */,
isActiveEsim2 /* isActive */)));
}
+
+ private UiccSlotInfo createUiccSlotInfoForRemovableEsimMep(int logicalSlotIdx1,
+ boolean isActiveEsim1, int logicalSlotIdx2, boolean isActiveEsim2) {
+ return new UiccSlotInfo(
+ true, /* isEuicc */
+ "123", /* cardId */
+ CARD_STATE_INFO_PRESENT, /* cardStateInfo */
+ true, /* isExtendApduSupported */
+ true, /* isRemovable */
+ Arrays.asList(
+ new UiccPortInfo("" /* iccId */, 0 /* portIdx */,
+ logicalSlotIdx1 /* logicalSlotIdx */, isActiveEsim1 /* isActive */),
+ new UiccPortInfo("" /* iccId */, 1 /* portIdx */,
+ logicalSlotIdx2 /* logicalSlotIdx */,
+ isActiveEsim2 /* isActive */)));
+ }
}