From a8cd6d353fdd1461cbfdf1874b3561a211e30849 Mon Sep 17 00:00:00 2001 From: Caitlin Shkuratov Date: Thu, 2 Feb 2023 21:03:56 +0000 Subject: [PATCH] [SB Refactor] Add better logging for the network type icon. Instead of logging `networkTypeIcon|Resource(res=2131232263, contentDescription=Resource(res=2131952280))`, it'll now log: showNetworkTypeIcon|false networkTypeIcon|LTE Bug: 238425913 Test: manual: dumped logs for MobileConnectionLog[3] (my local sub ID) Change-Id: I385e205017dd46c9047f308f45e6ef45f46f0f26 --- .../domain/interactor/MobileIconInteractor.kt | 12 +++++++ .../ui/viewmodel/MobileIconViewModel.kt | 33 +++++++++---------- 2 files changed, 28 insertions(+), 17 deletions(-) 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 9cdff96dc7d97..636d2cf91459e 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 @@ -33,7 +33,9 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.mapLatest +import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.stateIn interface MobileIconInteractor { @@ -181,6 +183,16 @@ class MobileIconInteractorImpl( else -> mapping[info.resolvedNetworkType.lookupKey] ?: defaultGroup } } + .distinctUntilChanged() + .onEach { + // Doesn't use [logDiffsForTable] because [MobileIconGroup] can't implement the + // [Diffable] interface. + tableLogBuffer.logChange( + prefix = "", + columnName = "networkTypeIcon", + value = it.name + ) + } .stateIn(scope, SharingStarted.WhileSubscribed(), defaultMobileIconGroup.value) override val isEmergencyOnly: StateFlow = 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 9e2024afda8f3..dc09fe45172c5 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 @@ -37,7 +37,6 @@ import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.mapLatest -import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.stateIn /** Common interface for all of the location-based mobile icon view models. */ @@ -124,14 +123,22 @@ constructor( private val showNetworkTypeIcon: Flow = combine( - iconInteractor.isDataConnected, - iconInteractor.isDataEnabled, - iconInteractor.isDefaultConnectionFailed, - iconInteractor.alwaysShowDataRatIcon, - iconInteractor.isConnected, - ) { dataConnected, dataEnabled, failedConnection, alwaysShow, connected -> - alwaysShow || (dataConnected && dataEnabled && !failedConnection && connected) - } + iconInteractor.isDataConnected, + iconInteractor.isDataEnabled, + iconInteractor.isDefaultConnectionFailed, + iconInteractor.alwaysShowDataRatIcon, + iconInteractor.isConnected, + ) { dataConnected, dataEnabled, failedConnection, alwaysShow, connected -> + alwaysShow || (dataConnected && dataEnabled && !failedConnection && connected) + } + .distinctUntilChanged() + .logDiffsForTable( + iconInteractor.tableLogBuffer, + columnPrefix = "", + columnName = "showNetworkTypeIcon", + initialValue = false, + ) + .stateIn(scope, SharingStarted.WhileSubscribed(), false) override val networkTypeIcon: Flow = combine( @@ -149,14 +156,6 @@ constructor( } } .distinctUntilChanged() - .onEach { - // This is done as an onEach side effect since Icon is not Diffable (yet) - iconInteractor.tableLogBuffer.logChange( - prefix = "", - columnName = "networkTypeIcon", - value = it.toString(), - ) - } .stateIn(scope, SharingStarted.WhileSubscribed(), null) override val roaming: StateFlow =