1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.spa.network 18 19 import android.content.Context 20 import android.telephony.SubscriptionInfo 21 import android.telephony.SubscriptionManager 22 import android.util.Log 23 import com.android.settings.R 24 import com.android.settings.network.SubscriptionUtil 25 import com.android.settingslib.spa.widget.preference.ListPreferenceOption 26 27 class PrimarySimRepository(private val context: Context) { 28 29 data class PrimarySimInfo( 30 val callsAndSmsList: List<ListPreferenceOption>, 31 val dataList: List<ListPreferenceOption>, 32 ) 33 getPrimarySimInfonull34 fun getPrimarySimInfo(selectableSubscriptionInfoList: List<SubscriptionInfo>): PrimarySimInfo? { 35 if (selectableSubscriptionInfoList.size < 2) { 36 Log.d(TAG, "Hide primary sim") 37 return null 38 } 39 40 val callsAndSmsList = mutableListOf<ListPreferenceOption>() 41 val dataList = mutableListOf<ListPreferenceOption>() 42 for (info in selectableSubscriptionInfoList) { 43 val item = ListPreferenceOption( 44 id = info.subscriptionId, 45 text = "${info.displayName}", 46 summary = SubscriptionUtil.getBidiFormattedPhoneNumber(context, info) ?: "", 47 ) 48 callsAndSmsList += item 49 dataList += item 50 } 51 callsAndSmsList += ListPreferenceOption( 52 id = SubscriptionManager.INVALID_SUBSCRIPTION_ID, 53 text = context.getString(R.string.sim_calls_ask_first_prefs_title), 54 ) 55 56 return PrimarySimInfo(callsAndSmsList, dataList) 57 } 58 59 private companion object { 60 private const val TAG = "PrimarySimRepository" 61 } 62 } 63