• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * Copyright (C) 2024 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.systemui.Dumpable
20 import com.android.systemui.KairosActivatable
21 import com.android.systemui.dagger.SysUISingleton
22 import com.android.systemui.dump.DumpManager
23 import com.android.systemui.kairos.BuildScope
24 import com.android.systemui.kairos.ExperimentalKairosApi
25 import com.android.systemui.kairos.awaitClose
26 import com.android.systemui.kairos.combine
27 import com.android.systemui.kairos.launchEffect
28 import com.android.systemui.shade.carrier.ShadeCarrierGroupController
29 import com.android.systemui.statusbar.phone.ui.StatusBarIconController
30 import com.android.systemui.statusbar.pipeline.mobile.domain.interactor.MobileIconsInteractorKairos
31 import com.android.systemui.statusbar.pipeline.mobile.ui.viewmodel.MobileIconsViewModelKairos
32 import java.io.PrintWriter
33 import javax.inject.Inject
34 
35 /**
36  * This class is intended to provide a context to collect on the
37  * [MobileIconsInteractorKairos.filteredSubscriptions] data source and supply a state flow that can
38  * control [StatusBarIconController] to keep the old UI in sync with the new data source.
39  *
40  * It also provides a mechanism to create a top-level view model for each IconManager to know about
41  * the list of available mobile lines of service for which we want to show icons.
42  */
43 @ExperimentalKairosApi
44 @SysUISingleton
45 class MobileUiAdapterKairos
46 @Inject
47 constructor(
48     private val iconController: StatusBarIconController,
49     val mobileIconsViewModel: MobileIconsViewModelKairos,
50     private val logger: MobileViewLogger,
51     dumpManager: DumpManager,
52 ) : KairosActivatable, Dumpable {
53 
54     init {
55         dumpManager.registerNormalDumpable(this)
56     }
57 
58     private var isCollecting: Boolean = false
59     private var lastValue: List<Int>? = null
60 
61     private var shadeCarrierGroupController: ShadeCarrierGroupController? = null
62 
63     override fun BuildScope.activate() {
64         launchEffect {
65             isCollecting = true
66             awaitClose { isCollecting = false }
67         }
68         // Start notifying the icon controller of subscriptions
69         combine(mobileIconsViewModel.subscriptionIds, mobileIconsViewModel.isStackable) { a, b ->
70                 Pair(a, b)
71             }
72             .observe { (subIds, isStackable) ->
73                 logger.logUiAdapterSubIdsSentToIconController(subIds, isStackable)
74                 lastValue = subIds
75                 if (isStackable) {
76                     // Passing an empty list to remove pre-existing mobile icons.
77                     // StackedMobileBindableIcon will show the stacked icon instead.
78                     iconController.setNewMobileIconSubIds(emptyList())
79                 } else {
80                     iconController.setNewMobileIconSubIds(subIds)
81                 }
82                 shadeCarrierGroupController?.updateModernMobileIcons(subIds)
83             }
84     }
85 
86     /** Set the [ShadeCarrierGroupController] to notify of subscription updates */
87     fun setShadeCarrierGroupController(controller: ShadeCarrierGroupController) {
88         shadeCarrierGroupController = controller
89     }
90 
91     override fun dump(pw: PrintWriter, args: Array<out String>) {
92         pw.println("isCollecting=$isCollecting")
93         pw.println("Last values sent to icon controller: $lastValue")
94     }
95 }
96