Use SubscriptionUtil.getFormattedPhoneNumber
For Primary SIM. Bug: 318310357 Test: manual - on Mobile Settings Change-Id: Ic8085532fd025bb1e0b6897f5509f485c37a6d56
This commit is contained in:
@@ -44,13 +44,13 @@ import androidx.lifecycle.viewmodel.compose.viewModel
|
|||||||
import com.android.settings.R
|
import com.android.settings.R
|
||||||
import com.android.settings.network.SubscriptionInfoListViewModel
|
import com.android.settings.network.SubscriptionInfoListViewModel
|
||||||
import com.android.settings.network.telephony.MobileNetworkUtils
|
import com.android.settings.network.telephony.MobileNetworkUtils
|
||||||
|
import com.android.settings.spa.network.PrimarySimRepository.PrimarySimInfo
|
||||||
import com.android.settings.wifi.WifiPickerTrackerHelper
|
import com.android.settings.wifi.WifiPickerTrackerHelper
|
||||||
import com.android.settingslib.spa.framework.common.SettingsEntryBuilder
|
import com.android.settingslib.spa.framework.common.SettingsEntryBuilder
|
||||||
import com.android.settingslib.spa.framework.common.SettingsPageProvider
|
import com.android.settingslib.spa.framework.common.SettingsPageProvider
|
||||||
import com.android.settingslib.spa.framework.common.createSettingsPage
|
import com.android.settingslib.spa.framework.common.createSettingsPage
|
||||||
import com.android.settingslib.spa.framework.compose.navigator
|
import com.android.settingslib.spa.framework.compose.navigator
|
||||||
import com.android.settingslib.spa.framework.util.collectLatestWithLifecycle
|
import com.android.settingslib.spa.framework.util.collectLatestWithLifecycle
|
||||||
import com.android.settingslib.spa.widget.preference.ListPreferenceOption
|
|
||||||
import com.android.settingslib.spa.widget.preference.Preference
|
import com.android.settingslib.spa.widget.preference.Preference
|
||||||
import com.android.settingslib.spa.widget.preference.PreferenceModel
|
import com.android.settingslib.spa.widget.preference.PreferenceModel
|
||||||
import com.android.settingslib.spa.widget.preference.SwitchPreference
|
import com.android.settingslib.spa.widget.preference.SwitchPreference
|
||||||
@@ -173,27 +173,23 @@ fun PageImpl(
|
|||||||
) {
|
) {
|
||||||
val selectableSubscriptionInfoList by selectableSubscriptionInfoListFlow
|
val selectableSubscriptionInfoList by selectableSubscriptionInfoListFlow
|
||||||
.collectAsStateWithLifecycle(initialValue = emptyList())
|
.collectAsStateWithLifecycle(initialValue = emptyList())
|
||||||
val activeSubscriptionInfoList: List<SubscriptionInfo> =
|
|
||||||
selectableSubscriptionInfoList.filter { subscriptionInfo ->
|
|
||||||
subscriptionInfo.simSlotIndex != -1
|
|
||||||
}
|
|
||||||
|
|
||||||
val stringSims = stringResource(R.string.provider_network_settings_title)
|
val stringSims = stringResource(R.string.provider_network_settings_title)
|
||||||
RegularScaffold(title = stringSims) {
|
RegularScaffold(title = stringSims) {
|
||||||
SimsSection(selectableSubscriptionInfoList)
|
SimsSection(selectableSubscriptionInfoList)
|
||||||
PrimarySimSectionImpl(
|
PrimarySimSectionImpl(
|
||||||
activeSubscriptionInfoList,
|
selectableSubscriptionInfoListFlow,
|
||||||
defaultVoiceSubId,
|
defaultVoiceSubId,
|
||||||
defaultSmsSubId,
|
defaultSmsSubId,
|
||||||
defaultDataSubId,
|
defaultDataSubId,
|
||||||
nonDds
|
nonDds
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun PrimarySimImpl(
|
fun PrimarySimImpl(
|
||||||
subscriptionInfoList: List<SubscriptionInfo>,
|
primarySimInfo: PrimarySimInfo,
|
||||||
callsSelectedId: MutableIntState,
|
callsSelectedId: MutableIntState,
|
||||||
textsSelectedId: MutableIntState,
|
textsSelectedId: MutableIntState,
|
||||||
mobileDataSelectedId: MutableIntState,
|
mobileDataSelectedId: MutableIntState,
|
||||||
@@ -237,108 +233,83 @@ fun PrimarySimImpl(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
var state = rememberSaveable { mutableStateOf(false) }
|
val telephonyManagerForNonDds: TelephonyManager? =
|
||||||
var callsAndSmsList = remember {
|
context.getSystemService(TelephonyManager::class.java)
|
||||||
mutableListOf(ListPreferenceOption(id = -1, text = "Loading"))
|
?.createForSubscriptionId(nonDds.intValue)
|
||||||
}
|
val automaticDataChecked = rememberSaveable() {
|
||||||
var dataList = remember {
|
mutableStateOf(false)
|
||||||
mutableListOf(ListPreferenceOption(id = -1, text = "Loading"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (subscriptionInfoList.size >= 2) {
|
CreatePrimarySimListPreference(
|
||||||
state.value = true
|
stringResource(id = R.string.primary_sim_calls_title),
|
||||||
callsAndSmsList.clear()
|
primarySimInfo.callsAndSmsList,
|
||||||
dataList.clear()
|
callsSelectedId,
|
||||||
for (info in subscriptionInfoList) {
|
ImageVector.vectorResource(R.drawable.ic_phone),
|
||||||
var item = ListPreferenceOption(
|
actionSetCalls
|
||||||
id = info.subscriptionId,
|
)
|
||||||
text = "${info.displayName}",
|
CreatePrimarySimListPreference(
|
||||||
summary = "${info.number}"
|
stringResource(id = R.string.primary_sim_texts_title),
|
||||||
)
|
primarySimInfo.callsAndSmsList,
|
||||||
callsAndSmsList.add(item)
|
textsSelectedId,
|
||||||
dataList.add(item)
|
Icons.AutoMirrored.Outlined.Message,
|
||||||
}
|
actionSetTexts
|
||||||
callsAndSmsList.add(
|
)
|
||||||
ListPreferenceOption(
|
CreatePrimarySimListPreference(
|
||||||
id = SubscriptionManager.INVALID_SUBSCRIPTION_ID,
|
stringResource(id = R.string.mobile_data_settings_title),
|
||||||
text = stringResource(id = R.string.sim_calls_ask_first_prefs_title)
|
primarySimInfo.dataList,
|
||||||
)
|
mobileDataSelectedId,
|
||||||
)
|
Icons.Outlined.DataUsage,
|
||||||
} else {
|
actionSetMobileData
|
||||||
// hide the primary sim
|
)
|
||||||
state.value = false
|
|
||||||
Log.d(NetworkCellularGroupProvider.name, "Hide primary sim")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state.value) {
|
val autoDataTitle = stringResource(id = R.string.primary_sim_automatic_data_title)
|
||||||
val telephonyManagerForNonDds: TelephonyManager? =
|
val autoDataSummary = stringResource(id = R.string.primary_sim_automatic_data_msg)
|
||||||
context.getSystemService(TelephonyManager::class.java)
|
SwitchPreference(
|
||||||
?.createForSubscriptionId(nonDds.intValue)
|
object : SwitchPreferenceModel {
|
||||||
val automaticDataChecked = rememberSaveable() {
|
override val title = autoDataTitle
|
||||||
mutableStateOf(false)
|
override val summary = { autoDataSummary }
|
||||||
}
|
override val checked = {
|
||||||
|
if (nonDds.intValue != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||||
CreatePrimarySimListPreference(
|
coroutineScope.launch {
|
||||||
stringResource(id = R.string.primary_sim_calls_title),
|
automaticDataChecked.value = getAutomaticData(telephonyManagerForNonDds)
|
||||||
callsAndSmsList,
|
Log.d(
|
||||||
callsSelectedId,
|
NetworkCellularGroupProvider.name,
|
||||||
ImageVector.vectorResource(R.drawable.ic_phone),
|
"NonDds:${nonDds.intValue}" +
|
||||||
actionSetCalls
|
"getAutomaticData:${automaticDataChecked.value}"
|
||||||
)
|
)
|
||||||
CreatePrimarySimListPreference(
|
|
||||||
stringResource(id = R.string.primary_sim_texts_title),
|
|
||||||
callsAndSmsList,
|
|
||||||
textsSelectedId,
|
|
||||||
Icons.AutoMirrored.Outlined.Message,
|
|
||||||
actionSetTexts
|
|
||||||
)
|
|
||||||
CreatePrimarySimListPreference(
|
|
||||||
stringResource(id = R.string.mobile_data_settings_title),
|
|
||||||
dataList,
|
|
||||||
mobileDataSelectedId,
|
|
||||||
Icons.Outlined.DataUsage,
|
|
||||||
actionSetMobileData
|
|
||||||
)
|
|
||||||
|
|
||||||
val autoDataTitle = stringResource(id = R.string.primary_sim_automatic_data_title)
|
|
||||||
val autoDataSummary = stringResource(id = R.string.primary_sim_automatic_data_msg)
|
|
||||||
SwitchPreference(
|
|
||||||
object : SwitchPreferenceModel {
|
|
||||||
override val title = autoDataTitle
|
|
||||||
override val summary = { autoDataSummary }
|
|
||||||
override val checked = {
|
|
||||||
if (nonDds.intValue != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
|
||||||
coroutineScope.launch {
|
|
||||||
automaticDataChecked.value = getAutomaticData(telephonyManagerForNonDds)
|
|
||||||
Log.d(
|
|
||||||
NetworkCellularGroupProvider.name,
|
|
||||||
"NonDds:${nonDds.intValue}" +
|
|
||||||
"getAutomaticData:${automaticDataChecked.value}"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
automaticDataChecked.value
|
|
||||||
}
|
|
||||||
override val onCheckedChange: ((Boolean) -> Unit)? = {
|
|
||||||
automaticDataChecked.value = it
|
|
||||||
actionSetAutoDataSwitch(it)
|
|
||||||
}
|
}
|
||||||
|
automaticDataChecked.value
|
||||||
}
|
}
|
||||||
)
|
override val onCheckedChange: ((Boolean) -> Unit)? = {
|
||||||
}
|
automaticDataChecked.value = it
|
||||||
|
actionSetAutoDataSwitch(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun PrimarySimSectionImpl(
|
fun PrimarySimSectionImpl(
|
||||||
subscriptionInfoList: List<SubscriptionInfo>,
|
subscriptionInfoListFlow: Flow<List<SubscriptionInfo>>,
|
||||||
callsSelectedId: MutableIntState,
|
callsSelectedId: MutableIntState,
|
||||||
textsSelectedId: MutableIntState,
|
textsSelectedId: MutableIntState,
|
||||||
mobileDataSelectedId: MutableIntState,
|
mobileDataSelectedId: MutableIntState,
|
||||||
nonDds: MutableIntState,
|
nonDds: MutableIntState,
|
||||||
) {
|
) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
val primarySimInfo = remember(subscriptionInfoListFlow) {
|
||||||
|
subscriptionInfoListFlow
|
||||||
|
.map { subscriptionInfoList ->
|
||||||
|
subscriptionInfoList.filter { subInfo -> subInfo.simSlotIndex != -1 }
|
||||||
|
}
|
||||||
|
.map(PrimarySimRepository(context)::getPrimarySimInfo)
|
||||||
|
.flowOn(Dispatchers.Default)
|
||||||
|
}.collectAsStateWithLifecycle(initialValue = null).value ?: return
|
||||||
|
|
||||||
Category(title = stringResource(id = R.string.primary_sim_title)) {
|
Category(title = stringResource(id = R.string.primary_sim_title)) {
|
||||||
PrimarySimImpl(
|
PrimarySimImpl(
|
||||||
subscriptionInfoList,
|
primarySimInfo,
|
||||||
callsSelectedId,
|
callsSelectedId,
|
||||||
textsSelectedId,
|
textsSelectedId,
|
||||||
mobileDataSelectedId,
|
mobileDataSelectedId,
|
||||||
|
62
src/com/android/settings/spa/network/PrimarySimRepository.kt
Normal file
62
src/com/android/settings/spa/network/PrimarySimRepository.kt
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* 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.telephony.SubscriptionInfo
|
||||||
|
import android.telephony.SubscriptionManager
|
||||||
|
import android.util.Log
|
||||||
|
import com.android.settings.R
|
||||||
|
import com.android.settings.network.SubscriptionUtil
|
||||||
|
import com.android.settingslib.spa.widget.preference.ListPreferenceOption
|
||||||
|
|
||||||
|
class PrimarySimRepository(private val context: Context) {
|
||||||
|
|
||||||
|
data class PrimarySimInfo(
|
||||||
|
val callsAndSmsList: List<ListPreferenceOption>,
|
||||||
|
val dataList: List<ListPreferenceOption>,
|
||||||
|
)
|
||||||
|
|
||||||
|
fun getPrimarySimInfo(selectableSubscriptionInfoList: List<SubscriptionInfo>): PrimarySimInfo? {
|
||||||
|
if (selectableSubscriptionInfoList.size < 2) {
|
||||||
|
Log.d(TAG, "Hide primary sim")
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
val callsAndSmsList = mutableListOf<ListPreferenceOption>()
|
||||||
|
val dataList = mutableListOf<ListPreferenceOption>()
|
||||||
|
for (info in selectableSubscriptionInfoList) {
|
||||||
|
val item = ListPreferenceOption(
|
||||||
|
id = info.subscriptionId,
|
||||||
|
text = "${info.displayName}",
|
||||||
|
summary = SubscriptionUtil.getFormattedPhoneNumber(context, info) ?: "",
|
||||||
|
)
|
||||||
|
callsAndSmsList += item
|
||||||
|
dataList += item
|
||||||
|
}
|
||||||
|
callsAndSmsList += ListPreferenceOption(
|
||||||
|
id = SubscriptionManager.INVALID_SUBSCRIPTION_ID,
|
||||||
|
text = context.getString(R.string.sim_calls_ask_first_prefs_title),
|
||||||
|
)
|
||||||
|
|
||||||
|
return PrimarySimInfo(callsAndSmsList, dataList)
|
||||||
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
private const val TAG = "PrimarySimRepository"
|
||||||
|
}
|
||||||
|
}
|
@@ -24,10 +24,13 @@ import androidx.compose.material.icons.outlined.SignalCellularAlt
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.MutableIntState
|
import androidx.compose.runtime.MutableIntState
|
||||||
import androidx.compose.runtime.mutableIntStateOf
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.saveable.rememberSaveable
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import com.android.settings.R
|
import com.android.settings.R
|
||||||
import com.android.settings.network.SimOnboardingService
|
import com.android.settings.network.SimOnboardingService
|
||||||
import com.android.settingslib.spa.framework.theme.SettingsDimension
|
import com.android.settingslib.spa.framework.theme.SettingsDimension
|
||||||
@@ -38,6 +41,9 @@ import com.android.settingslib.spa.widget.scaffold.BottomAppBarButton
|
|||||||
import com.android.settingslib.spa.widget.scaffold.SuwScaffold
|
import com.android.settingslib.spa.widget.scaffold.SuwScaffold
|
||||||
import com.android.settingslib.spa.widget.ui.SettingsBody
|
import com.android.settingslib.spa.widget.ui.SettingsBody
|
||||||
import com.android.settingslib.spa.widget.ui.SettingsIcon
|
import com.android.settingslib.spa.widget.ui.SettingsIcon
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.flow.flow
|
||||||
|
import kotlinx.coroutines.flow.flowOn
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the sim onboarding primary sim compose
|
* the sim onboarding primary sim compose
|
||||||
@@ -77,13 +83,19 @@ fun SimOnboardingPrimarySimImpl(
|
|||||||
SettingsBody(stringResource(id = R.string.sim_onboarding_primary_sim_msg))
|
SettingsBody(stringResource(id = R.string.sim_onboarding_primary_sim_msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
var selectedSubscriptionInfoList =
|
val context = LocalContext.current
|
||||||
onboardingService.getSelectedSubscriptionInfoListWithRenaming()
|
val primarySimInfo = remember {
|
||||||
|
flow {
|
||||||
|
val selectableSubInfoList =
|
||||||
|
onboardingService.getSelectedSubscriptionInfoListWithRenaming()
|
||||||
|
emit(PrimarySimRepository(context).getPrimarySimInfo(selectableSubInfoList))
|
||||||
|
}.flowOn(Dispatchers.Default)
|
||||||
|
}.collectAsStateWithLifecycle(initialValue = null).value ?: return@SuwScaffold
|
||||||
callsSelectedId.intValue = onboardingService.targetPrimarySimCalls
|
callsSelectedId.intValue = onboardingService.targetPrimarySimCalls
|
||||||
textsSelectedId.intValue = onboardingService.targetPrimarySimTexts
|
textsSelectedId.intValue = onboardingService.targetPrimarySimTexts
|
||||||
mobileDataSelectedId.intValue = onboardingService.targetPrimarySimMobileData
|
mobileDataSelectedId.intValue = onboardingService.targetPrimarySimMobileData
|
||||||
PrimarySimImpl(
|
PrimarySimImpl(
|
||||||
subscriptionInfoList = selectedSubscriptionInfoList,
|
primarySimInfo = primarySimInfo,
|
||||||
callsSelectedId = callsSelectedId,
|
callsSelectedId = callsSelectedId,
|
||||||
textsSelectedId = textsSelectedId,
|
textsSelectedId = textsSelectedId,
|
||||||
mobileDataSelectedId = mobileDataSelectedId,
|
mobileDataSelectedId = mobileDataSelectedId,
|
||||||
|
Reference in New Issue
Block a user