1 /* <lambda>null2 * Copyright (C) 2023 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.network.apn 18 19 import android.telephony.TelephonyManager 20 import androidx.compose.runtime.mutableStateOf 21 import com.android.settingslib.spa.widget.editor.SettingsDropdownCheckOption 22 23 object ApnNetworkTypes { 24 private val Types = listOf( 25 TelephonyManager.NETWORK_TYPE_LTE, 26 TelephonyManager.NETWORK_TYPE_HSPAP, 27 TelephonyManager.NETWORK_TYPE_HSPA, 28 TelephonyManager.NETWORK_TYPE_HSUPA, 29 TelephonyManager.NETWORK_TYPE_HSDPA, 30 TelephonyManager.NETWORK_TYPE_UMTS, 31 TelephonyManager.NETWORK_TYPE_EDGE, 32 TelephonyManager.NETWORK_TYPE_GPRS, 33 TelephonyManager.NETWORK_TYPE_EHRPD, 34 TelephonyManager.NETWORK_TYPE_EVDO_B, 35 TelephonyManager.NETWORK_TYPE_EVDO_A, 36 TelephonyManager.NETWORK_TYPE_EVDO_0, 37 TelephonyManager.NETWORK_TYPE_1xRTT, 38 TelephonyManager.NETWORK_TYPE_CDMA, 39 TelephonyManager.NETWORK_TYPE_NR, 40 ) 41 42 /** 43 * Gets the selected Network type Selected Options according to network type. 44 * @param networkType Initialized network type bitmask, often multiple network type options may 45 * be included. 46 */ 47 fun getNetworkTypeOptions(networkType: Long): List<SettingsDropdownCheckOption> = 48 Types.map { type -> 49 val selected = networkType and TelephonyManager.getBitMaskForNetworkType(type) != 0L 50 SettingsDropdownCheckOption( 51 text = TelephonyManager.getNetworkTypeName(type), 52 selected = mutableStateOf(selected), 53 ) 54 } 55 56 /** 57 * Gets the network type according to the selected Network type Selected Options. 58 * @param options the selected Network type Selected Options. 59 */ 60 fun optionsToNetworkType(options: List<SettingsDropdownCheckOption>): Long { 61 var networkType = 0L 62 options.forEachIndexed { index, option -> 63 if (option.selected.value) { 64 networkType = networkType or TelephonyManager.getBitMaskForNetworkType(Types[index]) 65 } 66 } 67 return networkType 68 } 69 } 70