diff options
| author | 2023-03-20 20:22:24 +0000 | |
|---|---|---|
| committer | 2023-03-24 18:58:42 +0000 | |
| commit | d7e5678a62213ac763b77988f32f2bfb17feab73 (patch) | |
| tree | fffd0deee07e45a3f01958e0a36004952ac11175 | |
| parent | 6ea1cc21f8f51dd2d7d775d6dde4df4da4114dc4 (diff) | |
[SB Refactor] Split out mobile's default information into two flows.
`defaultMobileConnectivity.isConnected` sounds like it means "is the
default mobile subscription connected?", when it actually means "is the
default connection a mobile one?". This CL splits out the
`defaultMobileNetworkConnectivity` flow into two flows with more
descriptive names.
Bug: 272586234
Test: all tests in mobile directory
Change-Id: Ie8d492c5983ce32bf22a0bca6d682a8b5cccf520
16 files changed, 237 insertions, 414 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/model/MobileConnectivityModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/model/MobileConnectivityModel.kt deleted file mode 100644 index 97a537ac0ce6..000000000000 --- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/model/MobileConnectivityModel.kt +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2022 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.systemui.statusbar.pipeline.mobile.data.model - -import android.net.NetworkCapabilities -import com.android.systemui.log.table.Diffable -import com.android.systemui.log.table.TableRowLogger - -/** Provides information about a mobile network connection */ -data class MobileConnectivityModel( - /** Whether mobile is the connected transport see [NetworkCapabilities.TRANSPORT_CELLULAR] */ - val isConnected: Boolean = false, - /** Whether the mobile transport is validated [NetworkCapabilities.NET_CAPABILITY_VALIDATED] */ - val isValidated: Boolean = false, -) : Diffable<MobileConnectivityModel> { - // TODO(b/267767715): Can we implement [logDiffs] and [logFull] generically for data classes? - override fun logDiffs(prevVal: MobileConnectivityModel, row: TableRowLogger) { - if (prevVal.isConnected != isConnected) { - row.logChange(COL_IS_CONNECTED, isConnected) - } - if (prevVal.isValidated != isValidated) { - row.logChange(COL_IS_VALIDATED, isValidated) - } - } - - override fun logFull(row: TableRowLogger) { - row.logChange(COL_IS_CONNECTED, isConnected) - row.logChange(COL_IS_VALIDATED, isValidated) - } - - companion object { - private const val COL_IS_CONNECTED = "isConnected" - private const val COL_IS_VALIDATED = "isValidated" - } -} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileConnectionsRepository.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileConnectionsRepository.kt index be30ea422bb6..fa712872eb13 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileConnectionsRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileConnectionsRepository.kt @@ -21,7 +21,6 @@ import android.telephony.SubscriptionManager import com.android.settingslib.SignalIcon.MobileIconGroup import com.android.settingslib.mobile.MobileMappings import com.android.settingslib.mobile.MobileMappings.Config -import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectivityModel import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.StateFlow @@ -52,8 +51,17 @@ interface MobileConnectionsRepository { /** Tracks [SubscriptionManager.getDefaultDataSubscriptionId] */ val defaultDataSubId: StateFlow<Int> - /** The current connectivity status for the default mobile network connection */ - val defaultMobileNetworkConnectivity: StateFlow<MobileConnectivityModel> + /** + * True if the default network connection is a mobile-like connection and false otherwise. + * + * This is typically shown by having [android.net.NetworkCapabilities.TRANSPORT_CELLULAR], but + * there are edge cases (like carrier merged wifi) that could also result in the default + * connection being mobile-like. + */ + val mobileIsDefault: StateFlow<Boolean> + + /** True if the default network connection is validated and false otherwise. */ + val defaultConnectionIsValidated: StateFlow<Boolean> /** Get or create a repository for the line of service for the given subscription ID */ fun getRepoForSubId(subId: Int): MobileConnectionRepository diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileRepositorySwitcher.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileRepositorySwitcher.kt index d54531a8370f..44b5b3fa2591 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileRepositorySwitcher.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileRepositorySwitcher.kt @@ -24,7 +24,6 @@ import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCall import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.demomode.DemoMode import com.android.systemui.demomode.DemoModeController -import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectivityModel import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel import com.android.systemui.statusbar.pipeline.mobile.data.repository.demo.DemoMobileConnectionsRepository import com.android.systemui.statusbar.pipeline.mobile.data.repository.prod.MobileConnectionsRepositoryImpl @@ -155,13 +154,18 @@ constructor( .flatMapLatest { it.defaultDataSubId } .stateIn(scope, SharingStarted.WhileSubscribed(), realRepository.defaultDataSubId.value) - override val defaultMobileNetworkConnectivity: StateFlow<MobileConnectivityModel> = + override val mobileIsDefault: StateFlow<Boolean> = activeRepo - .flatMapLatest { it.defaultMobileNetworkConnectivity } + .flatMapLatest { it.mobileIsDefault } + .stateIn(scope, SharingStarted.WhileSubscribed(), realRepository.mobileIsDefault.value) + + override val defaultConnectionIsValidated: StateFlow<Boolean> = + activeRepo + .flatMapLatest { it.defaultConnectionIsValidated } .stateIn( scope, SharingStarted.WhileSubscribed(), - realRepository.defaultMobileNetworkConnectivity.value + realRepository.defaultConnectionIsValidated.value ) override fun getRepoForSubId(subId: Int): MobileConnectionRepository { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionsRepository.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionsRepository.kt index 3cafb7377260..737bc6826d08 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionsRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionsRepository.kt @@ -24,7 +24,6 @@ import com.android.settingslib.mobile.MobileMappings import com.android.settingslib.mobile.TelephonyIcons import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.log.table.TableLogBufferFactory -import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectivityModel import com.android.systemui.statusbar.pipeline.mobile.data.model.ResolvedNetworkType import com.android.systemui.statusbar.pipeline.mobile.data.model.ResolvedNetworkType.DefaultNetworkType import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel @@ -158,8 +157,10 @@ constructor( override val defaultDataSubId = MutableStateFlow(INVALID_SUBSCRIPTION_ID) // TODO(b/261029387): not yet supported - override val defaultMobileNetworkConnectivity = - MutableStateFlow(MobileConnectivityModel(isConnected = true, isValidated = true)) + override val mobileIsDefault: StateFlow<Boolean> = MutableStateFlow(true) + + // TODO(b/261029387): not yet supported + override val defaultConnectionIsValidated: StateFlow<Boolean> = MutableStateFlow(true) override fun getRepoForSubId(subId: Int): DemoMobileConnectionRepository { val current = connectionRepoCache[subId]?.repo diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryImpl.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryImpl.kt index 991b7868439a..a6fa0c55888d 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryImpl.kt @@ -46,7 +46,6 @@ import com.android.systemui.log.table.TableLogBuffer import com.android.systemui.log.table.logDiffsForTable import com.android.systemui.statusbar.pipeline.dagger.MobileSummaryLog import com.android.systemui.statusbar.pipeline.mobile.data.MobileInputLogger -import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectivityModel import com.android.systemui.statusbar.pipeline.mobile.data.model.NetworkNameModel import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionsRepository @@ -262,15 +261,18 @@ constructor( ?: createRepositoryForSubId(subId).also { subIdRepositoryCache[subId] = it } @SuppressLint("MissingPermission") - override val defaultMobileNetworkConnectivity: StateFlow<MobileConnectivityModel> = + private val defaultMobileNetworkConnectivity: StateFlow<DefaultConnectionModel> = conflatedCallbackFlow { val callback = object : NetworkCallback(FLAG_INCLUDE_LOCATION_INFO) { override fun onLost(network: Network) { logger.logOnLost(network, isDefaultNetworkCallback = true) - // Send a disconnected model when lost. Maybe should create a sealed - // type or null here? - trySend(MobileConnectivityModel()) + trySend( + DefaultConnectionModel( + mobileIsDefault = false, + defaultConnectionIsValidated = false, + ) + ) } override fun onCapabilitiesChanged( @@ -283,9 +285,10 @@ constructor( isDefaultNetworkCallback = true, ) trySend( - MobileConnectivityModel( - isConnected = caps.hasTransport(TRANSPORT_CELLULAR), - isValidated = caps.hasCapability(NET_CAPABILITY_VALIDATED), + DefaultConnectionModel( + mobileIsDefault = caps.hasTransport(TRANSPORT_CELLULAR), + defaultConnectionIsValidated = + caps.hasCapability(NET_CAPABILITY_VALIDATED), ) ) } @@ -296,12 +299,31 @@ constructor( awaitClose { connectivityManager.unregisterNetworkCallback(callback) } } .distinctUntilChanged() + .stateIn(scope, SharingStarted.WhileSubscribed(), DefaultConnectionModel()) + + override val mobileIsDefault: StateFlow<Boolean> = + defaultMobileNetworkConnectivity + .map { it.mobileIsDefault } + .distinctUntilChanged() .logDiffsForTable( tableLogger, - columnPrefix = "$LOGGING_PREFIX.defaultConnection", - initialValue = MobileConnectivityModel(), + columnPrefix = "", + columnName = "mobileIsDefault", + initialValue = false, ) - .stateIn(scope, SharingStarted.WhileSubscribed(), MobileConnectivityModel()) + .stateIn(scope, SharingStarted.WhileSubscribed(), false) + + override val defaultConnectionIsValidated: StateFlow<Boolean> = + defaultMobileNetworkConnectivity + .map { it.defaultConnectionIsValidated } + .distinctUntilChanged() + .logDiffsForTable( + tableLogger, + columnPrefix = "", + columnName = "defaultConnectionIsValidated", + initialValue = false, + ) + .stateIn(scope, SharingStarted.WhileSubscribed(), false) /** * Flow that tracks the active mobile data subscriptions. Emits `true` whenever the active data @@ -385,6 +407,11 @@ constructor( groupUuid = groupUuid, ) + private data class DefaultConnectionModel( + val mobileIsDefault: Boolean = false, + val defaultConnectionIsValidated: Boolean = false, + ) + companion object { private const val LOGGING_PREFIX = "Repo" } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractor.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractor.kt index 7df6764fda1a..22351f8b2821 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractor.kt @@ -22,7 +22,6 @@ import com.android.settingslib.mobile.TelephonyIcons.NOT_DEFAULT_DATA import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.log.table.TableLogBuffer import com.android.systemui.statusbar.pipeline.mobile.data.model.DataConnectionState.Connected -import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectivityModel import com.android.systemui.statusbar.pipeline.mobile.data.model.NetworkNameModel import com.android.systemui.statusbar.pipeline.mobile.data.model.ResolvedNetworkType import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionRepository @@ -46,17 +45,8 @@ interface MobileIconInteractor { /** The current mobile data activity */ val activity: Flow<DataActivityModel> - /** - * This bit is meant to be `true` if and only if the default network capabilities (see - * [android.net.ConnectivityManager.registerDefaultNetworkCallback]) result in a network that - * has the [android.net.NetworkCapabilities.TRANSPORT_CELLULAR] represented. - * - * Note that this differs from [isDataConnected], which is tracked by telephony and has to do - * with the state of using this mobile connection for data as opposed to just voice. It is - * possible for a mobile subscription to be connected but not be in a connected data state, and - * thus we wouldn't want to show the network type icon. - */ - val isConnected: Flow<Boolean> + /** See [MobileConnectionsRepository.mobileIsDefault]. */ + val mobileIsDefault: Flow<Boolean> /** * True when telephony tells us that the data state is CONNECTED. See @@ -126,7 +116,7 @@ class MobileIconInteractorImpl( defaultSubscriptionHasDataEnabled: StateFlow<Boolean>, override val alwaysShowDataRatIcon: StateFlow<Boolean>, override val alwaysUseCdmaLevel: StateFlow<Boolean>, - defaultMobileConnectivity: StateFlow<MobileConnectivityModel>, + override val mobileIsDefault: StateFlow<Boolean>, defaultMobileIconMapping: StateFlow<Map<String, MobileIconGroup>>, defaultMobileIconGroup: StateFlow<MobileIconGroup>, defaultDataSubId: StateFlow<Int>, @@ -138,8 +128,6 @@ class MobileIconInteractorImpl( override val activity = connectionRepository.dataActivityDirection - override val isConnected: Flow<Boolean> = defaultMobileConnectivity.mapLatest { it.isConnected } - override val isDataEnabled: StateFlow<Boolean> = connectionRepository.dataEnabled private val isDefault = diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconsInteractor.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconsInteractor.kt index f4b6e55ebbba..6c8310ac3d29 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconsInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconsInteractor.kt @@ -25,7 +25,6 @@ import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.log.table.TableLogBuffer import com.android.systemui.log.table.logDiffsForTable import com.android.systemui.statusbar.pipeline.dagger.MobileSummaryLog -import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectivityModel import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionRepository import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionsRepository @@ -61,8 +60,12 @@ import kotlinx.coroutines.flow.transformLatest * icon */ interface MobileIconsInteractor { + /** See [MobileConnectionsRepository.mobileIsDefault]. */ + val mobileIsDefault: StateFlow<Boolean> + /** List of subscriptions, potentially filtered for CBRS */ val filteredSubscriptions: Flow<List<SubscriptionModel>> + /** True if the active mobile data subscription has data enabled */ val activeDataConnectionHasDataEnabled: StateFlow<Boolean> @@ -75,20 +78,15 @@ interface MobileIconsInteractor { /** Tracks the subscriptionId set as the default for data connections */ val defaultDataSubId: StateFlow<Int> - /** - * The connectivity of the default mobile network. Note that this can differ from what is - * reported from [MobileConnectionsRepository] in some cases. E.g., when the active subscription - * changes but the groupUuid remains the same, we keep the old validation information for 2 - * seconds to avoid icon flickering. - */ - val defaultMobileNetworkConnectivity: StateFlow<MobileConnectivityModel> - /** The icon mapping from network type to [MobileIconGroup] for the default subscription */ val defaultMobileIconMapping: StateFlow<Map<String, MobileIconGroup>> + /** Fallback [MobileIconGroup] in the case where there is no icon in the mapping */ val defaultMobileIconGroup: StateFlow<MobileIconGroup> + /** True only if the default network is mobile, and validation also failed */ val isDefaultConnectionFailed: StateFlow<Boolean> + /** True once the user has been set up */ val isUserSetup: StateFlow<Boolean> @@ -115,6 +113,9 @@ constructor( userSetupRepo: UserSetupRepository, @Application private val scope: CoroutineScope, ) : MobileIconsInteractor { + + override val mobileIsDefault = mobileConnectionsRepo.mobileIsDefault + override val activeDataConnectionHasDataEnabled: StateFlow<Boolean> = mobileConnectionsRepo.activeMobileDataRepository .flatMapLatest { it?.dataEnabled ?: flowOf(false) } @@ -197,7 +198,7 @@ constructor( */ private val forcingCellularValidation = mobileConnectionsRepo.activeSubChangedInGroupEvent - .filter { mobileConnectionsRepo.defaultMobileNetworkConnectivity.value.isValidated } + .filter { mobileConnectionsRepo.defaultConnectionIsValidated.value } .transformLatest { emit(true) delay(2000) @@ -211,32 +212,6 @@ constructor( ) .stateIn(scope, SharingStarted.WhileSubscribed(), false) - override val defaultMobileNetworkConnectivity: StateFlow<MobileConnectivityModel> = - combine( - mobileConnectionsRepo.defaultMobileNetworkConnectivity, - forcingCellularValidation, - ) { networkConnectivity, forceValidation -> - return@combine if (forceValidation) { - MobileConnectivityModel( - isValidated = true, - isConnected = networkConnectivity.isConnected - ) - } else { - networkConnectivity - } - } - .distinctUntilChanged() - .logDiffsForTable( - tableLogger, - columnPrefix = "$LOGGING_PREFIX.defaultConnection", - initialValue = mobileConnectionsRepo.defaultMobileNetworkConnectivity.value, - ) - .stateIn( - scope, - SharingStarted.WhileSubscribed(), - mobileConnectionsRepo.defaultMobileNetworkConnectivity.value - ) - /** * Mapping from network type to [MobileIconGroup] using the config generated for the default * subscription Id. This mapping is the same for every subscription. @@ -271,12 +246,15 @@ constructor( * other transport type is active, because then we expect there not to be validation. */ override val isDefaultConnectionFailed: StateFlow<Boolean> = - defaultMobileNetworkConnectivity - .mapLatest { connectivityModel -> - if (!connectivityModel.isConnected) { - false - } else { - !connectivityModel.isValidated + combine( + mobileConnectionsRepo.mobileIsDefault, + mobileConnectionsRepo.defaultConnectionIsValidated, + forcingCellularValidation, + ) { mobileIsDefault, defaultConnectionIsValidated, forcingCellularValidation -> + when { + !mobileIsDefault -> false + forcingCellularValidation -> false + else -> !defaultConnectionIsValidated } } .logDiffsForTable( @@ -301,7 +279,7 @@ constructor( activeDataConnectionHasDataEnabled, alwaysShowDataRatIcon, alwaysUseCdmaLevel, - defaultMobileNetworkConnectivity, + mobileIsDefault, defaultMobileIconMapping, defaultMobileIconGroup, defaultDataSubId, diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/viewmodel/MobileIconViewModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/viewmodel/MobileIconViewModel.kt index dbb534b24471..0fd007cf40ef 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/viewmodel/MobileIconViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/viewmodel/MobileIconViewModel.kt @@ -148,9 +148,9 @@ constructor( iconInteractor.isDataEnabled, iconInteractor.isDefaultConnectionFailed, iconInteractor.alwaysShowDataRatIcon, - iconInteractor.isConnected, - ) { dataConnected, dataEnabled, failedConnection, alwaysShow, connected -> - alwaysShow || (dataConnected && dataEnabled && !failedConnection && connected) + iconInteractor.mobileIsDefault, + ) { dataConnected, dataEnabled, failedConnection, alwaysShow, mobileIsDefault -> + alwaysShow || (dataConnected && dataEnabled && !failedConnection && mobileIsDefault) } .distinctUntilChanged() .logDiffsForTable( diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/FakeMobileConnectionsRepository.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/FakeMobileConnectionsRepository.kt index f483e42056f3..f9c72d523673 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/FakeMobileConnectionsRepository.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/FakeMobileConnectionsRepository.kt @@ -23,7 +23,6 @@ import com.android.settingslib.SignalIcon import com.android.settingslib.mobile.MobileMappings import com.android.settingslib.mobile.TelephonyIcons import com.android.systemui.log.table.TableLogBuffer -import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectivityModel import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel import com.android.systemui.statusbar.pipeline.mobile.util.MobileMappingsProxy import kotlinx.coroutines.flow.MutableSharedFlow @@ -66,8 +65,9 @@ class FakeMobileConnectionsRepository( private val _defaultDataSubId = MutableStateFlow(INVALID_SUBSCRIPTION_ID) override val defaultDataSubId = _defaultDataSubId - private val _mobileConnectivity = MutableStateFlow(MobileConnectivityModel()) - override val defaultMobileNetworkConnectivity = _mobileConnectivity + override val mobileIsDefault = MutableStateFlow(false) + + override val defaultConnectionIsValidated = MutableStateFlow(false) private val subIdRepos = mutableMapOf<Int, MobileConnectionRepository>() @@ -88,14 +88,6 @@ class FakeMobileConnectionsRepository( _subscriptions.value = subs } - fun setDefaultDataSubId(id: Int) { - _defaultDataSubId.value = id - } - - fun setMobileConnectivity(model: MobileConnectivityModel) { - _mobileConnectivity.value = model - } - fun setActiveMobileDataSubscriptionId(subId: Int) { // Simulate the filtering that the repo does if (subId == INVALID_SUBSCRIPTION_ID) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionsRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionsRepositoryTest.kt index 0e45d8ea5563..47f8cd319bff 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionsRepositoryTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionsRepositoryTest.kt @@ -91,11 +91,17 @@ class DemoMobileConnectionsRepositoryTest : SysuiTestCase() { } @Test - fun `connectivity - defaults to connected and validated`() = + fun isDefault_defaultsToTrue() = testScope.runTest { - val connectivity = underTest.defaultMobileNetworkConnectivity.value - assertThat(connectivity.isConnected).isTrue() - assertThat(connectivity.isValidated).isTrue() + val isDefault = underTest.mobileIsDefault.value + assertThat(isDefault).isTrue() + } + + @Test + fun validated_defaultsToTrue() = + testScope.runTest { + val isValidated = underTest.defaultConnectionIsValidated.value + assertThat(isValidated).isTrue() } @Test diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryTest.kt index 68b1cda62f4c..742abc273c8d 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryTest.kt @@ -38,7 +38,6 @@ import com.android.systemui.SysuiTestCase import com.android.systemui.log.table.TableLogBuffer import com.android.systemui.log.table.TableLogBufferFactory import com.android.systemui.statusbar.pipeline.mobile.data.MobileInputLogger -import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectivityModel import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel import com.android.systemui.statusbar.pipeline.mobile.data.repository.CarrierConfigRepository import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionRepository @@ -668,75 +667,83 @@ class MobileConnectionsRepositoryTest : SysuiTestCase() { } @Test - fun mobileConnectivity_default() { - assertThat(underTest.defaultMobileNetworkConnectivity.value) - .isEqualTo(MobileConnectivityModel(isConnected = false, isValidated = false)) + fun mobileIsDefault_startsAsFalse() { + assertThat(underTest.mobileIsDefault.value).isFalse() } @Test - fun mobileConnectivity_isConnected_isValidated() = + fun mobileIsDefault_capsHaveCellular_isDefault() = runBlocking(IMMEDIATE) { - val caps = createCapabilities(connected = true, validated = true) + val caps = + mock<NetworkCapabilities>().also { + whenever(it.hasTransport(TRANSPORT_CELLULAR)).thenReturn(true) + } - var latest: MobileConnectivityModel? = null - val job = - underTest.defaultMobileNetworkConnectivity.onEach { latest = it }.launchIn(this) + var latest: Boolean? = null + val job = underTest.mobileIsDefault.onEach { latest = it }.launchIn(this) getDefaultNetworkCallback().onCapabilitiesChanged(NETWORK, caps) - assertThat(latest) - .isEqualTo(MobileConnectivityModel(isConnected = true, isValidated = true)) + assertThat(latest).isTrue() job.cancel() } @Test - fun mobileConnectivity_isConnected_isNotValidated() = + fun mobileIsDefault_capsDoNotHaveCellular_isNotDefault() = runBlocking(IMMEDIATE) { - val caps = createCapabilities(connected = true, validated = false) + val caps = + mock<NetworkCapabilities>().also { + whenever(it.hasTransport(TRANSPORT_CELLULAR)).thenReturn(false) + } - var latest: MobileConnectivityModel? = null - val job = - underTest.defaultMobileNetworkConnectivity.onEach { latest = it }.launchIn(this) + var latest: Boolean? = null + val job = underTest.mobileIsDefault.onEach { latest = it }.launchIn(this) getDefaultNetworkCallback().onCapabilitiesChanged(NETWORK, caps) - assertThat(latest) - .isEqualTo(MobileConnectivityModel(isConnected = true, isValidated = false)) + assertThat(latest).isFalse() job.cancel() } @Test - fun mobileConnectivity_isNotConnected_isNotValidated() = + fun defaultConnectionIsValidated_startsAsFalse() { + assertThat(underTest.defaultConnectionIsValidated.value).isFalse() + } + + @Test + fun defaultConnectionIsValidated_capsHaveValidated_isValidated() = runBlocking(IMMEDIATE) { - val caps = createCapabilities(connected = false, validated = false) + val caps = + mock<NetworkCapabilities>().also { + whenever(it.hasCapability(NET_CAPABILITY_VALIDATED)).thenReturn(true) + } - var latest: MobileConnectivityModel? = null - val job = - underTest.defaultMobileNetworkConnectivity.onEach { latest = it }.launchIn(this) + var latest: Boolean? = null + val job = underTest.defaultConnectionIsValidated.onEach { latest = it }.launchIn(this) getDefaultNetworkCallback().onCapabilitiesChanged(NETWORK, caps) - assertThat(latest) - .isEqualTo(MobileConnectivityModel(isConnected = false, isValidated = false)) + assertThat(latest).isTrue() job.cancel() } - /** In practice, I don't think this state can ever happen (!connected, validated) */ @Test - fun mobileConnectivity_isNotConnected_isValidated() = + fun defaultConnectionIsValidated_capsHaveNotValidated_isNotValidated() = runBlocking(IMMEDIATE) { - val caps = createCapabilities(connected = false, validated = true) + val caps = + mock<NetworkCapabilities>().also { + whenever(it.hasCapability(NET_CAPABILITY_VALIDATED)).thenReturn(false) + } - var latest: MobileConnectivityModel? = null - val job = - underTest.defaultMobileNetworkConnectivity.onEach { latest = it }.launchIn(this) + var latest: Boolean? = null + val job = underTest.defaultConnectionIsValidated.onEach { latest = it }.launchIn(this) getDefaultNetworkCallback().onCapabilitiesChanged(NETWORK, caps) - assertThat(latest).isEqualTo(MobileConnectivityModel(false, true)) + assertThat(latest).isFalse() job.cancel() } @@ -860,12 +867,6 @@ class MobileConnectionsRepositoryTest : SysuiTestCase() { job.cancel() } - private fun createCapabilities(connected: Boolean, validated: Boolean): NetworkCapabilities = - mock<NetworkCapabilities>().also { - whenever(it.hasTransport(TRANSPORT_CELLULAR)).thenReturn(connected) - whenever(it.hasCapability(NET_CAPABILITY_VALIDATED)).thenReturn(validated) - } - private fun getDefaultNetworkCallback(): ConnectivityManager.NetworkCallback { val callbackCaptor = argumentCaptor<ConnectivityManager.NetworkCallback>() verify(connectivityManager).registerDefaultNetworkCallback(callbackCaptor.capture()) diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/FakeMobileIconInteractor.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/FakeMobileIconInteractor.kt index b645e667e183..8d2c5695c7c4 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/FakeMobileIconInteractor.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/FakeMobileIconInteractor.kt @@ -40,7 +40,7 @@ class FakeMobileIconInteractor( ) ) - override val isConnected = MutableStateFlow(true) + override val mobileIsDefault = MutableStateFlow(true) private val _iconGroup = MutableStateFlow<SignalIcon.MobileIconGroup>(TelephonyIcons.THREE_G) override val networkTypeIconGroup = _iconGroup diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/FakeMobileIconsInteractor.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/FakeMobileIconsInteractor.kt index 2699316d1b0b..d6fdad417b31 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/FakeMobileIconsInteractor.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/FakeMobileIconsInteractor.kt @@ -23,7 +23,6 @@ import android.telephony.TelephonyManager.NETWORK_TYPE_UMTS import com.android.settingslib.SignalIcon.MobileIconGroup import com.android.settingslib.mobile.TelephonyIcons import com.android.systemui.log.table.TableLogBuffer -import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectivityModel import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel import com.android.systemui.statusbar.pipeline.mobile.util.MobileMappingsProxy import kotlinx.coroutines.flow.MutableStateFlow @@ -62,7 +61,7 @@ class FakeMobileIconsInteractor( override val alwaysUseCdmaLevel = MutableStateFlow(false) override val defaultDataSubId = MutableStateFlow(DEFAULT_DATA_SUB_ID) - override val defaultMobileNetworkConnectivity = MutableStateFlow(MobileConnectivityModel()) + override val mobileIsDefault = MutableStateFlow(false) private val _defaultMobileIconMapping = MutableStateFlow(TEST_MAPPING) override val defaultMobileIconMapping = _defaultMobileIconMapping diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractorTest.kt index 1eb1056204cd..2054e8b12eff 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractorTest.kt @@ -60,7 +60,7 @@ class MobileIconInteractorTest : SysuiTestCase() { mobileIconsInteractor.activeDataConnectionHasDataEnabled, mobileIconsInteractor.alwaysShowDataRatIcon, mobileIconsInteractor.alwaysUseCdmaLevel, - mobileIconsInteractor.defaultMobileNetworkConnectivity, + mobileIconsInteractor.mobileIsDefault, mobileIconsInteractor.defaultMobileIconMapping, mobileIconsInteractor.defaultMobileIconGroup, mobileIconsInteractor.defaultDataSubId, diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconsInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconsInteractorTest.kt index 77e7cf202567..898e89770394 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconsInteractorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconsInteractorTest.kt @@ -22,7 +22,6 @@ import androidx.test.filters.SmallTest import com.android.settingslib.mobile.MobileMappings import com.android.systemui.SysuiTestCase import com.android.systemui.log.table.TableLogBuffer -import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectivityModel import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel import com.android.systemui.statusbar.pipeline.mobile.data.repository.FakeMobileConnectionRepository import com.android.systemui.statusbar.pipeline.mobile.data.repository.FakeMobileConnectionsRepository @@ -307,11 +306,13 @@ class MobileIconsInteractorTest : SysuiTestCase() { } @Test - fun failedConnection_connected_validated_notFailed() = + fun failedConnection_default_validated_notFailed() = testScope.runTest { var latest: Boolean? = null val job = underTest.isDefaultConnectionFailed.onEach { latest = it }.launchIn(this) - connectionsRepository.setMobileConnectivity(MobileConnectivityModel(true, true)) + + connectionsRepository.mobileIsDefault.value = true + connectionsRepository.defaultConnectionIsValidated.value = true yield() assertThat(latest).isFalse() @@ -320,12 +321,13 @@ class MobileIconsInteractorTest : SysuiTestCase() { } @Test - fun failedConnection_notConnected_notValidated_notFailed() = + fun failedConnection_notDefault_notValidated_notFailed() = testScope.runTest { var latest: Boolean? = null val job = underTest.isDefaultConnectionFailed.onEach { latest = it }.launchIn(this) - connectionsRepository.setMobileConnectivity(MobileConnectivityModel(false, false)) + connectionsRepository.mobileIsDefault.value = false + connectionsRepository.defaultConnectionIsValidated.value = false yield() assertThat(latest).isFalse() @@ -334,12 +336,13 @@ class MobileIconsInteractorTest : SysuiTestCase() { } @Test - fun failedConnection_connected_notValidated_failed() = + fun failedConnection_default_notValidated_failed() = testScope.runTest { var latest: Boolean? = null val job = underTest.isDefaultConnectionFailed.onEach { latest = it }.launchIn(this) - connectionsRepository.setMobileConnectivity(MobileConnectivityModel(true, false)) + connectionsRepository.mobileIsDefault.value = true + connectionsRepository.defaultConnectionIsValidated.value = false yield() assertThat(latest).isTrue() @@ -352,25 +355,14 @@ class MobileIconsInteractorTest : SysuiTestCase() { fun failedConnection_dataSwitchInSameGroup_notFailed() = testScope.runTest { var latest: Boolean? = null - val job = - underTest.isDefaultConnectionFailed.onEach { latest = it }.launchIn(this) + val job = underTest.isDefaultConnectionFailed.onEach { latest = it }.launchIn(this) - connectionsRepository.setMobileConnectivity( - MobileConnectivityModel( - isConnected = true, - isValidated = true, - ) - ) + connectionsRepository.mobileIsDefault.value = true + connectionsRepository.defaultConnectionIsValidated.value = true // WHEN there's a data change in the same subscription group connectionsRepository.activeSubChangedInGroupEvent.emit(Unit) - connectionsRepository.setMobileConnectivity( - MobileConnectivityModel( - // Keep the connection as connected, just not validated - isConnected = true, - isValidated = false, - ) - ) + connectionsRepository.defaultConnectionIsValidated.value = false // THEN the default connection is *not* marked as failed because of forced validation assertThat(latest).isFalse() @@ -379,6 +371,26 @@ class MobileIconsInteractorTest : SysuiTestCase() { } @Test + fun failedConnection_dataSwitchNotInSameGroup_isFailed() = + testScope.runTest { + var latestConnectionFailed: Boolean? = null + val job = + underTest.isDefaultConnectionFailed + .onEach { latestConnectionFailed = it } + .launchIn(this) + connectionsRepository.mobileIsDefault.value = true + connectionsRepository.defaultConnectionIsValidated.value = true + + // WHEN the connection is invalidated without a activeSubChangedInGroupEvent + connectionsRepository.defaultConnectionIsValidated.value = false + + // THEN the connection is immediately marked as failed + assertThat(latestConnectionFailed).isTrue() + + job.cancel() + } + + @Test fun alwaysShowDataRatIcon_configHasTrue() = testScope.runTest { var latest: Boolean? = null @@ -443,137 +455,69 @@ class MobileIconsInteractorTest : SysuiTestCase() { } @Test - fun `default mobile connectivity - uses repo value`() = + fun mobileIsDefault_usesRepoValue() = testScope.runTest { - var latest: MobileConnectivityModel? = null - val job = - underTest.defaultMobileNetworkConnectivity.onEach { latest = it }.launchIn(this) - - var expected = MobileConnectivityModel(isConnected = true, isValidated = true) - connectionsRepository.setMobileConnectivity(expected) - assertThat(latest).isEqualTo(expected) + var latest: Boolean? = null + val job = underTest.mobileIsDefault.onEach { latest = it }.launchIn(this) - expected = MobileConnectivityModel(isConnected = false, isValidated = true) - connectionsRepository.setMobileConnectivity(expected) - assertThat(latest).isEqualTo(expected) + connectionsRepository.mobileIsDefault.value = true + assertThat(latest).isTrue() - expected = MobileConnectivityModel(isConnected = true, isValidated = false) - connectionsRepository.setMobileConnectivity(expected) - assertThat(latest).isEqualTo(expected) + connectionsRepository.mobileIsDefault.value = false + assertThat(latest).isFalse() - expected = MobileConnectivityModel(isConnected = false, isValidated = false) - connectionsRepository.setMobileConnectivity(expected) - assertThat(latest).isEqualTo(expected) + connectionsRepository.mobileIsDefault.value = true + assertThat(latest).isTrue() job.cancel() } - @Test - fun `data switch - in same group - validated matches previous value`() = - testScope.runTest { - var latest: MobileConnectivityModel? = null - val job = - underTest.defaultMobileNetworkConnectivity.onEach { latest = it }.launchIn(this) - - connectionsRepository.setMobileConnectivity( - MobileConnectivityModel( - isConnected = true, - isValidated = true, - ) - ) - // Trigger a data change in the same subscription group - connectionsRepository.activeSubChangedInGroupEvent.emit(Unit) - connectionsRepository.setMobileConnectivity( - MobileConnectivityModel( - isConnected = false, - isValidated = false, - ) - ) - - assertThat(latest) - .isEqualTo( - MobileConnectivityModel( - isConnected = false, - isValidated = true, - ) - ) - - job.cancel() - } + // The data switch tests are mostly testing the [forcingCellularValidation] flow, but that flow + // is private and can only be tested by looking at [isDefaultConnectionFailed]. @Test fun `data switch - in same group - validated matches previous value - expires after 2s`() = testScope.runTest { - var latest: MobileConnectivityModel? = null + var latestConnectionFailed: Boolean? = null val job = - underTest.defaultMobileNetworkConnectivity.onEach { latest = it }.launchIn(this) + underTest.isDefaultConnectionFailed + .onEach { latestConnectionFailed = it } + .launchIn(this) - connectionsRepository.setMobileConnectivity( - MobileConnectivityModel( - isConnected = true, - isValidated = true, - ) - ) - // Trigger a data change in the same subscription group + connectionsRepository.mobileIsDefault.value = true + connectionsRepository.defaultConnectionIsValidated.value = true + + // Trigger a data change in the same subscription group that's not yet validated connectionsRepository.activeSubChangedInGroupEvent.emit(Unit) - connectionsRepository.setMobileConnectivity( - MobileConnectivityModel( - isConnected = false, - isValidated = false, - ) - ) - // After 1s, the force validation bit is still present + connectionsRepository.defaultConnectionIsValidated.value = false + + // After 1s, the force validation bit is still present, so the connection is not marked + // as failed advanceTimeBy(1000) - assertThat(latest) - .isEqualTo( - MobileConnectivityModel( - isConnected = false, - isValidated = true, - ) - ) + assertThat(latestConnectionFailed).isFalse() - // After 2s, the force validation expires + // After 2s, the force validation expires so the connection updates to failed advanceTimeBy(1001) - - assertThat(latest) - .isEqualTo( - MobileConnectivityModel( - isConnected = false, - isValidated = false, - ) - ) + assertThat(latestConnectionFailed).isTrue() job.cancel() } @Test - fun `data switch - in same group - not validated - uses new value immediately`() = + fun `data switch - in same group - not validated - immediately marked as failed`() = testScope.runTest { - var latest: MobileConnectivityModel? = null + var latestConnectionFailed: Boolean? = null val job = - underTest.defaultMobileNetworkConnectivity.onEach { latest = it }.launchIn(this) + underTest.isDefaultConnectionFailed + .onEach { latestConnectionFailed = it } + .launchIn(this) + + connectionsRepository.mobileIsDefault.value = true + connectionsRepository.defaultConnectionIsValidated.value = false - connectionsRepository.setMobileConnectivity( - MobileConnectivityModel( - isConnected = true, - isValidated = false, - ) - ) connectionsRepository.activeSubChangedInGroupEvent.emit(Unit) - connectionsRepository.setMobileConnectivity( - MobileConnectivityModel( - isConnected = false, - isValidated = false, - ) - ) - assertThat(latest) - .isEqualTo( - MobileConnectivityModel( - isConnected = false, - isValidated = false, - ) - ) + assertThat(latestConnectionFailed).isTrue() job.cancel() } @@ -581,60 +525,34 @@ class MobileIconsInteractorTest : SysuiTestCase() { @Test fun `data switch - lose validation - then switch happens - clears forced bit`() = testScope.runTest { - var latest: MobileConnectivityModel? = null + var latestConnectionFailed: Boolean? = null val job = - underTest.defaultMobileNetworkConnectivity.onEach { latest = it }.launchIn(this) + underTest.isDefaultConnectionFailed + .onEach { latestConnectionFailed = it } + .launchIn(this) // GIVEN the network starts validated - connectionsRepository.setMobileConnectivity( - MobileConnectivityModel( - isConnected = true, - isValidated = true, - ) - ) + connectionsRepository.mobileIsDefault.value = true + connectionsRepository.defaultConnectionIsValidated.value = true // WHEN a data change happens in the same group connectionsRepository.activeSubChangedInGroupEvent.emit(Unit) // WHEN the validation bit is lost - connectionsRepository.setMobileConnectivity( - MobileConnectivityModel( - isConnected = false, - isValidated = false, - ) - ) + connectionsRepository.defaultConnectionIsValidated.value = false // WHEN another data change happens in the same group connectionsRepository.activeSubChangedInGroupEvent.emit(Unit) - // THEN the forced validation bit is still removed after 2s - assertThat(latest) - .isEqualTo( - MobileConnectivityModel( - isConnected = false, - isValidated = true, - ) - ) + // THEN the forced validation bit is still used... + assertThat(latestConnectionFailed).isFalse() advanceTimeBy(1000) + assertThat(latestConnectionFailed).isFalse() - assertThat(latest) - .isEqualTo( - MobileConnectivityModel( - isConnected = false, - isValidated = true, - ) - ) - + // ... but expires after 2s advanceTimeBy(1001) - - assertThat(latest) - .isEqualTo( - MobileConnectivityModel( - isConnected = false, - isValidated = false, - ) - ) + assertThat(latestConnectionFailed).isTrue() job.cancel() } @@ -642,15 +560,13 @@ class MobileIconsInteractorTest : SysuiTestCase() { @Test fun `data switch - while already forcing validation - resets clock`() = testScope.runTest { - var latest: MobileConnectivityModel? = null + var latestConnectionFailed: Boolean? = null val job = - underTest.defaultMobileNetworkConnectivity.onEach { latest = it }.launchIn(this) - connectionsRepository.setMobileConnectivity( - MobileConnectivityModel( - isConnected = true, - isValidated = true, - ) - ) + underTest.isDefaultConnectionFailed + .onEach { latestConnectionFailed = it } + .launchIn(this) + connectionsRepository.mobileIsDefault.value = true + connectionsRepository.defaultConnectionIsValidated.value = true connectionsRepository.activeSubChangedInGroupEvent.emit(Unit) @@ -658,65 +574,17 @@ class MobileIconsInteractorTest : SysuiTestCase() { // WHEN another change in same group event happens connectionsRepository.activeSubChangedInGroupEvent.emit(Unit) - connectionsRepository.setMobileConnectivity( - MobileConnectivityModel( - isConnected = false, - isValidated = false, - ) - ) + connectionsRepository.defaultConnectionIsValidated.value = false // THEN the forced validation remains for exactly 2 more seconds from now // 1.500s from second event advanceTimeBy(1500) - assertThat(latest) - .isEqualTo( - MobileConnectivityModel( - isConnected = false, - isValidated = true, - ) - ) + assertThat(latestConnectionFailed).isFalse() // 2.001s from the second event advanceTimeBy(501) - assertThat(latest) - .isEqualTo( - MobileConnectivityModel( - isConnected = false, - isValidated = false, - ) - ) - - job.cancel() - } - - @Test - fun `data switch - not in same group - uses new values`() = - testScope.runTest { - var latest: MobileConnectivityModel? = null - val job = - underTest.defaultMobileNetworkConnectivity.onEach { latest = it }.launchIn(this) - - connectionsRepository.setMobileConnectivity( - MobileConnectivityModel( - isConnected = true, - isValidated = true, - ) - ) - connectionsRepository.setMobileConnectivity( - MobileConnectivityModel( - isConnected = false, - isValidated = false, - ) - ) - - assertThat(latest) - .isEqualTo( - MobileConnectivityModel( - isConnected = false, - isValidated = false, - ) - ) + assertThat(latestConnectionFailed).isTrue() job.cancel() } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/ui/viewmodel/MobileIconViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/ui/viewmodel/MobileIconViewModelTest.kt index bec276a9c68f..8ea8f87e6aff 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/ui/viewmodel/MobileIconViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/ui/viewmodel/MobileIconViewModelTest.kt @@ -400,10 +400,10 @@ class MobileIconViewModelTest : SysuiTestCase() { } @Test - fun `network type - alwaysShow - shown when not connected`() = + fun `network type - alwaysShow - shown when not default`() = testScope.runTest { interactor.setIconGroup(THREE_G) - interactor.isConnected.value = false + interactor.mobileIsDefault.value = false interactor.alwaysShowDataRatIcon.value = true var latest: Icon? = null @@ -420,11 +420,11 @@ class MobileIconViewModelTest : SysuiTestCase() { } @Test - fun `network type - not shown when not connected`() = + fun `network type - not shown when not default`() = testScope.runTest { interactor.setIconGroup(THREE_G) interactor.isDataConnected.value = true - interactor.isConnected.value = false + interactor.mobileIsDefault.value = false var latest: Icon? = null val job = underTest.networkTypeIcon.onEach { latest = it }.launchIn(this) |