Merge "Add condition for askEveryTime of SMS at Primary Sim" into main
diff --git a/src/com/android/settings/spa/network/NetworkCellularGroupProvider.kt b/src/com/android/settings/spa/network/NetworkCellularGroupProvider.kt
index 05a8f6a..873a2c3 100644
--- a/src/com/android/settings/spa/network/NetworkCellularGroupProvider.kt
+++ b/src/com/android/settings/spa/network/NetworkCellularGroupProvider.kt
@@ -279,14 +279,14 @@
) {
CreatePrimarySimListPreference(
stringResource(id = R.string.primary_sim_calls_title),
- primarySimInfo.callsAndSmsList,
+ primarySimInfo.callsList,
callsSelectedId,
ImageVector.vectorResource(R.drawable.ic_phone),
actionSetCalls
)
CreatePrimarySimListPreference(
stringResource(id = R.string.primary_sim_texts_title),
- primarySimInfo.callsAndSmsList,
+ primarySimInfo.smsList,
textsSelectedId,
Icons.AutoMirrored.Outlined.Message,
actionSetTexts
diff --git a/src/com/android/settings/spa/network/PrimarySimRepository.kt b/src/com/android/settings/spa/network/PrimarySimRepository.kt
index e34a29e..420f870 100644
--- a/src/com/android/settings/spa/network/PrimarySimRepository.kt
+++ b/src/com/android/settings/spa/network/PrimarySimRepository.kt
@@ -22,12 +22,14 @@
import android.util.Log
import com.android.settings.R
import com.android.settings.network.SubscriptionUtil
+import com.android.settings.network.telephony.CarrierConfigRepository
import com.android.settingslib.spa.widget.preference.ListPreferenceOption
class PrimarySimRepository(private val context: Context) {
data class PrimarySimInfo(
- val callsAndSmsList: List<ListPreferenceOption>,
+ val callsList: List<ListPreferenceOption>,
+ val smsList: List<ListPreferenceOption>,
val dataList: List<ListPreferenceOption>,
)
@@ -37,7 +39,8 @@
return null
}
- val callsAndSmsList = mutableListOf<ListPreferenceOption>()
+ val callsList = mutableListOf<ListPreferenceOption>()
+ val smsList = mutableListOf<ListPreferenceOption>()
val dataList = mutableListOf<ListPreferenceOption>()
for (info in selectableSubscriptionInfoList) {
val item = ListPreferenceOption(
@@ -45,15 +48,22 @@
text = "${info.displayName}",
summary = SubscriptionUtil.getBidiFormattedPhoneNumber(context, info) ?: "",
)
- callsAndSmsList += item
+ callsList += item
+ smsList += item
dataList += item
}
- callsAndSmsList += ListPreferenceOption(
+
+ val askEveryTime = ListPreferenceOption(
id = SubscriptionManager.INVALID_SUBSCRIPTION_ID,
text = context.getString(R.string.sim_calls_ask_first_prefs_title),
)
+ callsList += askEveryTime
+ if (context.resources
+ .getBoolean(com.android.internal.R.bool.config_sms_ask_every_time_support)) {
+ smsList += askEveryTime
+ }
- return PrimarySimInfo(callsAndSmsList, dataList)
+ return PrimarySimInfo(callsList, smsList, dataList)
}
private companion object {
diff --git a/tests/spa_unit/src/com/android/settings/spa/network/PrimarySimRepositoryTest.kt b/tests/spa_unit/src/com/android/settings/spa/network/PrimarySimRepositoryTest.kt
new file mode 100644
index 0000000..459afa9
--- /dev/null
+++ b/tests/spa_unit/src/com/android/settings/spa/network/PrimarySimRepositoryTest.kt
@@ -0,0 +1,206 @@
+/*
+ * 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.spa.network
+
+import android.content.Context
+import android.content.res.Resources
+import android.telephony.SubscriptionInfo
+import android.telephony.SubscriptionManager
+import androidx.compose.ui.test.junit4.createComposeRule
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.settings.R
+import com.android.settingslib.spa.widget.preference.ListPreferenceOption
+import com.google.common.truth.Truth.assertThat
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.kotlin.any
+import org.mockito.kotlin.doAnswer
+import org.mockito.kotlin.doReturn
+import org.mockito.kotlin.mock
+import org.mockito.kotlin.spy
+import org.mockito.kotlin.stub
+
+@RunWith(AndroidJUnit4::class)
+class PrimarySimRepositoryTest {
+ @get:Rule
+ val composeTestRule = createComposeRule()
+
+ private val mockSubscriptionManager = mock<SubscriptionManager> {
+ on { addOnSubscriptionsChangedListener(any(), any()) } doAnswer {
+ val listener = it.arguments[1] as SubscriptionManager.OnSubscriptionsChangedListener
+ listener.onSubscriptionsChanged()
+ }
+ on { getPhoneNumber(SUB_ID_1) } doReturn NUMBER_1
+ on { getPhoneNumber(SUB_ID_2) } doReturn NUMBER_2
+ }
+
+ private val context: Context = spy(ApplicationProvider.getApplicationContext()) {
+ on { getSystemService(SubscriptionManager::class.java) } doReturn mockSubscriptionManager
+ }
+ private val spyResources: Resources = spy(context.resources)
+
+ @Test
+ fun getPrimarySimInfo_oneSim_returnNull() {
+ val simList = listOf(
+ SUB_INFO_1,
+ )
+
+ val primarySimInfo = PrimarySimRepository(context).getPrimarySimInfo(simList)
+
+ assertThat(primarySimInfo).isNull()
+ }
+
+ @Test
+ fun getPrimarySimInfo_verifyCallsList() {
+ val simList = listOf(
+ SUB_INFO_1,
+ SUB_INFO_2
+ )
+ val expectedList = listOf(
+ ListPreferenceOption(
+ id = SUB_INFO_1.subscriptionId,
+ text = "${SUB_INFO_1.displayName}",
+ summary = NUMBER_1
+ ),
+ ListPreferenceOption(
+ id = SUB_INFO_2.subscriptionId,
+ text = "${SUB_INFO_2.displayName}",
+ summary = NUMBER_2
+ ),
+ ListPreferenceOption(
+ id = SubscriptionManager.INVALID_SUBSCRIPTION_ID,
+ text = context.getString(R.string.sim_calls_ask_first_prefs_title),
+ ),
+ )
+
+ val primarySimInfo = PrimarySimRepository(context).getPrimarySimInfo(simList)
+
+ assertThat(primarySimInfo).isNotNull()
+ assertThat(primarySimInfo?.callsList).isEqualTo(expectedList)
+ }
+
+ @Test
+ fun getPrimarySimInfo_verifySmsList() {
+ val simList = listOf(
+ SUB_INFO_1,
+ SUB_INFO_2
+ )
+ val expectedList = listOf(
+ ListPreferenceOption(
+ id = SUB_INFO_1.subscriptionId,
+ text = "${SUB_INFO_1.displayName}",
+ summary = NUMBER_1
+ ),
+ ListPreferenceOption(
+ id = SUB_INFO_2.subscriptionId,
+ text = "${SUB_INFO_2.displayName}",
+ summary = NUMBER_2
+ ),
+ ListPreferenceOption(
+ id = SubscriptionManager.INVALID_SUBSCRIPTION_ID,
+ text = context.getString(R.string.sim_calls_ask_first_prefs_title),
+ ),
+ )
+
+ val primarySimInfo = PrimarySimRepository(context).getPrimarySimInfo(simList)
+
+ assertThat(primarySimInfo).isNotNull()
+ assertThat(primarySimInfo?.smsList).isEqualTo(expectedList)
+ }
+
+ @Test
+ fun getPrimarySimInfo_noAskEveryTime_verifySmsList() {
+ val simList = listOf(
+ SUB_INFO_1,
+ SUB_INFO_2
+ )
+ context.stub {
+ on { resources } doReturn spyResources
+ }
+ spyResources.stub {
+ on {
+ getBoolean(com.android.internal.R.bool.config_sms_ask_every_time_support)
+ } doReturn false
+ }
+ val expectedList = listOf(
+ ListPreferenceOption(
+ id = SUB_INFO_1.subscriptionId,
+ text = "${SUB_INFO_1.displayName}",
+ summary = NUMBER_1
+ ),
+ ListPreferenceOption(
+ id = SUB_INFO_2.subscriptionId,
+ text = "${SUB_INFO_2.displayName}",
+ summary = NUMBER_2
+ ),
+ )
+
+ val primarySimInfo = PrimarySimRepository(context).getPrimarySimInfo(simList)
+
+ assertThat(primarySimInfo).isNotNull()
+ assertThat(primarySimInfo?.smsList).isEqualTo(expectedList)
+ }
+
+ @Test
+ fun getPrimarySimInfo_verifyDataList() {
+ val simList = listOf(
+ SUB_INFO_1,
+ SUB_INFO_2
+ )
+ val expectedList = listOf(
+ ListPreferenceOption(
+ id = SUB_INFO_1.subscriptionId,
+ text = "${SUB_INFO_1.displayName}",
+ summary = NUMBER_1
+ ),
+ ListPreferenceOption(
+ id = SUB_INFO_2.subscriptionId,
+ text = "${SUB_INFO_2.displayName}",
+ summary = NUMBER_2
+ ),
+ )
+
+ val primarySimInfo = PrimarySimRepository(context).getPrimarySimInfo(simList)
+
+ assertThat(primarySimInfo).isNotNull()
+ assertThat(primarySimInfo?.dataList).isEqualTo(expectedList)
+ }
+
+ private companion object {
+ const val SUB_ID_1 = 1
+ const val SUB_ID_2 = 2
+ const val DISPLAY_NAME_1 = "Sub 1"
+ const val DISPLAY_NAME_2 = "Sub 2"
+ const val NUMBER_1 = "000000001"
+ const val NUMBER_2 = "000000002"
+ const val MCC = "310"
+
+ val SUB_INFO_1: SubscriptionInfo = SubscriptionInfo.Builder().apply {
+ setId(SUB_ID_1)
+ setDisplayName(DISPLAY_NAME_1)
+ setMcc(MCC)
+ }.build()
+
+ val SUB_INFO_2: SubscriptionInfo = SubscriptionInfo.Builder().apply {
+ setId(SUB_ID_2)
+ setDisplayName(DISPLAY_NAME_2)
+ setMcc(MCC)
+ }.build()
+ }
+}