1 /*
2  * 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.dagger
18 
19 import android.net.wifi.WifiManager
20 import com.android.systemui.CoreStartable
21 import com.android.systemui.dagger.SysUISingleton
22 import com.android.systemui.log.LogBuffer
23 import com.android.systemui.log.LogBufferFactory
24 import com.android.systemui.log.table.TableLogBuffer
25 import com.android.systemui.log.table.TableLogBufferFactory
26 import com.android.systemui.statusbar.pipeline.airplane.data.repository.AirplaneModeRepository
27 import com.android.systemui.statusbar.pipeline.airplane.data.repository.AirplaneModeRepositoryImpl
28 import com.android.systemui.statusbar.pipeline.airplane.ui.viewmodel.AirplaneModeViewModel
29 import com.android.systemui.statusbar.pipeline.airplane.ui.viewmodel.AirplaneModeViewModelImpl
30 import com.android.systemui.statusbar.pipeline.icons.shared.BindableIconsRegistry
31 import com.android.systemui.statusbar.pipeline.icons.shared.BindableIconsRegistryImpl
32 import com.android.systemui.statusbar.pipeline.mobile.data.repository.CarrierConfigCoreStartable
33 import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionsRepository
34 import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileRepositorySwitcher
35 import com.android.systemui.statusbar.pipeline.mobile.domain.interactor.MobileIconsInteractor
36 import com.android.systemui.statusbar.pipeline.mobile.domain.interactor.MobileIconsInteractorImpl
37 import com.android.systemui.statusbar.pipeline.mobile.ui.MobileUiAdapter
38 import com.android.systemui.statusbar.pipeline.mobile.ui.viewmodel.MobileIconsViewModel
39 import com.android.systemui.statusbar.pipeline.mobile.util.MobileMappingsProxy
40 import com.android.systemui.statusbar.pipeline.mobile.util.MobileMappingsProxyImpl
41 import com.android.systemui.statusbar.pipeline.mobile.util.SubscriptionManagerProxy
42 import com.android.systemui.statusbar.pipeline.mobile.util.SubscriptionManagerProxyImpl
43 import com.android.systemui.statusbar.pipeline.satellite.data.DeviceBasedSatelliteRepository
44 import com.android.systemui.statusbar.pipeline.satellite.data.DeviceBasedSatelliteRepositorySwitcher
45 import com.android.systemui.statusbar.pipeline.satellite.data.RealDeviceBasedSatelliteRepository
46 import com.android.systemui.statusbar.pipeline.satellite.data.prod.DeviceBasedSatelliteRepositoryImpl
47 import com.android.systemui.statusbar.pipeline.satellite.ui.viewmodel.DeviceBasedSatelliteViewModel
48 import com.android.systemui.statusbar.pipeline.satellite.ui.viewmodel.DeviceBasedSatelliteViewModelImpl
49 import com.android.systemui.statusbar.pipeline.shared.data.repository.ConnectivityRepository
50 import com.android.systemui.statusbar.pipeline.shared.data.repository.ConnectivityRepositoryImpl
51 import com.android.systemui.statusbar.pipeline.shared.ui.binder.CollapsedStatusBarViewBinder
52 import com.android.systemui.statusbar.pipeline.shared.ui.binder.CollapsedStatusBarViewBinderImpl
53 import com.android.systemui.statusbar.pipeline.shared.ui.viewmodel.CollapsedStatusBarViewModel
54 import com.android.systemui.statusbar.pipeline.shared.ui.viewmodel.CollapsedStatusBarViewModelImpl
55 import com.android.systemui.statusbar.pipeline.wifi.data.repository.RealWifiRepository
56 import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository
57 import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepositorySwitcher
58 import com.android.systemui.statusbar.pipeline.wifi.data.repository.prod.DisabledWifiRepository
59 import com.android.systemui.statusbar.pipeline.wifi.data.repository.prod.WifiRepositoryImpl
60 import com.android.systemui.statusbar.pipeline.wifi.domain.interactor.WifiInteractor
61 import com.android.systemui.statusbar.pipeline.wifi.domain.interactor.WifiInteractorImpl
62 import com.android.systemui.statusbar.policy.data.repository.UserSetupRepository
63 import com.android.systemui.statusbar.policy.data.repository.UserSetupRepositoryImpl
64 import dagger.Binds
65 import dagger.Module
66 import dagger.Provides
67 import dagger.multibindings.ClassKey
68 import dagger.multibindings.IntoMap
69 import java.util.function.Supplier
70 import javax.inject.Named
71 import kotlinx.coroutines.flow.Flow
72 
73 @Module
74 abstract class StatusBarPipelineModule {
75     @Binds
airplaneModeRepositorynull76     abstract fun airplaneModeRepository(impl: AirplaneModeRepositoryImpl): AirplaneModeRepository
77 
78     @Binds
79     abstract fun airplaneModeViewModel(impl: AirplaneModeViewModelImpl): AirplaneModeViewModel
80 
81     @Binds
82     abstract fun bindableIconsRepository(impl: BindableIconsRegistryImpl): BindableIconsRegistry
83 
84     @Binds
85     abstract fun connectivityRepository(impl: ConnectivityRepositoryImpl): ConnectivityRepository
86 
87     @Binds
88     abstract fun realDeviceBasedSatelliteRepository(
89         impl: DeviceBasedSatelliteRepositoryImpl
90     ): RealDeviceBasedSatelliteRepository
91 
92     @Binds
93     abstract fun deviceBasedSatelliteRepository(
94         impl: DeviceBasedSatelliteRepositorySwitcher
95     ): DeviceBasedSatelliteRepository
96 
97     @Binds
98     abstract fun deviceBasedSatelliteViewModel(
99         impl: DeviceBasedSatelliteViewModelImpl
100     ): DeviceBasedSatelliteViewModel
101 
102     @Binds abstract fun wifiRepository(impl: WifiRepositorySwitcher): WifiRepository
103 
104     @Binds abstract fun wifiInteractor(impl: WifiInteractorImpl): WifiInteractor
105 
106     @Binds
107     abstract fun mobileConnectionsRepository(
108         impl: MobileRepositorySwitcher
109     ): MobileConnectionsRepository
110 
111     @Binds abstract fun userSetupRepository(impl: UserSetupRepositoryImpl): UserSetupRepository
112 
113     @Binds abstract fun mobileMappingsProxy(impl: MobileMappingsProxyImpl): MobileMappingsProxy
114 
115     @Binds
116     abstract fun subscriptionManagerProxy(
117         impl: SubscriptionManagerProxyImpl
118     ): SubscriptionManagerProxy
119 
120     @Binds
121     abstract fun mobileIconsInteractor(impl: MobileIconsInteractorImpl): MobileIconsInteractor
122 
123     @Binds
124     @IntoMap
125     @ClassKey(MobileUiAdapter::class)
126     abstract fun bindFeature(impl: MobileUiAdapter): CoreStartable
127 
128     @Binds
129     @IntoMap
130     @ClassKey(CarrierConfigCoreStartable::class)
131     abstract fun bindCarrierConfigStartable(impl: CarrierConfigCoreStartable): CoreStartable
132 
133     @Binds
134     abstract fun collapsedStatusBarViewModel(
135         impl: CollapsedStatusBarViewModelImpl
136     ): CollapsedStatusBarViewModel
137 
138     @Binds
139     abstract fun collapsedStatusBarViewBinder(
140         impl: CollapsedStatusBarViewBinderImpl
141     ): CollapsedStatusBarViewBinder
142 
143     companion object {
144 
145         @Provides
146         @SysUISingleton
147         fun provideRealWifiRepository(
148             wifiManager: WifiManager?,
149             disabledWifiRepository: DisabledWifiRepository,
150             wifiRepositoryImplFactory: WifiRepositoryImpl.Factory,
151         ): RealWifiRepository {
152             // If we have a null [WifiManager], then the wifi repository should be permanently
153             // disabled.
154             return if (wifiManager == null) {
155                 disabledWifiRepository
156             } else {
157                 wifiRepositoryImplFactory.create(wifiManager)
158             }
159         }
160 
161         @Provides
162         @SysUISingleton
163         @Named(FIRST_MOBILE_SUB_SHOWING_NETWORK_TYPE_ICON)
164         fun provideFirstMobileSubShowingNetworkTypeIconProvider(
165             mobileIconsViewModel: MobileIconsViewModel,
166         ): Supplier<Flow<Boolean>> {
167             return Supplier<Flow<Boolean>> {
168                 mobileIconsViewModel.firstMobileSubShowingNetworkTypeIcon
169             }
170         }
171 
172         @Provides
173         @SysUISingleton
174         @WifiInputLog
175         fun provideWifiLogBuffer(factory: LogBufferFactory): LogBuffer {
176             return factory.create("WifiInputLog", 200)
177         }
178 
179         @Provides
180         @SysUISingleton
181         @WifiTableLog
182         fun provideWifiTableLogBuffer(factory: TableLogBufferFactory): TableLogBuffer {
183             return factory.create("WifiTableLog", 100)
184         }
185 
186         @Provides
187         @SysUISingleton
188         @AirplaneTableLog
189         fun provideAirplaneTableLogBuffer(factory: TableLogBufferFactory): TableLogBuffer {
190             return factory.create("AirplaneTableLog", 30)
191         }
192 
193         @Provides
194         @SysUISingleton
195         @SharedConnectivityInputLog
196         fun provideSharedConnectivityTableLogBuffer(factory: LogBufferFactory): LogBuffer {
197             return factory.create("SharedConnectivityInputLog", 60)
198         }
199 
200         @Provides
201         @SysUISingleton
202         @MobileSummaryLog
203         fun provideMobileSummaryLogBuffer(factory: TableLogBufferFactory): TableLogBuffer {
204             return factory.create("MobileSummaryLog", 100)
205         }
206 
207         @Provides
208         @SysUISingleton
209         @MobileInputLog
210         fun provideMobileInputLogBuffer(factory: LogBufferFactory): LogBuffer {
211             return factory.create("MobileInputLog", 300)
212         }
213 
214         @Provides
215         @SysUISingleton
216         @MobileViewLog
217         fun provideMobileViewLogBuffer(factory: LogBufferFactory): LogBuffer {
218             return factory.create("MobileViewLog", 100)
219         }
220 
221         @Provides
222         @SysUISingleton
223         @VerboseMobileViewLog
224         fun provideVerboseMobileViewLogBuffer(factory: LogBufferFactory): LogBuffer {
225             return factory.create("VerboseMobileViewLog", 100)
226         }
227 
228         @Provides
229         @SysUISingleton
230         @DeviceBasedSatelliteInputLog
231         fun provideDeviceBasedSatelliteInputLog(factory: LogBufferFactory): LogBuffer {
232             return factory.create("DeviceBasedSatelliteInputLog", 200)
233         }
234 
235         @Provides
236         @SysUISingleton
237         @VerboseDeviceBasedSatelliteInputLog
238         fun provideVerboseDeviceBasedSatelliteInputLog(factory: LogBufferFactory): LogBuffer {
239             return factory.create("VerboseDeviceBasedSatelliteInputLog", 200)
240         }
241 
242         const val FIRST_MOBILE_SUB_SHOWING_NETWORK_TYPE_ICON =
243             "FirstMobileSubShowingNetworkTypeIcon"
244     }
245 }
246