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.network.apn
18
19 import android.provider.Telephony
20 import android.telephony.data.ApnSetting
21 import androidx.compose.runtime.Composable
22 import androidx.compose.runtime.LaunchedEffect
23 import androidx.compose.runtime.remember
24 import androidx.compose.ui.platform.LocalContext
25 import androidx.compose.ui.res.stringResource
26 import com.android.settings.R
27 import com.android.settings.network.apn.ApnTypes.isValid
28 import com.android.settings.network.apn.ApnTypes.toApnType
29 import com.android.settingslib.spa.widget.editor.SettingsDropdownCheckBox
30
31 @Composable
ApnTypeCheckBoxnull32 fun ApnTypeCheckBox(
33 apnData: ApnData,
34 onTypeChanged: (String) -> Unit,
35 onMmsSelectedChanged: (Boolean) -> Unit,
36 ) {
37 val context = LocalContext.current
38 val apnTypeOptions = remember {
39 ApnTypes.getOptions(context, apnData.apnType, apnData.customizedConfig.readOnlyApnTypes)
40 }
41
42 fun updateMmsSelected() {
43 val apnTypeOptionMms = apnTypeOptions.single { it.text == ApnSetting.TYPE_MMS_STRING }
44 onMmsSelectedChanged(apnTypeOptionMms.selected.value)
45 }
46 LaunchedEffect(Unit) { updateMmsSelected() }
47 SettingsDropdownCheckBox(
48 label = stringResource(R.string.apn_type),
49 options = apnTypeOptions,
50 enabled = apnData.isFieldEnabled(Telephony.Carriers.TYPE),
51 errorMessage = stringResource(R.string.error_apn_type_empty)
52 .takeUnless { apnTypeOptions.isValid() },
53 ) {
54 onTypeChanged(apnTypeOptions.toApnType())
55 updateMmsSelected()
56 }
57 }
58