• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * 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.data.repository
18 
19 import android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR
20 import com.android.systemui.CoreStartable
21 import com.android.systemui.dagger.SysUISingleton
22 import com.android.systemui.dagger.qualifiers.Background
23 import com.android.systemui.dagger.qualifiers.Main
24 import com.android.systemui.display.data.repository.DisplayRepository
25 import com.android.systemui.display.data.repository.DisplayWindowPropertiesRepository
26 import com.android.systemui.display.data.repository.PerDisplayStore
27 import com.android.systemui.display.data.repository.SingleDisplayStore
28 import com.android.systemui.statusbar.core.StatusBarConnectedDisplays
29 import com.android.systemui.statusbar.phone.ConfigurationControllerImpl
30 import com.android.systemui.statusbar.policy.ConfigurationController
31 import dagger.Lazy
32 import dagger.Module
33 import dagger.Provides
34 import dagger.multibindings.ClassKey
35 import dagger.multibindings.IntoMap
36 import javax.inject.Inject
37 import kotlinx.coroutines.CoroutineScope
38 
39 /** Status bar specific interface to disambiguate from the global [ConfigurationController]. */
40 interface StatusBarConfigurationController : ConfigurationController
41 
42 /** Provides per display instances of [ConfigurationController], specifically for the Status Bar. */
43 interface StatusBarConfigurationControllerStore : PerDisplayStore<StatusBarConfigurationController>
44 
45 @SysUISingleton
46 class MultiDisplayStatusBarConfigurationControllerStore
47 @Inject
48 constructor(
49     @Background backgroundApplicationScope: CoroutineScope,
50     displayRepository: DisplayRepository,
51     private val displayWindowPropertiesRepository: DisplayWindowPropertiesRepository,
52     private val configurationControllerFactory: ConfigurationControllerImpl.Factory,
53 ) :
54     StatusBarConfigurationControllerStore,
55     StatusBarPerDisplayStoreImpl<StatusBarConfigurationController>(
56         backgroundApplicationScope,
57         displayRepository,
58     ) {
59 
60     init {
61         StatusBarConnectedDisplays.unsafeAssertInNewMode()
62     }
63 
createInstanceForDisplaynull64     override fun createInstanceForDisplay(displayId: Int): StatusBarConfigurationController? {
65         val displayWindowProperties =
66             displayWindowPropertiesRepository.get(displayId, TYPE_STATUS_BAR) ?: return null
67         return configurationControllerFactory.create(displayWindowProperties.context)
68     }
69 
70     override val instanceClass = StatusBarConfigurationController::class.java
71 }
72 
73 @SysUISingleton
74 class SingleDisplayStatusBarConfigurationControllerStore
75 @Inject
76 constructor(@Main globalConfigurationController: ConfigurationController) :
77     StatusBarConfigurationControllerStore,
78     PerDisplayStore<StatusBarConfigurationController> by SingleDisplayStore(
79         globalConfigurationController as StatusBarConfigurationController
<lambda>null80     ) {
81 
82     init {
83         StatusBarConnectedDisplays.assertInLegacyMode()
84     }
85 }
86 
87 @Module
88 object StatusBarConfigurationControllerModule {
89 
90     @Provides
91     @SysUISingleton
storenull92     fun store(
93         singleDisplayLazy: Lazy<SingleDisplayStatusBarConfigurationControllerStore>,
94         multiDisplayLazy: Lazy<MultiDisplayStatusBarConfigurationControllerStore>,
95     ): StatusBarConfigurationControllerStore {
96         return if (StatusBarConnectedDisplays.isEnabled) {
97             multiDisplayLazy.get()
98         } else {
99             singleDisplayLazy.get()
100         }
101     }
102 
103     @Provides
104     @SysUISingleton
105     @IntoMap
106     @ClassKey(StatusBarConfigurationControllerStore::class)
storeAsCoreStartablenull107     fun storeAsCoreStartable(
108         multiDisplayLazy: Lazy<MultiDisplayStatusBarConfigurationControllerStore>
109     ): CoreStartable {
110         return if (StatusBarConnectedDisplays.isEnabled) {
111             multiDisplayLazy.get()
112         } else {
113             CoreStartable.NOP
114         }
115     }
116 }
117