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.network.SubscriptionInfoListViewModel
|
||||
import com.android.settings.network.telephony.MobileNetworkUtils
|
||||
import com.android.settings.spa.network.PrimarySimRepository.PrimarySimInfo
|
||||
import com.android.settings.wifi.WifiPickerTrackerHelper
|
||||
import com.android.settingslib.spa.framework.common.SettingsEntryBuilder
|
||||
import com.android.settingslib.spa.framework.common.SettingsPageProvider
|
||||
import com.android.settingslib.spa.framework.common.createSettingsPage
|
||||
import com.android.settingslib.spa.framework.compose.navigator
|
||||
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.PreferenceModel
|
||||
import com.android.settingslib.spa.widget.preference.SwitchPreference
|
||||
@@ -173,16 +173,12 @@ fun PageImpl(
|
||||
) {
|
||||
val selectableSubscriptionInfoList by selectableSubscriptionInfoListFlow
|
||||
.collectAsStateWithLifecycle(initialValue = emptyList())
|
||||
val activeSubscriptionInfoList: List<SubscriptionInfo> =
|
||||
selectableSubscriptionInfoList.filter { subscriptionInfo ->
|
||||
subscriptionInfo.simSlotIndex != -1
|
||||
}
|
||||
|
||||
val stringSims = stringResource(R.string.provider_network_settings_title)
|
||||
RegularScaffold(title = stringSims) {
|
||||
SimsSection(selectableSubscriptionInfoList)
|
||||
PrimarySimSectionImpl(
|
||||
activeSubscriptionInfoList,
|
||||
selectableSubscriptionInfoListFlow,
|
||||
defaultVoiceSubId,
|
||||
defaultSmsSubId,
|
||||
defaultDataSubId,
|
||||
@@ -193,7 +189,7 @@ fun PageImpl(
|
||||
|
||||
@Composable
|
||||
fun PrimarySimImpl(
|
||||
subscriptionInfoList: List<SubscriptionInfo>,
|
||||
primarySimInfo: PrimarySimInfo,
|
||||
callsSelectedId: MutableIntState,
|
||||
textsSelectedId: MutableIntState,
|
||||
mobileDataSelectedId: MutableIntState,
|
||||
@@ -237,40 +233,6 @@ fun PrimarySimImpl(
|
||||
}
|
||||
},
|
||||
) {
|
||||
var state = rememberSaveable { mutableStateOf(false) }
|
||||
var callsAndSmsList = remember {
|
||||
mutableListOf(ListPreferenceOption(id = -1, text = "Loading"))
|
||||
}
|
||||
var dataList = remember {
|
||||
mutableListOf(ListPreferenceOption(id = -1, text = "Loading"))
|
||||
}
|
||||
|
||||
if (subscriptionInfoList.size >= 2) {
|
||||
state.value = true
|
||||
callsAndSmsList.clear()
|
||||
dataList.clear()
|
||||
for (info in subscriptionInfoList) {
|
||||
var item = ListPreferenceOption(
|
||||
id = info.subscriptionId,
|
||||
text = "${info.displayName}",
|
||||
summary = "${info.number}"
|
||||
)
|
||||
callsAndSmsList.add(item)
|
||||
dataList.add(item)
|
||||
}
|
||||
callsAndSmsList.add(
|
||||
ListPreferenceOption(
|
||||
id = SubscriptionManager.INVALID_SUBSCRIPTION_ID,
|
||||
text = stringResource(id = R.string.sim_calls_ask_first_prefs_title)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
// hide the primary sim
|
||||
state.value = false
|
||||
Log.d(NetworkCellularGroupProvider.name, "Hide primary sim")
|
||||
}
|
||||
|
||||
if (state.value) {
|
||||
val telephonyManagerForNonDds: TelephonyManager? =
|
||||
context.getSystemService(TelephonyManager::class.java)
|
||||
?.createForSubscriptionId(nonDds.intValue)
|
||||
@@ -280,21 +242,21 @@ fun PrimarySimImpl(
|
||||
|
||||
CreatePrimarySimListPreference(
|
||||
stringResource(id = R.string.primary_sim_calls_title),
|
||||
callsAndSmsList,
|
||||
primarySimInfo.callsAndSmsList,
|
||||
callsSelectedId,
|
||||
ImageVector.vectorResource(R.drawable.ic_phone),
|
||||
actionSetCalls
|
||||
)
|
||||
CreatePrimarySimListPreference(
|
||||
stringResource(id = R.string.primary_sim_texts_title),
|
||||
callsAndSmsList,
|
||||
primarySimInfo.callsAndSmsList,
|
||||
textsSelectedId,
|
||||
Icons.AutoMirrored.Outlined.Message,
|
||||
actionSetTexts
|
||||
)
|
||||
CreatePrimarySimListPreference(
|
||||
stringResource(id = R.string.mobile_data_settings_title),
|
||||
dataList,
|
||||
primarySimInfo.dataList,
|
||||
mobileDataSelectedId,
|
||||
Icons.Outlined.DataUsage,
|
||||
actionSetMobileData
|
||||
@@ -326,19 +288,28 @@ fun PrimarySimImpl(
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun PrimarySimSectionImpl(
|
||||
subscriptionInfoList: List<SubscriptionInfo>,
|
||||
subscriptionInfoListFlow: Flow<List<SubscriptionInfo>>,
|
||||
callsSelectedId: MutableIntState,
|
||||
textsSelectedId: MutableIntState,
|
||||
mobileDataSelectedId: 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)) {
|
||||
PrimarySimImpl(
|
||||
subscriptionInfoList,
|
||||
primarySimInfo,
|
||||
callsSelectedId,
|
||||
textsSelectedId,
|
||||
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.MutableIntState
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.android.settings.R
|
||||
import com.android.settings.network.SimOnboardingService
|
||||
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.ui.SettingsBody
|
||||
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
|
||||
@@ -77,13 +83,19 @@ fun SimOnboardingPrimarySimImpl(
|
||||
SettingsBody(stringResource(id = R.string.sim_onboarding_primary_sim_msg))
|
||||
}
|
||||
|
||||
var selectedSubscriptionInfoList =
|
||||
val context = LocalContext.current
|
||||
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
|
||||
textsSelectedId.intValue = onboardingService.targetPrimarySimTexts
|
||||
mobileDataSelectedId.intValue = onboardingService.targetPrimarySimMobileData
|
||||
PrimarySimImpl(
|
||||
subscriptionInfoList = selectedSubscriptionInfoList,
|
||||
primarySimInfo = primarySimInfo,
|
||||
callsSelectedId = callsSelectedId,
|
||||
textsSelectedId = textsSelectedId,
|
||||
mobileDataSelectedId = mobileDataSelectedId,
|
||||
|
Reference in New Issue
Block a user