Merge "Refactor ApnEditCarrierEnabled" into main
This commit is contained in:
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* 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.provider.Telephony
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.res.booleanResource
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import com.android.settings.R
|
||||||
|
import com.android.settingslib.spa.widget.preference.SwitchPreference
|
||||||
|
import com.android.settingslib.spa.widget.preference.SwitchPreferenceModel
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ApnEditCarrierEnabled(apnData: ApnData, onCarrierEnabledChanged: (Boolean) -> Unit) {
|
||||||
|
SwitchPreference(
|
||||||
|
object : SwitchPreferenceModel {
|
||||||
|
override val title = stringResource(R.string.carrier_enabled)
|
||||||
|
val allowEdit = booleanResource(R.bool.config_allow_edit_carrier_enabled)
|
||||||
|
override val changeable = {
|
||||||
|
allowEdit && apnData.isFieldEnabled(Telephony.Carriers.CARRIER_ENABLED)
|
||||||
|
}
|
||||||
|
override val checked = { apnData.carrierEnabled }
|
||||||
|
override val onCheckedChange = onCarrierEnabledChanged
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -235,19 +235,7 @@ fun ApnPage(apnDataInit: ApnData, apnDataCur: MutableState<ApnData>, uriInit: Ur
|
|||||||
enabled = apnData.isFieldEnabled(Telephony.Carriers.ROAMING_PROTOCOL),
|
enabled = apnData.isFieldEnabled(Telephony.Carriers.ROAMING_PROTOCOL),
|
||||||
) { apnData = apnData.copy(apnRoaming = it) }
|
) { apnData = apnData.copy(apnRoaming = it) }
|
||||||
ApnNetworkTypeCheckBox(apnData) { apnData = apnData.copy(networkType = it) }
|
ApnNetworkTypeCheckBox(apnData) { apnData = apnData.copy(networkType = it) }
|
||||||
SwitchPreference(
|
ApnEditCarrierEnabled(apnData) { apnData = apnData.copy(carrierEnabled = it) }
|
||||||
object : SwitchPreferenceModel {
|
|
||||||
override val title = stringResource(R.string.carrier_enabled)
|
|
||||||
override val changeable = {
|
|
||||||
apnData.apnEnableEnabled &&
|
|
||||||
apnData.isFieldEnabled(Telephony.Carriers.CARRIER_ENABLED)
|
|
||||||
}
|
|
||||||
override val checked = { apnData.apnEnable }
|
|
||||||
override val onCheckedChange = { newChecked: Boolean ->
|
|
||||||
apnData = apnData.copy(apnEnable = newChecked)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,7 +90,7 @@ fun getApnDataFromUri(uri: Uri, context: Context): ApnData {
|
|||||||
apnRoaming = context.convertProtocol2Options(
|
apnRoaming = context.convertProtocol2Options(
|
||||||
cursor.getString(Telephony.Carriers.ROAMING_PROTOCOL)
|
cursor.getString(Telephony.Carriers.ROAMING_PROTOCOL)
|
||||||
),
|
),
|
||||||
apnEnable = cursor.getInt(Telephony.Carriers.CARRIER_ENABLED) == 1,
|
carrierEnabled = cursor.getInt(Telephony.Carriers.CARRIER_ENABLED) == 1,
|
||||||
networkType = cursor.getLong(Telephony.Carriers.NETWORK_TYPE_BITMASK),
|
networkType = cursor.getLong(Telephony.Carriers.NETWORK_TYPE_BITMASK),
|
||||||
edited = cursor.getInt(Telephony.Carriers.EDITED_STATUS),
|
edited = cursor.getInt(Telephony.Carriers.EDITED_STATUS),
|
||||||
userEditable = cursor.getInt(Telephony.Carriers.USER_EDITABLE),
|
userEditable = cursor.getInt(Telephony.Carriers.USER_EDITABLE),
|
||||||
|
|||||||
@@ -44,11 +44,10 @@ data class ApnData(
|
|||||||
val apnType: String = "",
|
val apnType: String = "",
|
||||||
val apnProtocol: Int = -1,
|
val apnProtocol: Int = -1,
|
||||||
val apnRoaming: Int = -1,
|
val apnRoaming: Int = -1,
|
||||||
val apnEnable: Boolean = true,
|
val carrierEnabled: Boolean = true,
|
||||||
val networkType: Long = 0,
|
val networkType: Long = 0,
|
||||||
val edited: Int = Telephony.Carriers.USER_EDITED,
|
val edited: Int = Telephony.Carriers.USER_EDITED,
|
||||||
val userEditable: Int = 1,
|
val userEditable: Int = 1,
|
||||||
val apnEnableEnabled: Boolean = true,
|
|
||||||
val newApn: Boolean = false,
|
val newApn: Boolean = false,
|
||||||
val subId: Int = -1,
|
val subId: Int = -1,
|
||||||
val validEnabled: Boolean = false,
|
val validEnabled: Boolean = false,
|
||||||
@@ -72,7 +71,7 @@ data class ApnData(
|
|||||||
Telephony.Carriers.NETWORK_TYPE_BITMASK to networkType,
|
Telephony.Carriers.NETWORK_TYPE_BITMASK to networkType,
|
||||||
// Copy network type into lingering network type.
|
// Copy network type into lingering network type.
|
||||||
Telephony.Carriers.LINGERING_NETWORK_TYPE_BITMASK to networkType,
|
Telephony.Carriers.LINGERING_NETWORK_TYPE_BITMASK to networkType,
|
||||||
Telephony.Carriers.CARRIER_ENABLED to apnEnable,
|
Telephony.Carriers.CARRIER_ENABLED to carrierEnabled,
|
||||||
Telephony.Carriers.EDITED_STATUS to Telephony.Carriers.USER_EDITED,
|
Telephony.Carriers.EDITED_STATUS to Telephony.Carriers.USER_EDITED,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -134,10 +133,6 @@ fun getApnDataInit(arguments: Bundle, context: Context, uriInit: Uri, subId: Int
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
apnDataInit = apnDataInit.copy(
|
|
||||||
apnEnableEnabled =
|
|
||||||
context.resources.getBoolean(R.bool.config_allow_edit_carrier_enabled)
|
|
||||||
)
|
|
||||||
// TODO: mIsCarrierIdApn
|
// TODO: mIsCarrierIdApn
|
||||||
return disableInit(apnDataInit)
|
return disableInit(apnDataInit)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* 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.content.Context
|
||||||
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.test.assertIsDisplayed
|
||||||
|
import androidx.compose.ui.test.assertIsEnabled
|
||||||
|
import androidx.compose.ui.test.assertIsNotEnabled
|
||||||
|
import androidx.compose.ui.test.assertIsOff
|
||||||
|
import androidx.compose.ui.test.assertIsOn
|
||||||
|
import androidx.compose.ui.test.junit4.ComposeTestRule
|
||||||
|
import androidx.compose.ui.test.junit4.createComposeRule
|
||||||
|
import androidx.compose.ui.test.onNodeWithText
|
||||||
|
import androidx.compose.ui.test.performClick
|
||||||
|
import androidx.test.core.app.ApplicationProvider
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
|
import com.android.settings.R
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Rule
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.mockito.kotlin.doReturn
|
||||||
|
import org.mockito.kotlin.spy
|
||||||
|
import org.mockito.kotlin.stub
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4::class)
|
||||||
|
class ApnEditCarrierEnabledTest {
|
||||||
|
|
||||||
|
@get:Rule val composeTestRule = createComposeRule()
|
||||||
|
|
||||||
|
private val context: Context = spy(ApplicationProvider.getApplicationContext()) {}
|
||||||
|
|
||||||
|
private val resources = spy(context.resources) {}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setUp() {
|
||||||
|
context.stub { on { resources } doReturn resources }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun carrierEnabled_displayed() {
|
||||||
|
composeTestRule.setContent { ApnEditCarrierEnabled(ApnData()) {} }
|
||||||
|
|
||||||
|
composeTestRule.onCarrierEnabled().assertIsDisplayed()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun carrierEnabled_isChecked() {
|
||||||
|
val apnData = ApnData(carrierEnabled = true)
|
||||||
|
|
||||||
|
composeTestRule.setContent { ApnEditCarrierEnabled(apnData) {} }
|
||||||
|
|
||||||
|
composeTestRule.onCarrierEnabled().assertIsOn()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun carrierEnabled_allowEdit_checkChanged() {
|
||||||
|
resources.stub { on { getBoolean(R.bool.config_allow_edit_carrier_enabled) } doReturn true }
|
||||||
|
var apnData by mutableStateOf(ApnData(carrierEnabled = true))
|
||||||
|
composeTestRule.setContent {
|
||||||
|
CompositionLocalProvider(LocalContext provides context) {
|
||||||
|
ApnEditCarrierEnabled(apnData) { apnData = apnData.copy(carrierEnabled = it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
composeTestRule.onCarrierEnabled().performClick()
|
||||||
|
|
||||||
|
composeTestRule.onCarrierEnabled().assertIsEnabled().assertIsOff()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun carrierEnabled_notAllowEdit_checkNotChanged() {
|
||||||
|
resources.stub {
|
||||||
|
on { getBoolean(R.bool.config_allow_edit_carrier_enabled) } doReturn false
|
||||||
|
}
|
||||||
|
var apnData by mutableStateOf(ApnData(carrierEnabled = true))
|
||||||
|
composeTestRule.setContent {
|
||||||
|
CompositionLocalProvider(LocalContext provides context) {
|
||||||
|
ApnEditCarrierEnabled(apnData) { apnData = apnData.copy(carrierEnabled = it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
composeTestRule.onCarrierEnabled().performClick()
|
||||||
|
|
||||||
|
composeTestRule.onCarrierEnabled().assertIsNotEnabled().assertIsOn()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun ComposeTestRule.onCarrierEnabled() =
|
||||||
|
onNodeWithText(context.getString(R.string.carrier_enabled))
|
||||||
|
}
|
||||||
@@ -21,24 +21,17 @@ import android.net.Uri
|
|||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.test.assertIsDisplayed
|
import androidx.compose.ui.test.assertIsDisplayed
|
||||||
import androidx.compose.ui.test.assertIsOff
|
|
||||||
import androidx.compose.ui.test.assertIsOn
|
|
||||||
import androidx.compose.ui.test.hasText
|
import androidx.compose.ui.test.hasText
|
||||||
import androidx.compose.ui.test.isFocused
|
|
||||||
import androidx.compose.ui.test.junit4.createComposeRule
|
import androidx.compose.ui.test.junit4.createComposeRule
|
||||||
import androidx.compose.ui.test.onAllNodesWithText
|
|
||||||
import androidx.compose.ui.test.onChild
|
import androidx.compose.ui.test.onChild
|
||||||
import androidx.compose.ui.test.onChildAt
|
import androidx.compose.ui.test.onChildAt
|
||||||
import androidx.compose.ui.test.onLast
|
|
||||||
import androidx.compose.ui.test.onNodeWithText
|
import androidx.compose.ui.test.onNodeWithText
|
||||||
import androidx.compose.ui.test.onRoot
|
import androidx.compose.ui.test.onRoot
|
||||||
import androidx.compose.ui.test.performClick
|
|
||||||
import androidx.compose.ui.test.performScrollToNode
|
import androidx.compose.ui.test.performScrollToNode
|
||||||
import androidx.test.core.app.ApplicationProvider
|
import androidx.test.core.app.ApplicationProvider
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
import com.android.settings.R
|
import com.android.settings.R
|
||||||
import com.google.common.truth.Truth
|
import com.google.common.truth.Truth
|
||||||
import org.junit.Ignore
|
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
@@ -55,7 +48,6 @@ class ApnEditPageProviderTest {
|
|||||||
private val port = "port"
|
private val port = "port"
|
||||||
private val apnType = context.resources.getString(R.string.apn_type)
|
private val apnType = context.resources.getString(R.string.apn_type)
|
||||||
private val apnRoaming = "IPv4"
|
private val apnRoaming = "IPv4"
|
||||||
private val apnEnable = context.resources.getString(R.string.carrier_enabled)
|
|
||||||
private val apnProtocolOptions =
|
private val apnProtocolOptions =
|
||||||
context.resources.getStringArray(R.array.apn_protocol_entries).toList()
|
context.resources.getStringArray(R.array.apn_protocol_entries).toList()
|
||||||
private val passwordTitle = context.resources.getString(R.string.apn_password)
|
private val passwordTitle = context.resources.getString(R.string.apn_password)
|
||||||
@@ -65,7 +57,6 @@ class ApnEditPageProviderTest {
|
|||||||
port = port,
|
port = port,
|
||||||
apnType = apnType,
|
apnType = apnType,
|
||||||
apnRoaming = apnProtocolOptions.indexOf(apnRoaming),
|
apnRoaming = apnProtocolOptions.indexOf(apnRoaming),
|
||||||
apnEnable = true
|
|
||||||
)
|
)
|
||||||
private val apnData = mutableStateOf(
|
private val apnData = mutableStateOf(
|
||||||
apnInit
|
apnInit
|
||||||
@@ -133,39 +124,6 @@ class ApnEditPageProviderTest {
|
|||||||
composeTestRule.onNodeWithText(apnRoaming, true).assertIsDisplayed()
|
composeTestRule.onNodeWithText(apnRoaming, true).assertIsDisplayed()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore("b/342374681")
|
|
||||||
@Test
|
|
||||||
fun carrier_enabled_displayed() {
|
|
||||||
composeTestRule.setContent {
|
|
||||||
ApnPage(apnInit, remember { apnData }, uri)
|
|
||||||
}
|
|
||||||
composeTestRule.onRoot().onChild().onChildAt(0)
|
|
||||||
.performScrollToNode(hasText(apnEnable, true))
|
|
||||||
composeTestRule.onNodeWithText(apnEnable, true).assertIsDisplayed()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun carrier_enabled_isChecked() {
|
|
||||||
composeTestRule.setContent {
|
|
||||||
ApnPage(apnInit, remember { apnData }, uri)
|
|
||||||
}
|
|
||||||
composeTestRule.onRoot().onChild().onChildAt(0)
|
|
||||||
.performScrollToNode(hasText(apnEnable, true))
|
|
||||||
composeTestRule.onNodeWithText(apnEnable, true).assertIsOn()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Ignore("b/342374681")
|
|
||||||
@Test
|
|
||||||
fun carrier_enabled_checkChanged() {
|
|
||||||
composeTestRule.setContent {
|
|
||||||
ApnPage(apnInit, remember { apnData }, uri)
|
|
||||||
}
|
|
||||||
composeTestRule.onRoot().onChild().onChildAt(0)
|
|
||||||
.performScrollToNode(hasText(apnEnable, true))
|
|
||||||
composeTestRule.onNodeWithText(apnEnable, true).performClick()
|
|
||||||
composeTestRule.onNodeWithText(apnEnable, true).assertIsOff()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun password_displayed() {
|
fun password_displayed() {
|
||||||
composeTestRule.setContent {
|
composeTestRule.setContent {
|
||||||
|
|||||||
Reference in New Issue
Block a user