Explicitly collect on mobile subscriptions in MobuileUiAdapter

The adapter was previously using an `onEach` to trigger the callback to
`StatusBarIconController#setNewMobileIconSubIds`, which is a side-effect
of the flow rather than being explicit.

This CL makes it so `MobileUiAdapter` explicitly launches a `collect`
job on the subscription list, making it clear that it is setting the new
subscription list on the icon controller.

Test: tests/src/com/android/systemui/statusbar/pipeline/mobile/*
Bug: 249790009
Change-Id: I0fdcc086c1028ac5f3e50942b4bd3a9dfdb9871f
This commit is contained in:
Evan Laird
2022-11-30 17:05:50 -05:00
parent c6393850e4
commit d6def5a620
2 changed files with 29 additions and 20 deletions

View File

@@ -16,6 +16,7 @@
package com.android.systemui.statusbar.pipeline.dagger
import com.android.systemui.CoreStartable
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.log.table.TableLogBuffer
import com.android.systemui.log.table.TableLogBufferFactory
@@ -27,6 +28,7 @@ import com.android.systemui.statusbar.pipeline.mobile.data.repository.UserSetupR
import com.android.systemui.statusbar.pipeline.mobile.data.repository.UserSetupRepositoryImpl
import com.android.systemui.statusbar.pipeline.mobile.domain.interactor.MobileIconsInteractor
import com.android.systemui.statusbar.pipeline.mobile.domain.interactor.MobileIconsInteractorImpl
import com.android.systemui.statusbar.pipeline.mobile.ui.MobileUiAdapter
import com.android.systemui.statusbar.pipeline.mobile.util.MobileMappingsProxy
import com.android.systemui.statusbar.pipeline.mobile.util.MobileMappingsProxyImpl
import com.android.systemui.statusbar.pipeline.shared.data.repository.ConnectivityRepository
@@ -36,6 +38,8 @@ import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiReposito
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.multibindings.ClassKey
import dagger.multibindings.IntoMap
@Module
abstract class StatusBarPipelineModule {
@@ -45,23 +49,25 @@ abstract class StatusBarPipelineModule {
@Binds
abstract fun connectivityRepository(impl: ConnectivityRepositoryImpl): ConnectivityRepository
@Binds
abstract fun wifiRepository(impl: WifiRepositoryImpl): WifiRepository
@Binds abstract fun wifiRepository(impl: WifiRepositoryImpl): WifiRepository
@Binds
abstract fun mobileConnectionsRepository(
impl: MobileConnectionsRepositoryImpl
): MobileConnectionsRepository
@Binds
abstract fun userSetupRepository(impl: UserSetupRepositoryImpl): UserSetupRepository
@Binds abstract fun userSetupRepository(impl: UserSetupRepositoryImpl): UserSetupRepository
@Binds
abstract fun mobileMappingsProxy(impl: MobileMappingsProxyImpl): MobileMappingsProxy
@Binds abstract fun mobileMappingsProxy(impl: MobileMappingsProxyImpl): MobileMappingsProxy
@Binds
abstract fun mobileIconsInteractor(impl: MobileIconsInteractorImpl): MobileIconsInteractor
@Binds
@IntoMap
@ClassKey(MobileUiAdapter::class)
abstract fun bindFeature(impl: MobileUiAdapter): CoreStartable
@Module
companion object {
@JvmStatic

View File

@@ -16,6 +16,7 @@
package com.android.systemui.statusbar.pipeline.mobile.ui
import com.android.systemui.CoreStartable
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.statusbar.phone.StatusBarIconController
@@ -29,9 +30,10 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
/**
* This class is intended to provide a context to collect on the
@@ -50,9 +52,9 @@ constructor(
interactor: MobileIconsInteractor,
private val iconController: StatusBarIconController,
private val iconsViewModelFactory: MobileIconsViewModel.Factory,
@Application scope: CoroutineScope,
@Application private val scope: CoroutineScope,
private val statusBarPipelineFlags: StatusBarPipelineFlags,
) {
) : CoreStartable {
private val mobileSubIds: Flow<List<Int>> =
interactor.filteredSubscriptions.mapLatest { infos ->
infos.map { subscriptionInfo -> subscriptionInfo.subscriptionId }
@@ -66,18 +68,19 @@ constructor(
* NOTE: this should go away as the view presenter learns more about this data pipeline
*/
private val mobileSubIdsState: StateFlow<List<Int>> =
mobileSubIds
.onEach {
// Only notify the icon controller if we want to *render* the new icons.
// Note that this flow may still run if
// [statusBarPipelineFlags.runNewMobileIconsBackend] is true because we may want to
// get the logging data without rendering.
if (statusBarPipelineFlags.useNewMobileIcons()) {
// Notify the icon controller here so that it knows to add icons
iconController.setNewMobileIconSubIds(it)
}
mobileSubIds.stateIn(scope, SharingStarted.WhileSubscribed(), listOf())
override fun start() {
// Only notify the icon controller if we want to *render* the new icons.
// Note that this flow may still run if
// [statusBarPipelineFlags.runNewMobileIconsBackend] is true because we may want to
// get the logging data without rendering.
if (statusBarPipelineFlags.useNewMobileIcons()) {
scope.launch {
mobileSubIds.collectLatest { iconController.setNewMobileIconSubIds(it) }
}
.stateIn(scope, SharingStarted.WhileSubscribed(), listOf())
}
}
/**
* Create a MobileIconsViewModel for a given [IconManager], and bind it to to the manager's