Loading src/com/android/settings/spa/network/MobileDataSwitchPreference.kt +7 −7 Original line number Diff line number Diff line Loading @@ -26,8 +26,8 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.android.settings.R import com.android.settings.network.SatelliteRepository import com.android.settings.network.telephony.MobileDataRepository import com.android.settings.network.telephony.SubscriptionActivationRepository import com.android.settings.network.telephony.subscriptionManager import com.android.settingslib.spa.framework.compose.HighlightBox import com.android.settingslib.spa.framework.compose.rememberContext Loading @@ -51,7 +51,7 @@ fun MobileDataSwitchPreference(subId: Int) { MobileDataSwitchPreference( subId = subId, mobileDataRepository = rememberContext(::MobileDataRepository), subscriptionActivationRepository = rememberContext(::SubscriptionActivationRepository), satelliteRepository = rememberContext(::SatelliteRepository), setMobileData = setMobileDataImpl(subId), ) } Loading @@ -62,16 +62,16 @@ fun MobileDataSwitchPreference(subId: Int) { fun MobileDataSwitchPreference( subId: Int, mobileDataRepository: MobileDataRepository, subscriptionActivationRepository: SubscriptionActivationRepository, satelliteRepository: SatelliteRepository, setMobileData: (newChecked: Boolean) -> Unit, ) { val mobileDataSummary = stringResource(id = R.string.mobile_data_settings_summary) val isMobileDataEnabled by remember(subId) { mobileDataRepository.isMobileDataEnabledFlow(subId) } .collectAsStateWithLifecycle(initialValue = null) val changeable by remember { subscriptionActivationRepository.isActivationChangeableFlow() }.collectAsStateWithLifecycle(initialValue = true) val satelliteStarted by remember { satelliteRepository.getIsSessionStartedFlow() }.collectAsStateWithLifecycle(initialValue = false) SwitchPreference( object : SwitchPreferenceModel { override val title = stringResource(id = R.string.mobile_data_settings_title) Loading @@ -79,7 +79,7 @@ fun MobileDataSwitchPreference( override val checked = { isMobileDataEnabled } override val onCheckedChange = setMobileData override val changeable: () -> Boolean get() = { changeable } get() = { !satelliteStarted } } ) } Loading tests/spa_unit/src/com/android/settings/spa/network/MobileDataSwitchPreferenceTest.kt +14 −17 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ 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 com.android.settings.network.SatelliteRepository import com.android.settings.network.telephony.MobileDataRepository import com.android.settings.network.telephony.SubscriptionActivationRepository import com.google.common.truth.Truth.assertThat Loading @@ -52,10 +53,10 @@ class MobileDataSwitchPreferenceTest { private val mockMobileDataRepository = mock<MobileDataRepository> { on { isMobileDataEnabledFlow(any()) } doReturn emptyFlow() } private val mockSubscriptionActivationRepository = mock<SubscriptionActivationRepository> { on { isActivationChangeableFlow() } doReturn flowOf( true private val mockSatelliteRepository= mock<SatelliteRepository> { on { getIsSessionStartedFlow() } doReturn flowOf( false ) } Loading @@ -66,7 +67,7 @@ class MobileDataSwitchPreferenceTest { MobileDataSwitchPreference( SUB_ID, mockMobileDataRepository, mockSubscriptionActivationRepository mockSatelliteRepository ) {} } } Loading @@ -83,7 +84,7 @@ class MobileDataSwitchPreferenceTest { MobileDataSwitchPreference( SUB_ID, mockMobileDataRepository, mockSubscriptionActivationRepository mockSatelliteRepository ) {} } } Loading @@ -104,7 +105,7 @@ class MobileDataSwitchPreferenceTest { MobileDataSwitchPreference( SUB_ID, mockMobileDataRepository, mockSubscriptionActivationRepository mockSatelliteRepository ) { newCheckedCalled = it } Loading @@ -119,13 +120,13 @@ class MobileDataSwitchPreferenceTest { } @Test fun changeable_activationIsNotChangeable_notEnabled() { fun changeable_satelliteIsStarted_notEnabled() { mockMobileDataRepository.stub { on { isMobileDataEnabledFlow(SUB_ID) } doReturn flowOf(true) } mockSubscriptionActivationRepository.stub { on { isActivationChangeableFlow() } doReturn flowOf(false) mockSatelliteRepository.stub { on { getIsSessionStartedFlow() } doReturn flowOf(true) } composeTestRule.setContent { Loading @@ -133,7 +134,7 @@ class MobileDataSwitchPreferenceTest { MobileDataSwitchPreference( SUB_ID, mockMobileDataRepository, mockSubscriptionActivationRepository mockSatelliteRepository ) { } } Loading @@ -145,21 +146,17 @@ class MobileDataSwitchPreferenceTest { } @Test fun changeable_activationIsChangeable_enabled() { fun changeable_satelliteIsNotStarted_Changeable_enabled() { mockMobileDataRepository.stub { on { isMobileDataEnabledFlow(SUB_ID) } doReturn flowOf(true) } mockSubscriptionActivationRepository.stub { on { isActivationChangeableFlow() } doReturn flowOf(true) } composeTestRule.setContent { CompositionLocalProvider(LocalContext provides context) { MobileDataSwitchPreference( SUB_ID, mockMobileDataRepository, mockSubscriptionActivationRepository mockSatelliteRepository ) { } } Loading Loading
src/com/android/settings/spa/network/MobileDataSwitchPreference.kt +7 −7 Original line number Diff line number Diff line Loading @@ -26,8 +26,8 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.android.settings.R import com.android.settings.network.SatelliteRepository import com.android.settings.network.telephony.MobileDataRepository import com.android.settings.network.telephony.SubscriptionActivationRepository import com.android.settings.network.telephony.subscriptionManager import com.android.settingslib.spa.framework.compose.HighlightBox import com.android.settingslib.spa.framework.compose.rememberContext Loading @@ -51,7 +51,7 @@ fun MobileDataSwitchPreference(subId: Int) { MobileDataSwitchPreference( subId = subId, mobileDataRepository = rememberContext(::MobileDataRepository), subscriptionActivationRepository = rememberContext(::SubscriptionActivationRepository), satelliteRepository = rememberContext(::SatelliteRepository), setMobileData = setMobileDataImpl(subId), ) } Loading @@ -62,16 +62,16 @@ fun MobileDataSwitchPreference(subId: Int) { fun MobileDataSwitchPreference( subId: Int, mobileDataRepository: MobileDataRepository, subscriptionActivationRepository: SubscriptionActivationRepository, satelliteRepository: SatelliteRepository, setMobileData: (newChecked: Boolean) -> Unit, ) { val mobileDataSummary = stringResource(id = R.string.mobile_data_settings_summary) val isMobileDataEnabled by remember(subId) { mobileDataRepository.isMobileDataEnabledFlow(subId) } .collectAsStateWithLifecycle(initialValue = null) val changeable by remember { subscriptionActivationRepository.isActivationChangeableFlow() }.collectAsStateWithLifecycle(initialValue = true) val satelliteStarted by remember { satelliteRepository.getIsSessionStartedFlow() }.collectAsStateWithLifecycle(initialValue = false) SwitchPreference( object : SwitchPreferenceModel { override val title = stringResource(id = R.string.mobile_data_settings_title) Loading @@ -79,7 +79,7 @@ fun MobileDataSwitchPreference( override val checked = { isMobileDataEnabled } override val onCheckedChange = setMobileData override val changeable: () -> Boolean get() = { changeable } get() = { !satelliteStarted } } ) } Loading
tests/spa_unit/src/com/android/settings/spa/network/MobileDataSwitchPreferenceTest.kt +14 −17 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ 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 com.android.settings.network.SatelliteRepository import com.android.settings.network.telephony.MobileDataRepository import com.android.settings.network.telephony.SubscriptionActivationRepository import com.google.common.truth.Truth.assertThat Loading @@ -52,10 +53,10 @@ class MobileDataSwitchPreferenceTest { private val mockMobileDataRepository = mock<MobileDataRepository> { on { isMobileDataEnabledFlow(any()) } doReturn emptyFlow() } private val mockSubscriptionActivationRepository = mock<SubscriptionActivationRepository> { on { isActivationChangeableFlow() } doReturn flowOf( true private val mockSatelliteRepository= mock<SatelliteRepository> { on { getIsSessionStartedFlow() } doReturn flowOf( false ) } Loading @@ -66,7 +67,7 @@ class MobileDataSwitchPreferenceTest { MobileDataSwitchPreference( SUB_ID, mockMobileDataRepository, mockSubscriptionActivationRepository mockSatelliteRepository ) {} } } Loading @@ -83,7 +84,7 @@ class MobileDataSwitchPreferenceTest { MobileDataSwitchPreference( SUB_ID, mockMobileDataRepository, mockSubscriptionActivationRepository mockSatelliteRepository ) {} } } Loading @@ -104,7 +105,7 @@ class MobileDataSwitchPreferenceTest { MobileDataSwitchPreference( SUB_ID, mockMobileDataRepository, mockSubscriptionActivationRepository mockSatelliteRepository ) { newCheckedCalled = it } Loading @@ -119,13 +120,13 @@ class MobileDataSwitchPreferenceTest { } @Test fun changeable_activationIsNotChangeable_notEnabled() { fun changeable_satelliteIsStarted_notEnabled() { mockMobileDataRepository.stub { on { isMobileDataEnabledFlow(SUB_ID) } doReturn flowOf(true) } mockSubscriptionActivationRepository.stub { on { isActivationChangeableFlow() } doReturn flowOf(false) mockSatelliteRepository.stub { on { getIsSessionStartedFlow() } doReturn flowOf(true) } composeTestRule.setContent { Loading @@ -133,7 +134,7 @@ class MobileDataSwitchPreferenceTest { MobileDataSwitchPreference( SUB_ID, mockMobileDataRepository, mockSubscriptionActivationRepository mockSatelliteRepository ) { } } Loading @@ -145,21 +146,17 @@ class MobileDataSwitchPreferenceTest { } @Test fun changeable_activationIsChangeable_enabled() { fun changeable_satelliteIsNotStarted_Changeable_enabled() { mockMobileDataRepository.stub { on { isMobileDataEnabledFlow(SUB_ID) } doReturn flowOf(true) } mockSubscriptionActivationRepository.stub { on { isActivationChangeableFlow() } doReturn flowOf(true) } composeTestRule.setContent { CompositionLocalProvider(LocalContext provides context) { MobileDataSwitchPreference( SUB_ID, mockMobileDataRepository, mockSubscriptionActivationRepository mockSatelliteRepository ) { } } Loading