Merge "Create UiccSlotRepository" into main

This commit is contained in:
Chaohui Wang
2024-08-19 05:17:04 +00:00
committed by Android (Google) Code Review
11 changed files with 328 additions and 315 deletions

View File

@@ -24,10 +24,10 @@ import android.telephony.SubscriptionInfo
import android.telephony.SubscriptionManager
import android.telephony.TelephonyManager
import android.telephony.UiccCardInfo
import android.telephony.UiccSlotInfo
import android.util.Log
import com.android.settings.network.SimOnboardingActivity.Companion.CallbackType
import com.android.settings.network.telephony.MobileDataRepository
import com.android.settings.network.telephony.UiccSlotRepository
import com.android.settings.sim.SimActivationNotifier
import com.android.settings.spa.network.setDefaultData
import com.android.settings.spa.network.setDefaultSms
@@ -46,7 +46,6 @@ class SimOnboardingService {
var targetSubInfo: SubscriptionInfo? = null
var availableSubInfoList: List<SubscriptionInfo> = listOf()
var activeSubInfoList: List<SubscriptionInfo> = listOf()
var slotInfoList: List<UiccSlotInfo> = listOf()
var uiccCardInfoList: List<UiccCardInfo> = listOf()
var targetPrimarySimCalls: Int = INVALID_SUBSCRIPTION_ID
var targetPrimarySimTexts: Int = INVALID_SUBSCRIPTION_ID
@@ -73,14 +72,6 @@ class SimOnboardingService {
}
return uiccCardInfoList.any { it.isMultipleEnabledProfilesSupported }
}
var isRemovablePsimProfileEnabled: Boolean = false
get() {
if(slotInfoList.isEmpty()) {
Log.w(TAG, "UICC Slot info list is empty.")
return false
}
return UiccSlotUtil.isRemovableSimEnabled(slotInfoList)
}
var isEsimProfileEnabled: Boolean = false
get() {
activeSubInfoList.stream().anyMatch { it.isEmbedded }
@@ -137,19 +128,11 @@ class SimOnboardingService {
return telephonyManager?.doesSwitchMultiSimConfigTriggerReboot() ?: false
}
fun isValid(): Boolean {
return targetSubId != INVALID_SUBSCRIPTION_ID
&& targetSubInfo != null
&& activeSubInfoList.isNotEmpty()
&& slotInfoList.isNotEmpty()
}
fun clear() {
targetSubId = -1
targetSubInfo = null
availableSubInfoList = listOf()
activeSubInfoList = listOf()
slotInfoList = listOf()
uiccCardInfoList = listOf()
targetPrimarySimCalls = -1
targetPrimarySimTexts = -1
@@ -181,8 +164,6 @@ class SimOnboardingService {
availableSubInfoList.find { subInfo -> subInfo.subscriptionId == targetSubId }
targetSubInfo?.let { userSelectedSubInfoList.add(it) }
Log.d(TAG, "targetSubId: $targetSubId , targetSubInfo: $targetSubInfo")
slotInfoList = telephonyManager?.uiccSlotsInfo?.toList() ?: listOf()
Log.d(TAG, "slotInfoList: $slotInfoList.")
uiccCardInfoList = telephonyManager?.uiccCardsInfo!!
Log.d(TAG, "uiccCardInfoList: $uiccCardInfoList")
@@ -192,7 +173,6 @@ class SimOnboardingService {
Log.d(
TAG,"doesTargetSimHaveEsimOperation: $doesTargetSimHaveEsimOperation" +
", isRemovableSimEnabled: $isRemovablePsimProfileEnabled" +
", isMultipleEnabledProfilesSupported: $isMultipleEnabledProfilesSupported" +
", targetPrimarySimCalls: $targetPrimarySimCalls" +
", targetPrimarySimTexts: $targetPrimarySimTexts" +
@@ -317,14 +297,15 @@ class SimOnboardingService {
return true
}
if (doesTargetSimHaveEsimOperation && isRemovablePsimProfileEnabled) {
Log.d(TAG,
if (doesTargetSimHaveEsimOperation) {
if (UiccSlotRepository(telephonyManager).anyRemovablePhysicalSimEnabled()) {
Log.d(
TAG,
"eSIM operation and removable PSIM is enabled. DSDS condition satisfied."
)
return true
}
if (!doesTargetSimHaveEsimOperation && isEsimProfileEnabled) {
} else if (isEsimProfileEnabled) {
Log.d(TAG,
"Removable SIM operation and eSIM profile is enabled. DSDS condition"
+ " satisfied."

View File

@@ -30,8 +30,6 @@ import android.util.Log;
import com.android.settings.SidecarFragment;
import com.android.settings.network.telephony.EuiccOperationSidecar;
import com.google.common.collect.ImmutableList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
@@ -205,10 +203,10 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
}
private int getLogicalSlotIndex(int physicalSlotIndex, int portIndex) {
ImmutableList<UiccSlotInfo> slotInfos = UiccSlotUtil.getSlotInfos(mTelephonyManager);
if (slotInfos != null && physicalSlotIndex >= 0 && physicalSlotIndex < slotInfos.size()
&& slotInfos.get(physicalSlotIndex) != null) {
for (UiccPortInfo portInfo : slotInfos.get(physicalSlotIndex).getPorts()) {
UiccSlotInfo[] slotInfos = mTelephonyManager.getUiccSlotsInfo();
if (slotInfos != null && physicalSlotIndex >= 0 && physicalSlotIndex < slotInfos.length
&& slotInfos[physicalSlotIndex] != null) {
for (UiccPortInfo portInfo : slotInfos[physicalSlotIndex].getPorts()) {
if (portInfo.getPortIndex() == portIndex) {
return portInfo.getLogicalSlotIndex();
}

View File

@@ -33,8 +33,6 @@ import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settingslib.utils.ThreadUtils;
import com.google.common.collect.ImmutableList;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
@@ -105,18 +103,6 @@ public class UiccSlotUtil {
int SYNC_CLEANUP = 2;
}
/**
* Returns an immutable list of all UICC slots. If TelephonyManager#getUiccSlotsInfo returns, it
* returns an empty list instead.
*/
public static ImmutableList<UiccSlotInfo> getSlotInfos(TelephonyManager telMgr) {
UiccSlotInfo[] slotInfos = telMgr.getUiccSlotsInfo();
if (slotInfos == null) {
return ImmutableList.of();
}
return ImmutableList.copyOf(slotInfos);
}
/**
* Switches to the removable slot. It waits for SIM_STATE_LOADED after switch. If slotId is
* INVALID_PHYSICAL_SLOT_ID, the method will use the first detected inactive removable slot.
@@ -219,14 +205,13 @@ public class UiccSlotUtil {
*/
public static int getEsimSlotId(Context context, int subId) {
TelephonyManager telMgr = context.getSystemService(TelephonyManager.class);
List<UiccCardInfo> uiccCardInfos = telMgr.getUiccCardsInfo();
ImmutableList<UiccSlotInfo> slotInfos = UiccSlotUtil.getSlotInfos(telMgr);
SubscriptionManager subscriptionManager = context.getSystemService(
SubscriptionManager.class).createForAllUserProfiles();
SubscriptionInfo subInfo = SubscriptionUtil.getSubById(subscriptionManager, subId);
// checking whether this is the removable esim. If it is, then return the removable slot id.
if (subInfo != null && subInfo.isEmbedded()) {
List<UiccCardInfo> uiccCardInfos = telMgr.getUiccCardsInfo();
for (UiccCardInfo uiccCardInfo : uiccCardInfos) {
if (uiccCardInfo.getCardId() == subInfo.getCardId()
&& uiccCardInfo.getCardId() > TelephonyManager.UNSUPPORTED_CARD_ID
@@ -238,10 +223,12 @@ public class UiccSlotUtil {
}
}
int firstEsimSlot = IntStream.range(0, slotInfos.size())
UiccSlotInfo[] slotInfos = telMgr.getUiccSlotsInfo();
if (slotInfos == null) return -1;
int firstEsimSlot = IntStream.range(0, slotInfos.length)
.filter(
index -> {
UiccSlotInfo slotInfo = slotInfos.get(index);
UiccSlotInfo slotInfo = slotInfos[index];
if (slotInfo == null) {
return false;
}
@@ -421,41 +408,6 @@ public class UiccSlotUtil {
.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;
}
List<UiccSlotInfo> slotInfos = UiccSlotUtil.getSlotInfos(telMgr);
return isRemovableSimEnabled(slotInfos);
}
/**
* Return whether the removable psim is enabled.
*
* @param slotInfos is a List of UiccSlotInfo.
* @return whether the removable psim is enabled.
*/
public static boolean isRemovableSimEnabled(List<UiccSlotInfo> slotInfos) {
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;
}
private static boolean isMultipleEnabledProfilesSupported(TelephonyManager telMgr) {
List<UiccCardInfo> cardInfos = telMgr.getUiccCardsInfo();
if (cardInfos == null) {

View File

@@ -583,7 +583,7 @@ public class ToggleSubscriptionDialogActivity extends SubscriptionActionDialogAc
}
private boolean isRemovableSimEnabled() {
return UiccSlotUtil.isRemovableSimEnabled(mTelMgr);
return new UiccSlotRepository(mTelMgr).anyRemovablePhysicalSimEnabled();
}
private boolean isMultipleEnabledProfilesSupported() {

View File

@@ -0,0 +1,46 @@
/*
* Copyright (C) 2024 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.telephony
import android.telephony.TelephonyManager
import android.telephony.UiccSlotInfo
import android.util.Log
class UiccSlotRepository(private val telephonyManager: TelephonyManager?) {
/** Returns whether any removable physical sim is enabled. */
fun anyRemovablePhysicalSimEnabled(): Boolean {
val result =
telephonyManager?.uiccSlotsInfo?.any { uiccSlotInfo: UiccSlotInfo? ->
uiccSlotInfo.isRemovablePhysicalSimEnabled()
} ?: false
Log.i(TAG, "anyRemovablePhysicalSimEnabled: $result")
return result
}
private fun UiccSlotInfo?.isRemovablePhysicalSimEnabled(): Boolean {
return this != null &&
isRemovable &&
!isEuicc &&
ports.any { port -> port.isActive } &&
cardStateInfo == UiccSlotInfo.CARD_STATE_INFO_PRESENT
}
companion object {
private const val TAG = "UiccRepository"
}
}

View File

@@ -0,0 +1,262 @@
/*
* Copyright (C) 2024 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.telephony
import android.telephony.TelephonyManager
import android.telephony.UiccPortInfo
import android.telephony.UiccSlotInfo
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.mockito.kotlin.stub
@RunWith(AndroidJUnit4::class)
class UiccSlotRepositoryTest {
private val mockTelephonyManager = mock<TelephonyManager>()
private val repository = UiccSlotRepository(mockTelephonyManager)
@Test
fun anyRemovablePhysicalSimEnabled_oneSimSlotDeviceActiveEsim_returnsFalse() {
mockTelephonyManager.stub {
on { uiccSlotsInfo } doReturn
arrayOf(
createUiccSlotInfo(
isEuicc = true, isRemovable = false, logicalSlotIdx = 1, isActive = true),
)
}
val result = repository.anyRemovablePhysicalSimEnabled()
assertThat(result).isFalse()
}
@Test
fun anyRemovablePhysicalSimEnabled_activeRemovableEsimAndInactivePsim_returnsFalse() {
mockTelephonyManager.stub {
on { uiccSlotsInfo } doReturn
arrayOf(
createUiccSlotInfo(
isEuicc = true, isRemovable = true, logicalSlotIdx = 0, isActive = true),
createUiccSlotInfo(
isEuicc = false, isRemovable = true, logicalSlotIdx = -1, isActive = false),
)
}
val result = repository.anyRemovablePhysicalSimEnabled()
assertThat(result).isFalse()
}
@Test
fun anyRemovablePhysicalSimEnabled_activeRemovableEsimAndActivePsim_returnsTrue() {
mockTelephonyManager.stub {
on { uiccSlotsInfo } doReturn
arrayOf(
createUiccSlotInfo(
isEuicc = false, isRemovable = true, logicalSlotIdx = 0, isActive = true),
createUiccSlotInfo(
isEuicc = true, isRemovable = true, logicalSlotIdx = 1, isActive = true),
)
}
val result = repository.anyRemovablePhysicalSimEnabled()
assertThat(result).isTrue()
}
@Test
fun anyRemovablePhysicalSimEnabled_inactiveRemovableEsimAndActivePsim_returnsTrue() {
mockTelephonyManager.stub {
on { uiccSlotsInfo } doReturn
arrayOf(
createUiccSlotInfo(
isEuicc = true, isRemovable = true, logicalSlotIdx = -1, isActive = false),
createUiccSlotInfo(
isEuicc = false, isRemovable = true, logicalSlotIdx = 0, isActive = true),
)
}
val result = repository.anyRemovablePhysicalSimEnabled()
assertThat(result).isTrue()
}
@Test
fun anyRemovablePhysicalSimEnabled_twoActiveRemovableEsimsAndInactivePsim_returnsFalse() {
mockTelephonyManager.stub {
on { uiccSlotsInfo } doReturn
arrayOf(
createUiccSlotInfoForRemovableEsimMep(
logicalSlotIdx1 = 0,
isActiveEsim1 = true,
logicalSlotIdx2 = 1,
isActiveEsim2 = true,
),
createUiccSlotInfo(
isEuicc = false, isRemovable = true, logicalSlotIdx = -1, isActive = false),
)
}
val result = repository.anyRemovablePhysicalSimEnabled()
assertThat(result).isFalse()
}
@Test
fun anyRemovablePhysicalSimEnabled_oneActiveOneInactiveRemovableEsimActivePsim_returnsTrue() {
mockTelephonyManager.stub {
on { uiccSlotsInfo } doReturn
arrayOf(
createUiccSlotInfoForRemovableEsimMep(
logicalSlotIdx1 = 1,
isActiveEsim1 = true,
logicalSlotIdx2 = -1,
isActiveEsim2 = false,
),
createUiccSlotInfo(
isEuicc = false, isRemovable = true, logicalSlotIdx = 0, isActive = true),
)
}
val result = repository.anyRemovablePhysicalSimEnabled()
assertThat(result).isTrue()
}
@Test
fun anyRemovablePhysicalSimEnabled_activePsim_returnsTrue() {
mockTelephonyManager.stub {
on { uiccSlotsInfo } doReturn
arrayOf(
createUiccSlotInfo(
isEuicc = false, isRemovable = true, logicalSlotIdx = 0, isActive = true),
)
}
val result = repository.anyRemovablePhysicalSimEnabled()
assertThat(result).isTrue()
}
@Test
fun anyRemovablePhysicalSimEnabled_inactivePsim_returnsFalse() {
mockTelephonyManager.stub {
on { uiccSlotsInfo } doReturn
arrayOf(
createUiccSlotInfo(
isEuicc = false, isRemovable = true, logicalSlotIdx = -1, isActive = false),
)
}
val result = repository.anyRemovablePhysicalSimEnabled()
assertThat(result).isFalse()
}
@Test
fun anyRemovablePhysicalSimEnabled_activeEsimAndActivePsim_returnsTrue() {
mockTelephonyManager.stub {
on { uiccSlotsInfo } doReturn
arrayOf(
createUiccSlotInfo(
isEuicc = false, isRemovable = true, logicalSlotIdx = 0, isActive = true),
createUiccSlotInfo(
isEuicc = true, isRemovable = false, logicalSlotIdx = 1, isActive = true),
)
}
val result = repository.anyRemovablePhysicalSimEnabled()
assertThat(result).isTrue()
}
@Test
fun anyRemovablePhysicalSimEnabled_activeEsimAndInactivePsim_returnsFalse() {
mockTelephonyManager.stub {
on { uiccSlotsInfo } doReturn
arrayOf(
createUiccSlotInfo(
isEuicc = false, isRemovable = true, logicalSlotIdx = 0, isActive = false),
createUiccSlotInfo(
isEuicc = true, isRemovable = false, logicalSlotIdx = 1, isActive = true),
)
}
val result = repository.anyRemovablePhysicalSimEnabled()
assertThat(result).isFalse()
}
@Test
fun anyRemovablePhysicalSimEnabled_uiccSlotInfoIsNull_returnsFalse() {
mockTelephonyManager.stub { on { uiccSlotsInfo } doReturn arrayOf(null) }
val result = repository.anyRemovablePhysicalSimEnabled()
assertThat(result).isFalse()
}
private companion object {
fun createUiccSlotInfo(
isEuicc: Boolean,
isRemovable: Boolean,
logicalSlotIdx: Int,
isActive: Boolean
) =
UiccSlotInfo(
isEuicc,
/* cardId = */ "123",
/* cardStateInfo = */ UiccSlotInfo.CARD_STATE_INFO_PRESENT,
/* isExtendedApduSupported = */ true,
isRemovable,
/* portList = */ listOf(
UiccPortInfo(/* iccId= */ "", /* portIndex= */ 0, logicalSlotIdx, isActive),
),
)
fun createUiccSlotInfoForRemovableEsimMep(
logicalSlotIdx1: Int,
isActiveEsim1: Boolean,
logicalSlotIdx2: Int,
isActiveEsim2: Boolean,
) =
UiccSlotInfo(
/* isEuicc = */ true,
/* cardId = */ "123",
/* cardStateInfo = */ UiccSlotInfo.CARD_STATE_INFO_PRESENT,
/* isExtendedApduSupported = */ true,
/* isRemovable = */ true,
/* portList = */ listOf(
UiccPortInfo(
/* iccId = */ "",
/* portIndex = */ 0,
/* logicalSlotIndex = */ logicalSlotIdx1,
/* isActive = */ isActiveEsim1),
UiccPortInfo(
/* iccId = */ "",
/* portIndex = */ 1,
/* logicalSlotIndex = */ logicalSlotIdx2,
/* isActive = */ isActiveEsim2),
),
)
}
}

View File

@@ -19,23 +19,17 @@ package com.android.settings.spa.network
import android.content.Context
import android.telephony.SubscriptionInfo
import android.telephony.SubscriptionManager
import android.view.KeyEvent.ACTION_DOWN
import android.view.KeyEvent.KEYCODE_FORWARD_DEL
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.input.key.KeyEvent
import androidx.compose.ui.input.key.NativeKeyEvent
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.semantics.SemanticsProperties
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsEnabled
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performKeyPress
import androidx.compose.ui.test.performTextClearance
import androidx.compose.ui.test.performTextInput
import androidx.lifecycle.testing.TestLifecycleOwner
@@ -80,7 +74,6 @@ class SimOnboardingLabelSimTest {
on { targetSubInfo }.doReturn(null)
on { availableSubInfoList }.doReturn(listOf())
on { activeSubInfoList }.doReturn(listOf())
on { slotInfoList }.doReturn(listOf())
on { uiccCardInfoList }.doReturn(listOf())
on { targetPrimarySimCalls }.doReturn(PRIMARY_SIM_ASK_EVERY_TIME)

View File

@@ -45,7 +45,6 @@ class SimOnboardingPageProviderTest {
on { targetSubInfo }.doReturn(null)
on { availableSubInfoList }.doReturn(listOf())
on { activeSubInfoList }.doReturn(listOf())
on { slotInfoList }.doReturn(listOf())
on { uiccCardInfoList }.doReturn(listOf())
on { targetPrimarySimCalls }.doReturn(PRIMARY_SIM_ASK_EVERY_TIME)

View File

@@ -46,7 +46,6 @@ class SimOnboardingPrimarySimTest {
on { targetSubInfo }.doReturn(null)
on { availableSubInfoList }.doReturn(listOf())
on { activeSubInfoList }.doReturn(listOf())
on { slotInfoList }.doReturn(listOf())
on { uiccCardInfoList }.doReturn(listOf())
on { targetPrimarySimCalls }.doReturn(PRIMARY_SIM_ASK_EVERY_TIME)

View File

@@ -69,7 +69,6 @@ class SimOnboardingSelectSimTest {
on { targetSubInfo }.doReturn(null)
on { availableSubInfoList }.doReturn(listOf())
on { activeSubInfoList }.doReturn(listOf())
on { slotInfoList }.doReturn(listOf())
on { uiccCardInfoList }.doReturn(listOf())
on { targetPrimarySimCalls }.doReturn(PRIMARY_SIM_ASK_EVERY_TIME)

View File

@@ -38,8 +38,6 @@ import android.telephony.UiccSlotMapping;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.common.collect.ImmutableList;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -47,7 +45,6 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
@@ -81,25 +78,6 @@ public class UiccSlotUtilTest {
when(mSubscriptionManager.getAllSubscriptionInfoList()).thenReturn(mSubscriptionInfoList);
}
@Test
public void getSlotInfos_oneSimSlotDevice_returnTheCorrectSlotInfoList() {
when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(oneSimSlotDeviceActivePsim());
ImmutableList<UiccSlotInfo> testUiccSlotInfos =
UiccSlotUtil.getSlotInfos(mTelephonyManager);
assertThat(testUiccSlotInfos.size()).isEqualTo(1);
}
@Test
public void getSlotInfos_twoSimSlotsDevice_returnTheCorrectSlotInfoList() {
when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
twoSimSlotsDeviceActivePsimActiveEsim());
ImmutableList<UiccSlotInfo> testUiccSlotInfos =
UiccSlotUtil.getSlotInfos(mTelephonyManager);
assertThat(testUiccSlotInfos.size()).isEqualTo(2);
}
@Test
public void getEsimSlotId_twoSimSlotsDeviceAndEsimIsSlot0_returnTheCorrectEsimSlot() {
when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
@@ -643,105 +621,7 @@ public class UiccSlotUtilTest {
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();
}
@Test
public void performSwitchToSlot_setSimSlotMapping() throws UiccSlotsException {
@@ -856,13 +736,6 @@ public class UiccSlotUtilTest {
return slotMap;
}
private List<UiccSlotMapping> createUiccSlotMappingSsModeEsimPort1Active() {
List<UiccSlotMapping> slotMap = new ArrayList<>();
slotMap.add(new UiccSlotMapping(1, ESIM_PHYSICAL_SLOT, 0));
return slotMap;
}
private List<UiccSlotMapping> createUiccSlotMappingPsimAndPort0() {
List<UiccSlotMapping> slotMap = new ArrayList<>();
slotMap.add(new UiccSlotMapping(0, PSIM_PHYSICAL_SLOT, 0));
@@ -915,14 +788,6 @@ public class UiccSlotUtilTest {
return new UiccSlotInfo[]{createUiccSlotInfo(false, true, 0, true)};
}
private UiccSlotInfo[] oneSimSlotDeviceActiveEsim() {
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),
@@ -941,61 +806,12 @@ public class UiccSlotUtilTest {
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),
createUiccSlotInfo(false, true, 1, true)};
}
private UiccSlotInfo[] twoSimSlotsDeviceTwoActiveEsims() {
// device supports MEP, so device can enable two esims.
// If device has psim slot, the UiccSlotInfo of psim always be in UiccSlotInfo[].
return new UiccSlotInfo[]{
createUiccSlotInfo(false, true, -1, true),
createUiccSlotInfoForEsimMep(0, true, 1, true)};
}
private UiccSlotInfo[] twoSimSlotsDeviceActivePsimInactiveEsim() {
return new UiccSlotInfo[]{
createUiccSlotInfo(false, true, 0, true),
createUiccSlotInfo(true, false, -1, false)};
}
private UiccSlotInfo[] twoSimSlotsDeviceInactivePsimActiveEsim() {
return new UiccSlotInfo[]{
createUiccSlotInfo(false, true, 0, false),
createUiccSlotInfo(true, false, 1, true)};
}
private UiccSlotInfo[] twoSimSlotsDeviceNoInsertPsimActiveEsim() {
return new UiccSlotInfo[]{
createUiccSlotInfo(false, true, -1, false),
createUiccSlotInfo(true, false, 1, true)};
}
//ToDo: add more cases.
private UiccSlotInfo createUiccSlotInfo(boolean isEuicc, boolean isRemovable,
@@ -1011,36 +827,4 @@ public class UiccSlotUtilTest {
logicalSlotIdx /* logicalSlotIdx */, isActive /* isActive */))
);
}
private UiccSlotInfo createUiccSlotInfoForEsimMep(int logicalSlotIdx1, boolean isActiveEsim1,
int logicalSlotIdx2, boolean isActiveEsim2) {
return new UiccSlotInfo(
true, /* isEuicc */
"123", /* cardId */
CARD_STATE_INFO_PRESENT, /* cardStateInfo */
true, /* isExtendApduSupported */
false, /* isRemovable */
Arrays.asList(
new UiccPortInfo("" /* iccId */, 0 /* portIdx */,
logicalSlotIdx1 /* logicalSlotIdx */, isActiveEsim1 /* isActive */),
new UiccPortInfo("" /* iccId */, 1 /* portIdx */,
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 */)));
}
}