Fix APN network type not updated
The issue is caused by SettingsDropdownCheckBox's interface is updated, but ApnNetworkTypeCheckBox not updated. Update ApnNetworkTypeCheckBox to fix. Bug: 329547692 Test: manual - update network type Test: unit test Change-Id: I4a5a1ad7d9d97960799f5ba0d89b5178ce410b6e
This commit is contained in:
@@ -24,18 +24,13 @@ import com.android.settingslib.spa.widget.editor.SettingsDropdownCheckBox
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ApnNetworkTypeCheckBox(apnData: ApnData, onNetworkTypeChanged: (Long) -> Unit) {
|
fun ApnNetworkTypeCheckBox(apnData: ApnData, onNetworkTypeChanged: (Long) -> Unit) {
|
||||||
val options = remember { ApnNetworkTypes.getNetworkTypeOptions() }
|
val options = remember { ApnNetworkTypes.getNetworkTypeOptions(apnData.networkType) }
|
||||||
val selectedStateMap = remember {
|
|
||||||
ApnNetworkTypes.networkTypeToSelectedStateMap(options, apnData.networkType)
|
|
||||||
}
|
|
||||||
SettingsDropdownCheckBox(
|
SettingsDropdownCheckBox(
|
||||||
label = stringResource(R.string.network_type),
|
label = stringResource(R.string.network_type),
|
||||||
options = options,
|
options = options,
|
||||||
emptyText = stringResource(R.string.network_type_unspecified),
|
emptyText = stringResource(R.string.network_type_unspecified),
|
||||||
enabled = apnData.networkTypeEnabled,
|
enabled = apnData.networkTypeEnabled,
|
||||||
) {
|
) {
|
||||||
onNetworkTypeChanged(
|
onNetworkTypeChanged(ApnNetworkTypes.optionsToNetworkType(options))
|
||||||
ApnNetworkTypes.selectedStateMapToNetworkType(options, selectedStateMap)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,8 +17,7 @@
|
|||||||
package com.android.settings.network.apn
|
package com.android.settings.network.apn
|
||||||
|
|
||||||
import android.telephony.TelephonyManager
|
import android.telephony.TelephonyManager
|
||||||
import androidx.compose.runtime.mutableStateMapOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.snapshots.SnapshotStateMap
|
|
||||||
import com.android.settingslib.spa.widget.editor.SettingsDropdownCheckOption
|
import com.android.settingslib.spa.widget.editor.SettingsDropdownCheckOption
|
||||||
|
|
||||||
object ApnNetworkTypes {
|
object ApnNetworkTypes {
|
||||||
@@ -40,38 +39,28 @@ object ApnNetworkTypes {
|
|||||||
TelephonyManager.NETWORK_TYPE_NR,
|
TelephonyManager.NETWORK_TYPE_NR,
|
||||||
)
|
)
|
||||||
|
|
||||||
fun getNetworkTypeOptions(): List<SettingsDropdownCheckOption> =
|
|
||||||
Types.map { SettingsDropdownCheckOption(TelephonyManager.getNetworkTypeName(it)) }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the selected Network type Selected Options according to network type.
|
* Gets the selected Network type Selected Options according to network type.
|
||||||
* @param networkType Initialized network type bitmask, often multiple network type options may
|
* @param networkType Initialized network type bitmask, often multiple network type options may
|
||||||
* be included.
|
* be included.
|
||||||
*/
|
*/
|
||||||
fun networkTypeToSelectedStateMap(
|
fun getNetworkTypeOptions(networkType: Long): List<SettingsDropdownCheckOption> =
|
||||||
options: List<SettingsDropdownCheckOption>,
|
Types.map { type ->
|
||||||
networkType: Long,
|
val selected = networkType and TelephonyManager.getBitMaskForNetworkType(type) != 0L
|
||||||
): SnapshotStateMap<SettingsDropdownCheckOption, Boolean> {
|
SettingsDropdownCheckOption(
|
||||||
val stateMap = mutableStateMapOf<SettingsDropdownCheckOption, Boolean>()
|
text = TelephonyManager.getNetworkTypeName(type),
|
||||||
Types.forEachIndexed { index, type ->
|
selected = mutableStateOf(selected),
|
||||||
if (networkType and TelephonyManager.getBitMaskForNetworkType(type) != 0L) {
|
)
|
||||||
stateMap[options[index]] = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return stateMap
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the network type according to the selected Network type Selected Options.
|
* Gets the network type according to the selected Network type Selected Options.
|
||||||
* @param stateMap the selected Network type Selected Options.
|
* @param options the selected Network type Selected Options.
|
||||||
*/
|
*/
|
||||||
fun selectedStateMapToNetworkType(
|
fun optionsToNetworkType(options: List<SettingsDropdownCheckOption>): Long {
|
||||||
options: List<SettingsDropdownCheckOption>,
|
|
||||||
stateMap: SnapshotStateMap<SettingsDropdownCheckOption, Boolean>,
|
|
||||||
): Long {
|
|
||||||
var networkType = 0L
|
var networkType = 0L
|
||||||
options.forEachIndexed { index, option ->
|
options.forEachIndexed { index, option ->
|
||||||
if (stateMap[option] == true) {
|
if (option.selected.value) {
|
||||||
networkType = networkType or TelephonyManager.getBitMaskForNetworkType(Types[index])
|
networkType = networkType or TelephonyManager.getBitMaskForNetworkType(Types[index])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* 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.apn
|
||||||
|
|
||||||
|
import android.telephony.TelephonyManager.NETWORK_TYPE_BITMASK_CDMA
|
||||||
|
import android.telephony.TelephonyManager.NETWORK_TYPE_BITMASK_EDGE
|
||||||
|
import android.telephony.TelephonyManager.NETWORK_TYPE_BITMASK_HSPAP
|
||||||
|
import android.telephony.TelephonyManager.NETWORK_TYPE_BITMASK_HSUPA
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
|
import com.android.settingslib.spa.widget.editor.SettingsDropdownCheckOption
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4::class)
|
||||||
|
class ApnNetworkTypesTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun getNetworkTypeOptions() {
|
||||||
|
val networkTypeOptions =
|
||||||
|
ApnNetworkTypes.getNetworkTypeOptions(
|
||||||
|
NETWORK_TYPE_BITMASK_EDGE xor NETWORK_TYPE_BITMASK_CDMA
|
||||||
|
)
|
||||||
|
|
||||||
|
assertThat(networkTypeOptions.single { it.text == "EDGE" }.selected.value).isTrue()
|
||||||
|
assertThat(networkTypeOptions.single { it.text == "CDMA" }.selected.value).isTrue()
|
||||||
|
assertThat(networkTypeOptions.single { it.text == "GPRS" }.selected.value).isFalse()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun optionsToNetworkType() {
|
||||||
|
val options = listOf(
|
||||||
|
SettingsDropdownCheckOption(text = "", selected = mutableStateOf(false)),
|
||||||
|
SettingsDropdownCheckOption(text = "", selected = mutableStateOf(true)),
|
||||||
|
SettingsDropdownCheckOption(text = "", selected = mutableStateOf(false)),
|
||||||
|
SettingsDropdownCheckOption(text = "", selected = mutableStateOf(true)),
|
||||||
|
)
|
||||||
|
|
||||||
|
val networkType = ApnNetworkTypes.optionsToNetworkType(options)
|
||||||
|
|
||||||
|
assertThat(networkType).isEqualTo(NETWORK_TYPE_BITMASK_HSPAP xor NETWORK_TYPE_BITMASK_HSUPA)
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user