Merge "Modify the condition for showing DSDS dialog" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
10373c67c0
@@ -74,8 +74,11 @@ class SimOnboardingService {
|
||||
}
|
||||
var isEsimProfileEnabled: Boolean = false
|
||||
get() {
|
||||
activeSubInfoList.stream().anyMatch { it.isEmbedded }
|
||||
return false
|
||||
return activeSubInfoList.stream().anyMatch { it.isEmbedded }
|
||||
}
|
||||
var isRemovableSimProfileEnabled: Boolean = false
|
||||
get() {
|
||||
return activeSubInfoList.stream().anyMatch { !it.isEmbedded }
|
||||
}
|
||||
var doesTargetSimActive = false
|
||||
get() {
|
||||
@@ -288,8 +291,8 @@ class SimOnboardingService {
|
||||
Log.d(TAG, "Hardware does not support DSDS.")
|
||||
return false
|
||||
}
|
||||
val isActiveSim = activeSubInfoList.isNotEmpty()
|
||||
if (isMultipleEnabledProfilesSupported && isActiveSim) {
|
||||
val anyActiveSim = activeSubInfoList.isNotEmpty()
|
||||
if (isMultipleEnabledProfilesSupported && anyActiveSim) {
|
||||
Log.d(TAG,
|
||||
"Device supports MEP and eSIM operation and eSIM profile is enabled."
|
||||
+ " DSDS condition satisfied."
|
||||
@@ -297,15 +300,13 @@ class SimOnboardingService {
|
||||
return true
|
||||
}
|
||||
|
||||
if (doesTargetSimHaveEsimOperation) {
|
||||
if (UiccSlotRepository(telephonyManager).anyRemovablePhysicalSimEnabled()) {
|
||||
Log.d(
|
||||
TAG,
|
||||
"eSIM operation and removable PSIM is enabled. DSDS condition satisfied."
|
||||
)
|
||||
return true
|
||||
}
|
||||
} else if (isEsimProfileEnabled) {
|
||||
if (doesTargetSimHaveEsimOperation && isRemovableSimProfileEnabled) {
|
||||
Log.d(TAG,
|
||||
"eSIM operation and removable PSIM is enabled. DSDS condition satisfied."
|
||||
)
|
||||
return true
|
||||
}
|
||||
if (!doesTargetSimHaveEsimOperation && isEsimProfileEnabled) {
|
||||
Log.d(TAG,
|
||||
"Removable SIM operation and eSIM profile is enabled. DSDS condition"
|
||||
+ " satisfied."
|
||||
|
@@ -557,15 +557,17 @@ public class ToggleSubscriptionDialogActivity extends SubscriptionActionDialogAc
|
||||
Log.d(TAG, "Hardware does not support DSDS.");
|
||||
return false;
|
||||
}
|
||||
boolean isActiveSim = SubscriptionUtil.getActiveSubscriptions(
|
||||
boolean anyActiveSim = SubscriptionUtil.getActiveSubscriptions(
|
||||
mSubscriptionManager).size() > 0;
|
||||
if (isMultipleEnabledProfilesSupported() && isActiveSim) {
|
||||
if (isMultipleEnabledProfilesSupported() && anyActiveSim) {
|
||||
Log.d(TAG,
|
||||
"Device supports MEP and eSIM operation and eSIM profile is enabled."
|
||||
+ " DSDS condition satisfied.");
|
||||
return true;
|
||||
}
|
||||
boolean isRemovableSimEnabled = isRemovableSimEnabled();
|
||||
boolean isRemovableSimEnabled =
|
||||
SubscriptionUtil.getActiveSubscriptions(mSubscriptionManager).stream()
|
||||
.anyMatch(subInfo-> !subInfo.isEmbedded());
|
||||
if (mIsEsimOperation && isRemovableSimEnabled) {
|
||||
Log.d(TAG, "eSIM operation and removable SIM is enabled. DSDS condition satisfied.");
|
||||
return true;
|
||||
@@ -583,7 +585,7 @@ public class ToggleSubscriptionDialogActivity extends SubscriptionActionDialogAc
|
||||
}
|
||||
|
||||
private boolean isRemovableSimEnabled() {
|
||||
return new UiccSlotRepository(mTelMgr).anyRemovablePhysicalSimEnabled();
|
||||
return new UiccSlotRepository(mTelMgr).anyRemovablePhysicalSimSlotActiveAndInserted();
|
||||
}
|
||||
|
||||
private boolean isMultipleEnabledProfilesSupported() {
|
||||
|
@@ -22,17 +22,17 @@ import android.util.Log
|
||||
|
||||
class UiccSlotRepository(private val telephonyManager: TelephonyManager?) {
|
||||
|
||||
/** Returns whether any removable physical sim is enabled. */
|
||||
fun anyRemovablePhysicalSimEnabled(): Boolean {
|
||||
/** Returns whether any removable physical sim slot is active and the sim is inserted. */
|
||||
fun anyRemovablePhysicalSimSlotActiveAndInserted(): Boolean {
|
||||
val result =
|
||||
telephonyManager?.uiccSlotsInfo?.any { uiccSlotInfo: UiccSlotInfo? ->
|
||||
uiccSlotInfo.isRemovablePhysicalSimEnabled()
|
||||
uiccSlotInfo.isRemovablePhysicalSimSlotActiveAndInserted()
|
||||
} ?: false
|
||||
Log.i(TAG, "anyRemovablePhysicalSimEnabled: $result")
|
||||
return result
|
||||
}
|
||||
|
||||
private fun UiccSlotInfo?.isRemovablePhysicalSimEnabled(): Boolean {
|
||||
private fun UiccSlotInfo?.isRemovablePhysicalSimSlotActiveAndInserted(): Boolean {
|
||||
return this != null &&
|
||||
isRemovable &&
|
||||
!isEuicc &&
|
||||
|
@@ -16,21 +16,55 @@
|
||||
|
||||
package com.android.settings.network
|
||||
|
||||
import android.content.Context
|
||||
import android.telephony.SubscriptionInfo
|
||||
import android.telephony.SubscriptionManager
|
||||
import android.telephony.TelephonyManager
|
||||
import android.telephony.UiccCardInfo
|
||||
import android.telephony.UiccPortInfo
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.Rule
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.kotlin.doReturn
|
||||
import org.mockito.kotlin.mock
|
||||
import org.mockito.kotlin.spy
|
||||
import org.mockito.kotlin.stub
|
||||
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class SimOnboardingServiceTest {
|
||||
val simOnboardingService = SimOnboardingService()
|
||||
|
||||
private val mockTelephonyManager = mock<TelephonyManager> {
|
||||
on { activeModemCount } doReturn 2
|
||||
on { isMultiSimSupported } doReturn TelephonyManager.MULTISIM_ALLOWED
|
||||
on { uiccCardsInfo } doReturn mepUiccCardInfoList
|
||||
}
|
||||
|
||||
private val mockSubscriptionManager = mock<SubscriptionManager> {
|
||||
on { activeSubscriptionInfoList } doReturn listOf(
|
||||
SUB_INFO_1,
|
||||
SUB_INFO_2
|
||||
)
|
||||
on { availableSubscriptionInfoList } doReturn listOf(
|
||||
SUB_INFO_1,
|
||||
SUB_INFO_2,
|
||||
SUB_INFO_3,
|
||||
)
|
||||
}
|
||||
|
||||
private val context: Context = spy(ApplicationProvider.getApplicationContext()) {
|
||||
on { getSystemService(SubscriptionManager::class.java) } doReturn mockSubscriptionManager
|
||||
on { getSystemService(TelephonyManager::class.java) } doReturn mockTelephonyManager
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addItemForRenaming_addItemWithNewName_findItem() {
|
||||
val simOnboardingService = SimOnboardingService()
|
||||
val newName = "NewName"
|
||||
|
||||
simOnboardingService.addItemForRenaming(SUB_INFO_1, newName)
|
||||
|
||||
assertThat(simOnboardingService.renameMutableMap)
|
||||
@@ -39,8 +73,6 @@ class SimOnboardingServiceTest {
|
||||
|
||||
@Test
|
||||
fun addItemForRenaming_sameNameAndItemNotInList_removeItem() {
|
||||
val simOnboardingService = SimOnboardingService()
|
||||
|
||||
simOnboardingService.addItemForRenaming(SUB_INFO_1, DISPLAY_NAME_1)
|
||||
|
||||
assertThat(simOnboardingService.renameMutableMap)
|
||||
@@ -49,7 +81,6 @@ class SimOnboardingServiceTest {
|
||||
|
||||
@Test
|
||||
fun addItemForRenaming_sameNameAndItemInList_removeItem() {
|
||||
val simOnboardingService = SimOnboardingService()
|
||||
simOnboardingService.renameMutableMap[SUB_INFO_1.subscriptionId] = "NewName"
|
||||
|
||||
simOnboardingService.addItemForRenaming(SUB_INFO_1, DISPLAY_NAME_1)
|
||||
@@ -58,13 +89,205 @@ class SimOnboardingServiceTest {
|
||||
.doesNotContainKey(SUB_INFO_1.subscriptionId)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isDsdsConditionSatisfied_isMultiSimEnabled_returnFalse(){
|
||||
simOnboardingService.initData(SUB_ID_3, context, {})
|
||||
|
||||
assertThat(simOnboardingService.isDsdsConditionSatisfied()).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isDsdsConditionSatisfied_isNotMultiSimSupported_returnFalse() {
|
||||
mockTelephonyManager.stub {
|
||||
on { activeModemCount } doReturn 1
|
||||
on {
|
||||
isMultiSimSupported
|
||||
} doReturn TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE
|
||||
}
|
||||
simOnboardingService.initData(SUB_ID_3, context, {})
|
||||
|
||||
assertThat(simOnboardingService.isDsdsConditionSatisfied()).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isDsdsConditionSatisfied_mepAndOneActiveSim_returnTrue() = runBlocking {
|
||||
mockTelephonyManager.stub {
|
||||
on { activeModemCount } doReturn 1
|
||||
}
|
||||
simOnboardingService.initData(SUB_ID_3, context, {})
|
||||
delay(100)
|
||||
|
||||
assertThat(simOnboardingService.isDsdsConditionSatisfied()).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isDsdsConditionSatisfied_mepAndNoActiveSim_returnFalse() = runBlocking {
|
||||
mockTelephonyManager.stub {
|
||||
on { activeModemCount } doReturn 1
|
||||
}
|
||||
mockSubscriptionManager.stub {
|
||||
on { activeSubscriptionInfoList } doReturn listOf()
|
||||
}
|
||||
simOnboardingService.initData(SUB_ID_3, context, {})
|
||||
delay(100)
|
||||
|
||||
assertThat(simOnboardingService.isDsdsConditionSatisfied()).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isDsdsConditionSatisfied_insertEsimAndOneActivePsimNoMep_returnTrue() = runBlocking {
|
||||
mockTelephonyManager.stub {
|
||||
on { getActiveModemCount() } doReturn 1
|
||||
on { uiccCardsInfo } doReturn noMepUiccCardInfoList
|
||||
}
|
||||
simOnboardingService.initData(SUB_ID_3, context, {})
|
||||
delay(100)
|
||||
|
||||
assertThat(simOnboardingService.isDsdsConditionSatisfied()).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isDsdsConditionSatisfied_insertEsimAndNoPsimNoMep_returnFalse() = runBlocking {
|
||||
mockTelephonyManager.stub {
|
||||
on { getActiveModemCount() } doReturn 1
|
||||
on { uiccCardsInfo } doReturn noMepUiccCardInfoList
|
||||
}
|
||||
mockSubscriptionManager.stub {
|
||||
on { activeSubscriptionInfoList } doReturn listOf()
|
||||
}
|
||||
simOnboardingService.initData(SUB_ID_3, context, {})
|
||||
delay(100)
|
||||
|
||||
assertThat(simOnboardingService.isDsdsConditionSatisfied()).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isDsdsConditionSatisfied_insertPsimAndOneActiveEsimNoMep_returnTrue() = runBlocking {
|
||||
mockTelephonyManager.stub {
|
||||
on { getActiveModemCount() } doReturn 1
|
||||
on { uiccCardsInfo } doReturn noMepUiccCardInfoList
|
||||
}
|
||||
mockSubscriptionManager.stub {
|
||||
on { activeSubscriptionInfoList } doReturn listOf(
|
||||
SUB_INFO_2
|
||||
)
|
||||
}
|
||||
simOnboardingService.initData(SUB_ID_1, context, {})
|
||||
delay(100)
|
||||
|
||||
assertThat(simOnboardingService.isDsdsConditionSatisfied()).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isDsdsConditionSatisfied_insertPsimAndNoEsimNoMep_returnFalse() = runBlocking {
|
||||
mockTelephonyManager.stub {
|
||||
on { getActiveModemCount() } doReturn 1
|
||||
on { uiccCardsInfo } doReturn noMepUiccCardInfoList
|
||||
}
|
||||
mockSubscriptionManager.stub {
|
||||
on { activeSubscriptionInfoList } doReturn listOf()
|
||||
}
|
||||
simOnboardingService.initData(SUB_ID_1, context, {})
|
||||
delay(100)
|
||||
|
||||
assertThat(simOnboardingService.isDsdsConditionSatisfied()).isFalse()
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val SUB_ID_1 = 1
|
||||
const val SUB_ID_2 = 2
|
||||
const val SUB_ID_3 = 3
|
||||
const val SUB_ID_4 = 4
|
||||
const val DISPLAY_NAME_1 = "Sub 1"
|
||||
|
||||
val SUB_INFO_1: SubscriptionInfo = SubscriptionInfo.Builder().apply {
|
||||
setId(SUB_ID_1)
|
||||
setDisplayName(DISPLAY_NAME_1)
|
||||
}.build()
|
||||
|
||||
val SUB_INFO_2: SubscriptionInfo = SubscriptionInfo.Builder().apply {
|
||||
setId(SUB_ID_2)
|
||||
setEmbedded(true)
|
||||
}.build()
|
||||
|
||||
val SUB_INFO_3: SubscriptionInfo = SubscriptionInfo.Builder().apply {
|
||||
setId(SUB_ID_3)
|
||||
setEmbedded(true)
|
||||
}.build()
|
||||
|
||||
val SUB_INFO_4: SubscriptionInfo = SubscriptionInfo.Builder().apply {
|
||||
setId(SUB_ID_4)
|
||||
}.build()
|
||||
|
||||
private const val REMOVABLE_CARD_ID_1: Int = 25
|
||||
private const val REMOVABLE_CARD_ID_2: Int = 26
|
||||
private const val EUICC_CARD_ID_3: Int = 27
|
||||
private const val EUICC_CARD_ID_4: Int = 28
|
||||
|
||||
val noMepUiccCardInfoList: List<UiccCardInfo> = listOf(
|
||||
createUiccCardInfo(
|
||||
isEuicc = true,
|
||||
cardId = EUICC_CARD_ID_3,
|
||||
physicalSlotIndex = 0,
|
||||
isRemovable = false,
|
||||
isMultipleEnabledProfileSupported = false,
|
||||
logicalSlotIndex = -1,
|
||||
portIndex = -1
|
||||
),
|
||||
createUiccCardInfo(
|
||||
isEuicc = false,
|
||||
cardId = REMOVABLE_CARD_ID_1,
|
||||
physicalSlotIndex = 1,
|
||||
isRemovable = true,
|
||||
isMultipleEnabledProfileSupported = false,
|
||||
logicalSlotIndex = -1,
|
||||
portIndex = -1
|
||||
)
|
||||
)
|
||||
val mepUiccCardInfoList: List<UiccCardInfo> = listOf(
|
||||
createUiccCardInfo(
|
||||
isEuicc = true,
|
||||
cardId = EUICC_CARD_ID_3,
|
||||
physicalSlotIndex = 0,
|
||||
isRemovable = false,
|
||||
logicalSlotIndex = -1,
|
||||
portIndex = -1
|
||||
),
|
||||
createUiccCardInfo(
|
||||
isEuicc = false,
|
||||
cardId = REMOVABLE_CARD_ID_1,
|
||||
physicalSlotIndex = 1,
|
||||
isRemovable = true,
|
||||
logicalSlotIndex = -1,
|
||||
portIndex = -1
|
||||
)
|
||||
)
|
||||
|
||||
private fun createUiccCardInfo(
|
||||
isEuicc: Boolean,
|
||||
cardId: Int,
|
||||
physicalSlotIndex: Int,
|
||||
isRemovable: Boolean,
|
||||
logicalSlotIndex: Int,
|
||||
portIndex: Int,
|
||||
isMultipleEnabledProfileSupported:Boolean = true,
|
||||
): UiccCardInfo {
|
||||
return UiccCardInfo(
|
||||
isEuicc, /* isEuicc */
|
||||
cardId, /* cardId */
|
||||
null, /* eid */
|
||||
physicalSlotIndex, /* physicalSlotIndex */
|
||||
isRemovable, /* isRemovable */
|
||||
isMultipleEnabledProfileSupported, /* isMultipleEnabledProfileSupported */
|
||||
listOf(
|
||||
UiccPortInfo(
|
||||
"123451234567890", /* iccId */
|
||||
portIndex, /* portIdx */
|
||||
logicalSlotIndex, /* logicalSlotIdx */
|
||||
true /* isActive */
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@@ -44,7 +44,7 @@ class UiccSlotRepositoryTest {
|
||||
)
|
||||
}
|
||||
|
||||
val result = repository.anyRemovablePhysicalSimEnabled()
|
||||
val result = repository.anyRemovablePhysicalSimSlotActiveAndInserted()
|
||||
|
||||
assertThat(result).isFalse()
|
||||
}
|
||||
@@ -61,7 +61,7 @@ class UiccSlotRepositoryTest {
|
||||
)
|
||||
}
|
||||
|
||||
val result = repository.anyRemovablePhysicalSimEnabled()
|
||||
val result = repository.anyRemovablePhysicalSimSlotActiveAndInserted()
|
||||
|
||||
assertThat(result).isFalse()
|
||||
}
|
||||
@@ -78,7 +78,7 @@ class UiccSlotRepositoryTest {
|
||||
)
|
||||
}
|
||||
|
||||
val result = repository.anyRemovablePhysicalSimEnabled()
|
||||
val result = repository.anyRemovablePhysicalSimSlotActiveAndInserted()
|
||||
|
||||
assertThat(result).isTrue()
|
||||
}
|
||||
@@ -95,7 +95,7 @@ class UiccSlotRepositoryTest {
|
||||
)
|
||||
}
|
||||
|
||||
val result = repository.anyRemovablePhysicalSimEnabled()
|
||||
val result = repository.anyRemovablePhysicalSimSlotActiveAndInserted()
|
||||
|
||||
assertThat(result).isTrue()
|
||||
}
|
||||
@@ -116,7 +116,7 @@ class UiccSlotRepositoryTest {
|
||||
)
|
||||
}
|
||||
|
||||
val result = repository.anyRemovablePhysicalSimEnabled()
|
||||
val result = repository.anyRemovablePhysicalSimSlotActiveAndInserted()
|
||||
|
||||
assertThat(result).isFalse()
|
||||
}
|
||||
@@ -137,13 +137,13 @@ class UiccSlotRepositoryTest {
|
||||
)
|
||||
}
|
||||
|
||||
val result = repository.anyRemovablePhysicalSimEnabled()
|
||||
val result = repository.anyRemovablePhysicalSimSlotActiveAndInserted()
|
||||
|
||||
assertThat(result).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anyRemovablePhysicalSimEnabled_activePsim_returnsTrue() {
|
||||
fun anyRemovablePhysicalSimSlotActiveAndInserted_activePsim_returnsTrue() {
|
||||
mockTelephonyManager.stub {
|
||||
on { uiccSlotsInfo } doReturn
|
||||
arrayOf(
|
||||
@@ -152,13 +152,13 @@ class UiccSlotRepositoryTest {
|
||||
)
|
||||
}
|
||||
|
||||
val result = repository.anyRemovablePhysicalSimEnabled()
|
||||
val result = repository.anyRemovablePhysicalSimSlotActiveAndInserted()
|
||||
|
||||
assertThat(result).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anyRemovablePhysicalSimEnabled_inactivePsim_returnsFalse() {
|
||||
fun anyRemovablePhysicalSimSlotActiveAndInserted_inactivePsim_returnsFalse() {
|
||||
mockTelephonyManager.stub {
|
||||
on { uiccSlotsInfo } doReturn
|
||||
arrayOf(
|
||||
@@ -167,13 +167,13 @@ class UiccSlotRepositoryTest {
|
||||
)
|
||||
}
|
||||
|
||||
val result = repository.anyRemovablePhysicalSimEnabled()
|
||||
val result = repository.anyRemovablePhysicalSimSlotActiveAndInserted()
|
||||
|
||||
assertThat(result).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anyRemovablePhysicalSimEnabled_activeEsimAndActivePsim_returnsTrue() {
|
||||
fun anyRemovablePhysicalSimSlotActiveAndInserted_activeEsimAndActivePsim_returnsTrue() {
|
||||
mockTelephonyManager.stub {
|
||||
on { uiccSlotsInfo } doReturn
|
||||
arrayOf(
|
||||
@@ -184,13 +184,13 @@ class UiccSlotRepositoryTest {
|
||||
)
|
||||
}
|
||||
|
||||
val result = repository.anyRemovablePhysicalSimEnabled()
|
||||
val result = repository.anyRemovablePhysicalSimSlotActiveAndInserted()
|
||||
|
||||
assertThat(result).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anyRemovablePhysicalSimEnabled_activeEsimAndInactivePsim_returnsFalse() {
|
||||
fun anyRemovablePhysicalSimSlotActiveAndInserted_activeEsimAndInactivePsim_returnsFalse() {
|
||||
mockTelephonyManager.stub {
|
||||
on { uiccSlotsInfo } doReturn
|
||||
arrayOf(
|
||||
@@ -201,16 +201,16 @@ class UiccSlotRepositoryTest {
|
||||
)
|
||||
}
|
||||
|
||||
val result = repository.anyRemovablePhysicalSimEnabled()
|
||||
val result = repository.anyRemovablePhysicalSimSlotActiveAndInserted()
|
||||
|
||||
assertThat(result).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anyRemovablePhysicalSimEnabled_uiccSlotInfoIsNull_returnsFalse() {
|
||||
fun anyRemovablePhysicalSimSlotActiveAndInserted_uiccSlotInfoIsNull_returnsFalse() {
|
||||
mockTelephonyManager.stub { on { uiccSlotsInfo } doReturn arrayOf(null) }
|
||||
|
||||
val result = repository.anyRemovablePhysicalSimEnabled()
|
||||
val result = repository.anyRemovablePhysicalSimSlotActiveAndInserted()
|
||||
|
||||
assertThat(result).isFalse()
|
||||
}
|
||||
|
Reference in New Issue
Block a user