1 /* <lambda>null2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.statusbar.pipeline.mobile.ui 18 19 import com.android.app.tracing.coroutines.launchTraced as launch 20 import com.android.systemui.CoreStartable 21 import com.android.systemui.dagger.SysUISingleton 22 import com.android.systemui.dagger.qualifiers.Application 23 import com.android.systemui.shade.carrier.ShadeCarrierGroupController 24 import com.android.systemui.statusbar.phone.ui.StatusBarIconController 25 import com.android.systemui.statusbar.pipeline.mobile.domain.interactor.MobileIconsInteractor 26 import com.android.systemui.statusbar.pipeline.mobile.ui.viewmodel.MobileIconsViewModel 27 import java.io.PrintWriter 28 import javax.inject.Inject 29 import kotlinx.coroutines.CoroutineScope 30 import kotlinx.coroutines.flow.collectLatest 31 import kotlinx.coroutines.flow.combine 32 33 /** 34 * This class is intended to provide a context to collect on the 35 * [MobileIconsInteractor.filteredSubscriptions] data source and supply a state flow that can 36 * control [StatusBarIconController] to keep the old UI in sync with the new data source. 37 * 38 * It also provides a mechanism to create a top-level view model for each IconManager to know about 39 * the list of available mobile lines of service for which we want to show icons. 40 */ 41 @Suppress("EXPERIMENTAL_IS_NOT_ENABLED") 42 @SysUISingleton 43 class MobileUiAdapter 44 @Inject 45 constructor( 46 private val iconController: StatusBarIconController, 47 val mobileIconsViewModel: MobileIconsViewModel, 48 private val logger: MobileViewLogger, 49 @Application private val scope: CoroutineScope, 50 ) : CoreStartable { 51 private var isCollecting: Boolean = false 52 private var lastValue: List<Int>? = null 53 54 private var shadeCarrierGroupController: ShadeCarrierGroupController? = null 55 56 override fun start() { 57 // Start notifying the icon controller of subscriptions 58 scope.launch { 59 isCollecting = true 60 combine( 61 mobileIconsViewModel.subscriptionIdsFlow, 62 mobileIconsViewModel.isStackable, 63 ::Pair, 64 ) 65 .collectLatest { (subIds, isStackable) -> 66 logger.logUiAdapterSubIdsSentToIconController(subIds, isStackable) 67 lastValue = subIds 68 if (isStackable) { 69 // Passing an empty list to remove pre-existing mobile icons. 70 // StackedMobileBindableIcon will show the stacked icon instead. 71 iconController.setNewMobileIconSubIds(emptyList()) 72 } else { 73 iconController.setNewMobileIconSubIds(subIds) 74 } 75 shadeCarrierGroupController?.updateModernMobileIcons(subIds) 76 } 77 } 78 } 79 80 /** Set the [ShadeCarrierGroupController] to notify of subscription updates */ 81 fun setShadeCarrierGroupController(controller: ShadeCarrierGroupController) { 82 shadeCarrierGroupController = controller 83 } 84 85 override fun dump(pw: PrintWriter, args: Array<out String>) { 86 pw.println("isCollecting=$isCollecting") 87 pw.println("Last values sent to icon controller: $lastValue") 88 } 89 } 90