Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 98fa7185 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix Mobile data is disabled during in call." into main

parents e8bd411e a65e5c44
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -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
@@ -51,7 +51,7 @@ fun MobileDataSwitchPreference(subId: Int) {
        MobileDataSwitchPreference(
            subId = subId,
            mobileDataRepository = rememberContext(::MobileDataRepository),
            subscriptionActivationRepository = rememberContext(::SubscriptionActivationRepository),
            satelliteRepository = rememberContext(::SatelliteRepository),
            setMobileData = setMobileDataImpl(subId),
        )
    }
@@ -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)
@@ -79,7 +79,7 @@ fun MobileDataSwitchPreference(
            override val checked = { isMobileDataEnabled }
            override val onCheckedChange = setMobileData
            override val changeable: () -> Boolean
                get() = { changeable }
                get() = { !satelliteStarted }
        }
    )
}
+14 −17
Original line number Diff line number Diff line
@@ -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
@@ -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
            )
        }

@@ -66,7 +67,7 @@ class MobileDataSwitchPreferenceTest {
                MobileDataSwitchPreference(
                    SUB_ID,
                    mockMobileDataRepository,
                    mockSubscriptionActivationRepository
                    mockSatelliteRepository
                ) {}
            }
        }
@@ -83,7 +84,7 @@ class MobileDataSwitchPreferenceTest {
                MobileDataSwitchPreference(
                    SUB_ID,
                    mockMobileDataRepository,
                    mockSubscriptionActivationRepository
                    mockSatelliteRepository
                ) {}
            }
        }
@@ -104,7 +105,7 @@ class MobileDataSwitchPreferenceTest {
                MobileDataSwitchPreference(
                    SUB_ID,
                    mockMobileDataRepository,
                    mockSubscriptionActivationRepository
                    mockSatelliteRepository
                ) {
                    newCheckedCalled = it
                }
@@ -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 {
@@ -133,7 +134,7 @@ class MobileDataSwitchPreferenceTest {
                MobileDataSwitchPreference(
                    SUB_ID,
                    mockMobileDataRepository,
                    mockSubscriptionActivationRepository
                    mockSatelliteRepository
                ) {
                }
            }
@@ -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
                ) {
                }
            }