[Sim UI enhancement] MobileNetworkSettings UI enhancement
- Add the phone number - Add the mobile network(SPN) - Add the IMEI - Add the EID - Remove the mobile data - Remove the Auto data switch - Remove the calls and SMS default subscription Bug: 318310357 Bug: 298898436 Bug: 298891941 Test: atest MobileNetworkEidPreferenceControllerTest atest MobileNetworkImeiPreferenceControllerTest atest MobileNetworkPhoneNumberPreferenceControllerTest atest MobileNetworkSpnPreferenceControllerTest atest MobileDataPreferenceControllerTest atest MobileNetworkSettingsTest Change-Id: Ie2767056dd04d1131390e3a03d6d82d56fe5b2dc
This commit is contained in:
committed by
SongFerng Wang
parent
c7e0649c2e
commit
8535539582
@@ -42,6 +42,7 @@ import androidx.preference.TwoStatePreference;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.datausage.DataUsageUtils;
|
||||
import com.android.settings.flags.Flags;
|
||||
import com.android.settings.network.MobileDataContentObserver;
|
||||
import com.android.settings.network.ProxySubscriptionManager;
|
||||
import com.android.settings.network.SubscriptionsChangeListener;
|
||||
@@ -194,7 +195,8 @@ public class AutoDataSwitchPreferenceController extends TelephonyTogglePreferenc
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus(int subId) {
|
||||
if (!SubscriptionManager.isValidSubscriptionId(subId)
|
||||
if (Flags.isDualSimOnboardingEnabled()
|
||||
|| !SubscriptionManager.isValidSubscriptionId(subId)
|
||||
|| SubscriptionManager.getDefaultDataSubscriptionId() == subId
|
||||
|| (!hasMobileData())) {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
|
@@ -32,6 +32,7 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.flags.Flags;
|
||||
import com.android.settings.network.DefaultSubscriptionReceiver;
|
||||
import com.android.settings.network.MobileNetworkRepository;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
@@ -88,6 +89,9 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus(int subId) {
|
||||
if (Flags.isDualSimOnboardingEnabled()) {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
|
@@ -34,6 +34,7 @@ import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.flags.Flags;
|
||||
import com.android.settings.network.MobileNetworkRepository;
|
||||
import com.android.settings.wifi.WifiPickerTrackerHelper;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
@@ -83,6 +84,9 @@ public class MobileDataPreferenceController extends TelephonyTogglePreferenceCon
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus(int subId) {
|
||||
if (Flags.isDualSimOnboardingEnabled()) {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
return subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID
|
||||
? AVAILABLE
|
||||
: AVAILABLE_UNSEARCHABLE;
|
||||
|
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* 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.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.telephony.SubscriptionInfo
|
||||
import android.telephony.SubscriptionManager
|
||||
import android.telephony.TelephonyManager
|
||||
import android.telephony.euicc.EuiccManager
|
||||
import android.text.TextUtils
|
||||
import android.util.Log
|
||||
import android.view.WindowManager
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceScreen
|
||||
import com.android.settings.R
|
||||
import com.android.settings.deviceinfo.PhoneNumberUtil
|
||||
import com.android.settings.flags.Flags
|
||||
import com.android.settings.network.SubscriptionInfoListViewModel
|
||||
import com.android.settings.network.SubscriptionUtil
|
||||
import com.android.settingslib.CustomDialogPreferenceCompat
|
||||
import com.android.settingslib.Utils
|
||||
import com.android.settingslib.qrcode.QrCodeGenerator
|
||||
import com.android.settingslib.spa.framework.util.collectLatestWithLifecycle
|
||||
import com.android.settingslib.spaprivileged.framework.common.userManager
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
/**
|
||||
* Preference controller for "EID"
|
||||
*/
|
||||
open class MobileNetworkEidPreferenceController(context: Context, key: String) :
|
||||
TelephonyBasePreferenceController(context, key) {
|
||||
|
||||
private lateinit var lazyViewModel: Lazy<SubscriptionInfoListViewModel>
|
||||
private lateinit var preference: CustomDialogPreferenceCompat
|
||||
private lateinit var fragment: Fragment
|
||||
private var coroutineScope: CoroutineScope? = null
|
||||
private var title = String()
|
||||
private var eid = String()
|
||||
|
||||
fun init(fragment: Fragment, subId: Int) {
|
||||
this.fragment = fragment
|
||||
lazyViewModel = fragment.viewModels()
|
||||
mSubId = subId
|
||||
}
|
||||
|
||||
override fun getAvailabilityStatus(subId: Int): Int = when {
|
||||
!Flags.isDualSimOnboardingEnabled() -> CONDITIONALLY_UNAVAILABLE
|
||||
SubscriptionManager.isValidSubscriptionId(subId)
|
||||
&& eid.isNotEmpty()
|
||||
&& mContext.userManager.isAdminUser -> AVAILABLE
|
||||
|
||||
else -> CONDITIONALLY_UNAVAILABLE
|
||||
}
|
||||
|
||||
override fun displayPreference(screen: PreferenceScreen) {
|
||||
super.displayPreference(screen)
|
||||
preference = screen.findPreference(preferenceKey)!!
|
||||
}
|
||||
|
||||
override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
|
||||
preference.isVisible = false
|
||||
|
||||
val viewModel by lazyViewModel
|
||||
coroutineScope = viewLifecycleOwner.lifecycleScope
|
||||
viewModel.subscriptionInfoListFlow
|
||||
.map { subscriptionInfoList ->
|
||||
subscriptionInfoList
|
||||
.firstOrNull { subInfo ->
|
||||
subInfo.subscriptionId == mSubId && subInfo.isEmbedded
|
||||
}
|
||||
}
|
||||
.collectLatestWithLifecycle(viewLifecycleOwner) { subscriptionInfo ->
|
||||
subscriptionInfo?.let {
|
||||
coroutineScope?.launch {
|
||||
refreshData(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
suspend fun refreshData(subscriptionInfo: SubscriptionInfo) {
|
||||
withContext(Dispatchers.Default) {
|
||||
eid = getEid(subscriptionInfo)
|
||||
if (eid.isEmpty()) {
|
||||
Log.d(TAG, "EID is empty.")
|
||||
}
|
||||
title = getTitle()
|
||||
}
|
||||
refreshUi()
|
||||
}
|
||||
|
||||
fun refreshUi() {
|
||||
preference.title = title
|
||||
preference.dialogTitle = title
|
||||
preference.summary = eid
|
||||
preference.isVisible = eid.isNotEmpty()
|
||||
}
|
||||
|
||||
override fun handlePreferenceTreeClick(preference: Preference): Boolean {
|
||||
if (preference.key != preferenceKey) return false
|
||||
this.preference.setOnShowListener {
|
||||
coroutineScope?.launch { updateDialog() }
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun getTitle(): String {
|
||||
return mContext.getString(R.string.status_eid)
|
||||
}
|
||||
|
||||
private suspend fun updateDialog() {
|
||||
val dialog = preference.dialog ?: return
|
||||
dialog.window?.setFlags(
|
||||
WindowManager.LayoutParams.FLAG_SECURE,
|
||||
WindowManager.LayoutParams.FLAG_SECURE
|
||||
)
|
||||
dialog.setCanceledOnTouchOutside(false)
|
||||
val textView = dialog.requireViewById<TextView>(R.id.esim_id_value)
|
||||
textView.text = PhoneNumberUtil.expandByTts(eid)
|
||||
|
||||
val qrCodeView = dialog.requireViewById<ImageView>(R.id.esim_id_qrcode)
|
||||
|
||||
qrCodeView.setImageBitmap(getEidQrCode(eid))
|
||||
}
|
||||
|
||||
protected fun getTelephonyManager(context: Context): TelephonyManager? {
|
||||
return context.getSystemService(TelephonyManager::class.java)
|
||||
}
|
||||
|
||||
protected fun getEuiccManager(context: Context): EuiccManager? {
|
||||
return context.getSystemService(EuiccManager::class.java)
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
fun getEid(subscriptionInfo: SubscriptionInfo): String {
|
||||
val euiccMgr = getEuiccManager(mContext)
|
||||
val telMgr = getTelephonyManager(mContext)
|
||||
if(euiccMgr==null || telMgr==null) return String()
|
||||
|
||||
var eid = getEidPerSlot(telMgr, euiccMgr, subscriptionInfo)
|
||||
return eid.ifEmpty {
|
||||
getDefaultEid(euiccMgr)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getEidPerSlot(
|
||||
telMgr: TelephonyManager,
|
||||
euiccMgr: EuiccManager,
|
||||
subscriptionInfo: SubscriptionInfo
|
||||
): String {
|
||||
val uiccCardInfoList = telMgr.uiccCardsInfo
|
||||
val cardId = subscriptionInfo.cardId
|
||||
|
||||
/**
|
||||
* Find EID from first slot which contains an eSIM and with card ID within
|
||||
* the eSIM card ID provided by SubscriptionManager.
|
||||
*/
|
||||
return uiccCardInfoList.firstOrNull { cardInfo -> cardInfo.isEuicc && cardInfo.cardId == cardId }
|
||||
?.let { cardInfo ->
|
||||
var eid = cardInfo.getEid()
|
||||
if (TextUtils.isEmpty(eid)) {
|
||||
eid = euiccMgr.createForCardId(cardInfo.cardId).getEid()
|
||||
}
|
||||
eid
|
||||
} ?: String()
|
||||
}
|
||||
|
||||
private fun getDefaultEid(euiccMgr: EuiccManager?): String {
|
||||
return if (euiccMgr == null || !euiccMgr.isEnabled) {
|
||||
String()
|
||||
} else euiccMgr.getEid() ?: String()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "MobileNetworkEidPreferenceController"
|
||||
private const val QR_CODE_SIZE = 600
|
||||
|
||||
/**
|
||||
* Gets the QR code for EID
|
||||
* @param eid is the EID string
|
||||
* @return a Bitmap of QR code
|
||||
*/
|
||||
private suspend fun getEidQrCode(eid: String): Bitmap? = withContext(Dispatchers.Default) {
|
||||
try {
|
||||
Log.d(TAG, "updateDialog. getEidQrCode $eid")
|
||||
QrCodeGenerator.encodeQrCode(contents = eid, size = QR_CODE_SIZE)
|
||||
} catch (exception: Exception) {
|
||||
Log.w(TAG, "Error when creating QR code width $QR_CODE_SIZE", exception)
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* 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.content.Context
|
||||
import android.os.UserManager
|
||||
import android.telephony.SubscriptionInfo
|
||||
import android.telephony.SubscriptionManager
|
||||
import android.telephony.TelephonyManager
|
||||
import android.util.Log
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceScreen
|
||||
import com.android.settings.R
|
||||
import com.android.settings.deviceinfo.imei.ImeiInfoDialogFragment
|
||||
import com.android.settings.flags.Flags
|
||||
import com.android.settings.network.SubscriptionInfoListViewModel
|
||||
import com.android.settings.network.SubscriptionUtil
|
||||
import com.android.settingslib.Utils
|
||||
import com.android.settingslib.spa.framework.util.collectLatestWithLifecycle
|
||||
import com.android.settingslib.spaprivileged.framework.common.userManager
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
/**
|
||||
* Preference controller for "IMEI"
|
||||
*/
|
||||
class MobileNetworkImeiPreferenceController(context: Context, key: String) :
|
||||
TelephonyBasePreferenceController(context, key) {
|
||||
|
||||
private lateinit var lazyViewModel: Lazy<SubscriptionInfoListViewModel>
|
||||
private lateinit var preference: Preference
|
||||
private lateinit var fragment: Fragment
|
||||
private lateinit var mTelephonyManager: TelephonyManager
|
||||
private var simSlot = -1
|
||||
private var imei = String()
|
||||
private var title = String()
|
||||
|
||||
fun init(fragment: Fragment, subId: Int) {
|
||||
this.fragment = fragment
|
||||
lazyViewModel = fragment.viewModels()
|
||||
mSubId = subId
|
||||
mTelephonyManager = mContext.getSystemService(TelephonyManager::class.java)
|
||||
?.createForSubscriptionId(mSubId)!!
|
||||
}
|
||||
|
||||
override fun getAvailabilityStatus(subId: Int): Int = when {
|
||||
!Flags.isDualSimOnboardingEnabled() -> CONDITIONALLY_UNAVAILABLE
|
||||
SubscriptionManager.isValidSubscriptionId(subId)
|
||||
&& SubscriptionUtil.isSimHardwareVisible(mContext)
|
||||
&& mContext.userManager.isAdminUser
|
||||
&& !Utils.isWifiOnly(mContext) -> AVAILABLE
|
||||
else -> CONDITIONALLY_UNAVAILABLE
|
||||
}
|
||||
|
||||
override fun displayPreference(screen: PreferenceScreen) {
|
||||
super.displayPreference(screen)
|
||||
preference = screen.findPreference(preferenceKey)!!
|
||||
}
|
||||
|
||||
override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
|
||||
val viewModel by lazyViewModel
|
||||
val coroutineScope = viewLifecycleOwner.lifecycleScope
|
||||
|
||||
viewModel.subscriptionInfoListFlow
|
||||
.collectLatestWithLifecycle(viewLifecycleOwner) { subscriptionInfoList ->
|
||||
subscriptionInfoList
|
||||
.firstOrNull { subInfo -> subInfo.subscriptionId == mSubId }
|
||||
?.let {
|
||||
coroutineScope.launch {
|
||||
refreshData(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
suspend fun refreshData(subscription:SubscriptionInfo){
|
||||
withContext(Dispatchers.Default) {
|
||||
title = getTitle()
|
||||
imei = getImei()
|
||||
simSlot = subscription.simSlotIndex
|
||||
}
|
||||
refreshUi()
|
||||
}
|
||||
|
||||
private fun refreshUi(){
|
||||
preference.title = title
|
||||
preference.summary = imei
|
||||
preference.isVisible = true
|
||||
}
|
||||
|
||||
override fun handlePreferenceTreeClick(preference: Preference): Boolean {
|
||||
if (preference.key != preferenceKey) return false
|
||||
|
||||
Log.d(TAG, "handlePreferenceTreeClick:")
|
||||
ImeiInfoDialogFragment.show(fragment, simSlot, preference.title.toString())
|
||||
return true
|
||||
}
|
||||
private fun getImei(): String {
|
||||
val phoneType = getPhoneType()
|
||||
return if (phoneType == TelephonyManager.PHONE_TYPE_CDMA) mTelephonyManager.meid?: String()
|
||||
else mTelephonyManager.imei?: String()
|
||||
}
|
||||
private fun getTitleForGsmPhone(): String {
|
||||
return mContext.getString(R.string.status_imei)
|
||||
}
|
||||
|
||||
private fun getTitleForCdmaPhone(): String {
|
||||
return mContext.getString(R.string.status_meid_number)
|
||||
}
|
||||
|
||||
private fun getTitle(): String {
|
||||
val phoneType = getPhoneType()
|
||||
return if (phoneType == TelephonyManager.PHONE_TYPE_CDMA) getTitleForCdmaPhone()
|
||||
else getTitleForGsmPhone()
|
||||
}
|
||||
|
||||
fun getPhoneType(): Int {
|
||||
return mTelephonyManager.currentPhoneType
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "MobileNetworkImeiPreferenceController"
|
||||
}
|
||||
}
|
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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.content.Context
|
||||
import android.telephony.SubscriptionInfo
|
||||
import android.telephony.SubscriptionManager
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceScreen
|
||||
import com.android.settings.R
|
||||
import com.android.settings.flags.Flags
|
||||
import com.android.settings.network.SubscriptionInfoListViewModel
|
||||
import com.android.settings.network.SubscriptionUtil
|
||||
import com.android.settingslib.spa.framework.util.collectLatestWithLifecycle
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
/**
|
||||
* Preference controller for "Phone number"
|
||||
*/
|
||||
class MobileNetworkPhoneNumberPreferenceController(context: Context, key: String) :
|
||||
TelephonyBasePreferenceController(context, key) {
|
||||
|
||||
private lateinit var lazyViewModel: Lazy<SubscriptionInfoListViewModel>
|
||||
private lateinit var preference: Preference
|
||||
|
||||
private var phoneNumber = String()
|
||||
|
||||
fun init(fragment: Fragment, subId: Int) {
|
||||
lazyViewModel = fragment.viewModels()
|
||||
mSubId = subId
|
||||
}
|
||||
|
||||
override fun getAvailabilityStatus(subId: Int): Int = when {
|
||||
!Flags.isDualSimOnboardingEnabled() -> CONDITIONALLY_UNAVAILABLE
|
||||
SubscriptionManager.isValidSubscriptionId(subId)
|
||||
&& SubscriptionUtil.isSimHardwareVisible(mContext) -> AVAILABLE
|
||||
else -> CONDITIONALLY_UNAVAILABLE
|
||||
}
|
||||
|
||||
override fun displayPreference(screen: PreferenceScreen) {
|
||||
super.displayPreference(screen)
|
||||
preference = screen.findPreference(preferenceKey)!!
|
||||
}
|
||||
|
||||
override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
|
||||
val viewModel by lazyViewModel
|
||||
val coroutineScope = viewLifecycleOwner.lifecycleScope
|
||||
|
||||
viewModel.subscriptionInfoListFlow
|
||||
.map { subscriptionInfoList ->
|
||||
subscriptionInfoList
|
||||
.firstOrNull { subInfo -> subInfo.subscriptionId == mSubId }
|
||||
}
|
||||
.flowOn(Dispatchers.Default)
|
||||
.collectLatestWithLifecycle(viewLifecycleOwner) {
|
||||
it?.let {
|
||||
coroutineScope.launch {
|
||||
refreshData(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
suspend fun refreshData(subscriptionInfo: SubscriptionInfo){
|
||||
withContext(Dispatchers.Default) {
|
||||
phoneNumber = getFormattedPhoneNumber(subscriptionInfo)
|
||||
}
|
||||
refreshUi()
|
||||
}
|
||||
|
||||
private fun refreshUi(){
|
||||
preference.summary = phoneNumber
|
||||
}
|
||||
|
||||
private fun getFormattedPhoneNumber(subscriptionInfo: SubscriptionInfo?): String {
|
||||
val phoneNumber = SubscriptionUtil.getBidiFormattedPhoneNumber(
|
||||
mContext,
|
||||
subscriptionInfo
|
||||
)
|
||||
return phoneNumber
|
||||
?.let { return it.ifEmpty { getStringUnknown() } }
|
||||
?: getStringUnknown()
|
||||
}
|
||||
|
||||
private fun getStringUnknown(): String {
|
||||
return mContext.getString(R.string.device_info_default)
|
||||
}
|
||||
}
|
@@ -85,6 +85,7 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme
|
||||
private static final String KEY_SMS_PREF = "sms_preference";
|
||||
private static final String KEY_MOBILE_DATA_PREF = "mobile_data_enable";
|
||||
private static final String KEY_CONVERT_TO_ESIM_PREF = "convert_to_esim";
|
||||
private static final String KEY_EID_KEY = "network_mode_eid_info";
|
||||
|
||||
//String keys for preference lookup
|
||||
private static final String BUTTON_CDMA_SYSTEM_SELECT_KEY = "cdma_system_select_key";
|
||||
@@ -171,6 +172,10 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme
|
||||
String.valueOf(mSubId));
|
||||
});
|
||||
|
||||
MobileNetworkEidPreferenceController eid = new MobileNetworkEidPreferenceController(context,
|
||||
KEY_EID_KEY);
|
||||
eid.init(this, mSubId);
|
||||
|
||||
return Arrays.asList(
|
||||
new DataUsageSummaryPreferenceController(context, mSubId),
|
||||
new RoamingPreferenceController(context, KEY_ROAMING_PREF, getSettingsLifecycle(),
|
||||
@@ -182,7 +187,7 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme
|
||||
new MobileDataPreferenceController(context, KEY_MOBILE_DATA_PREF,
|
||||
getSettingsLifecycle(), this, mSubId),
|
||||
new ConvertToEsimPreferenceController(context, KEY_CONVERT_TO_ESIM_PREF,
|
||||
getSettingsLifecycle(), this, mSubId));
|
||||
getSettingsLifecycle(), this, mSubId), eid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -239,6 +244,10 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme
|
||||
use(DisableSimFooterPreferenceController.class).init(mSubId);
|
||||
use(NrDisabledInDsdsFooterPreferenceController.class).init(mSubId);
|
||||
|
||||
use(MobileNetworkSpnPreferenceController.class).init(this, mSubId);
|
||||
use(MobileNetworkPhoneNumberPreferenceController.class).init(this, mSubId);
|
||||
use(MobileNetworkImeiPreferenceController.class).init(this, mSubId);
|
||||
|
||||
final MobileDataPreferenceController mobileDataPreferenceController =
|
||||
use(MobileDataPreferenceController.class);
|
||||
if (mobileDataPreferenceController != null) {
|
||||
|
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.content.Context
|
||||
import android.telephony.SubscriptionInfo
|
||||
import android.telephony.SubscriptionManager
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceScreen
|
||||
import com.android.settings.flags.Flags
|
||||
import com.android.settings.network.SubscriptionInfoListViewModel
|
||||
import com.android.settingslib.spa.framework.util.collectLatestWithLifecycle
|
||||
|
||||
/**
|
||||
* Preference controller for "Mobile network" and showing the SPN.
|
||||
*/
|
||||
class MobileNetworkSpnPreferenceController(context: Context, key: String) :
|
||||
TelephonyBasePreferenceController(context, key) {
|
||||
|
||||
private lateinit var lazyViewModel: Lazy<SubscriptionInfoListViewModel>
|
||||
private lateinit var preference: Preference
|
||||
|
||||
private var spn = String()
|
||||
|
||||
fun init(fragment: Fragment, subId: Int) {
|
||||
lazyViewModel = fragment.viewModels()
|
||||
mSubId = subId
|
||||
}
|
||||
|
||||
override fun getAvailabilityStatus(subId: Int): Int = when {
|
||||
!Flags.isDualSimOnboardingEnabled() -> CONDITIONALLY_UNAVAILABLE
|
||||
SubscriptionManager.isValidSubscriptionId(subId)-> AVAILABLE
|
||||
else -> CONDITIONALLY_UNAVAILABLE
|
||||
}
|
||||
|
||||
override fun displayPreference(screen: PreferenceScreen) {
|
||||
super.displayPreference(screen)
|
||||
preference = screen.findPreference(preferenceKey)!!
|
||||
}
|
||||
|
||||
override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
|
||||
val viewModel by lazyViewModel
|
||||
|
||||
viewModel.subscriptionInfoListFlow
|
||||
.collectLatestWithLifecycle(viewLifecycleOwner) { subscriptionInfoList ->
|
||||
refreshData(subscriptionInfoList)
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
fun refreshData(subscriptionInfoList: List<SubscriptionInfo>){
|
||||
spn = subscriptionInfoList
|
||||
.firstOrNull { subInfo -> subInfo.subscriptionId == mSubId }
|
||||
?.let { info -> info.carrierName.toString() }
|
||||
?: String()
|
||||
|
||||
refreshUi()
|
||||
}
|
||||
|
||||
private fun refreshUi(){
|
||||
preference.summary = spn
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user