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

@@ -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 */)));
}
}