1 /*
2  * Copyright (C) 2019 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.dagger;
18 
19 import android.app.INotificationManager;
20 import android.app.Service;
21 import android.app.backup.BackupManager;
22 import android.content.Context;
23 import android.service.dreams.IDreamManager;
24 
25 import androidx.annotation.Nullable;
26 
27 import com.android.internal.statusbar.IStatusBarService;
28 import com.android.keyguard.dagger.ClockRegistryModule;
29 import com.android.keyguard.dagger.KeyguardBouncerComponent;
30 import com.android.systemui.BootCompleteCache;
31 import com.android.systemui.BootCompleteCacheImpl;
32 import com.android.systemui.CameraProtectionModule;
33 import com.android.systemui.CoreStartable;
34 import com.android.systemui.SystemUISecondaryUserService;
35 import com.android.systemui.accessibility.AccessibilityModule;
36 import com.android.systemui.accessibility.data.repository.AccessibilityRepositoryModule;
37 import com.android.systemui.ambient.dagger.AmbientModule;
38 import com.android.systemui.appops.dagger.AppOpsModule;
39 import com.android.systemui.assist.AssistModule;
40 import com.android.systemui.authentication.AuthenticationModule;
41 import com.android.systemui.biometrics.FingerprintInteractiveToAuthProvider;
42 import com.android.systemui.biometrics.FingerprintReEnrollNotification;
43 import com.android.systemui.biometrics.UdfpsDisplayModeProvider;
44 import com.android.systemui.biometrics.dagger.BiometricsModule;
45 import com.android.systemui.biometrics.domain.BiometricsDomainLayerModule;
46 import com.android.systemui.bouncer.data.repository.BouncerRepositoryModule;
47 import com.android.systemui.bouncer.domain.interactor.BouncerInteractorModule;
48 import com.android.systemui.bouncer.ui.BouncerViewModule;
49 import com.android.systemui.brightness.dagger.ScreenBrightnessModule;
50 import com.android.systemui.classifier.FalsingModule;
51 import com.android.systemui.clipboardoverlay.dagger.ClipboardOverlayModule;
52 import com.android.systemui.common.data.CommonDataLayerModule;
53 import com.android.systemui.communal.dagger.CommunalModule;
54 import com.android.systemui.complication.dagger.ComplicationComponent;
55 import com.android.systemui.controls.dagger.ControlsModule;
56 import com.android.systemui.dagger.qualifiers.Application;
57 import com.android.systemui.dagger.qualifiers.Main;
58 import com.android.systemui.dagger.qualifiers.SystemUser;
59 import com.android.systemui.dagger.qualifiers.UiBackground;
60 import com.android.systemui.demomode.dagger.DemoModeModule;
61 import com.android.systemui.deviceentry.DeviceEntryModule;
62 import com.android.systemui.display.DisplayModule;
63 import com.android.systemui.doze.dagger.DozeComponent;
64 import com.android.systemui.dreams.dagger.DreamModule;
65 import com.android.systemui.dump.DumpManager;
66 import com.android.systemui.flags.FeatureFlags;
67 import com.android.systemui.flags.FlagDependenciesModule;
68 import com.android.systemui.flags.FlagsModule;
69 import com.android.systemui.inputmethod.InputMethodModule;
70 import com.android.systemui.keyboard.KeyboardModule;
71 import com.android.systemui.keyevent.data.repository.KeyEventRepositoryModule;
72 import com.android.systemui.keyguard.ui.composable.LockscreenContent;
73 import com.android.systemui.log.dagger.LogModule;
74 import com.android.systemui.log.dagger.MonitorLog;
75 import com.android.systemui.log.table.TableLogBuffer;
76 import com.android.systemui.mediaprojection.MediaProjectionModule;
77 import com.android.systemui.mediaprojection.appselector.MediaProjectionActivitiesModule;
78 import com.android.systemui.mediaprojection.taskswitcher.MediaProjectionTaskSwitcherModule;
79 import com.android.systemui.model.SceneContainerPlugin;
80 import com.android.systemui.model.SysUiState;
81 import com.android.systemui.motiontool.MotionToolModule;
82 import com.android.systemui.navigationbar.NavigationBarComponent;
83 import com.android.systemui.notetask.NoteTaskModule;
84 import com.android.systemui.people.PeopleModule;
85 import com.android.systemui.plugins.BcSmartspaceConfigPlugin;
86 import com.android.systemui.plugins.BcSmartspaceDataPlugin;
87 import com.android.systemui.privacy.PrivacyModule;
88 import com.android.systemui.process.condition.SystemProcessCondition;
89 import com.android.systemui.qrcodescanner.dagger.QRCodeScannerModule;
90 import com.android.systemui.qs.FgsManagerController;
91 import com.android.systemui.qs.FgsManagerControllerImpl;
92 import com.android.systemui.qs.QSFragmentStartableModule;
93 import com.android.systemui.qs.footer.dagger.FooterActionsModule;
94 import com.android.systemui.recents.Recents;
95 import com.android.systemui.recordissue.RecordIssueModule;
96 import com.android.systemui.retail.dagger.RetailModeModule;
97 import com.android.systemui.scene.shared.model.SceneContainerConfig;
98 import com.android.systemui.scene.shared.model.SceneDataSource;
99 import com.android.systemui.scene.shared.model.SceneDataSourceDelegator;
100 import com.android.systemui.scene.ui.view.WindowRootViewComponent;
101 import com.android.systemui.screenrecord.ScreenRecordModule;
102 import com.android.systemui.screenshot.dagger.ScreenshotModule;
103 import com.android.systemui.security.data.repository.SecurityRepositoryModule;
104 import com.android.systemui.settings.DisplayTracker;
105 import com.android.systemui.shade.ShadeController;
106 import com.android.systemui.shade.transition.LargeScreenShadeInterpolator;
107 import com.android.systemui.shade.transition.LargeScreenShadeInterpolatorImpl;
108 import com.android.systemui.shared.condition.Monitor;
109 import com.android.systemui.smartspace.dagger.SmartspaceModule;
110 import com.android.systemui.startable.Dependencies;
111 import com.android.systemui.statusbar.CommandQueue;
112 import com.android.systemui.statusbar.NotificationLockscreenUserManager;
113 import com.android.systemui.statusbar.NotificationShadeWindowController;
114 import com.android.systemui.statusbar.connectivity.ConnectivityModule;
115 import com.android.systemui.statusbar.dagger.StatusBarModule;
116 import com.android.systemui.statusbar.disableflags.dagger.DisableFlagsModule;
117 import com.android.systemui.statusbar.events.StatusBarEventsModule;
118 import com.android.systemui.statusbar.events.SystemStatusAnimationScheduler;
119 import com.android.systemui.statusbar.notification.NotifPipelineFlags;
120 import com.android.systemui.statusbar.notification.collection.NotifPipeline;
121 import com.android.systemui.statusbar.notification.collection.inflation.NotificationRowBinder;
122 import com.android.systemui.statusbar.notification.collection.inflation.NotificationRowBinderImpl;
123 import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection;
124 import com.android.systemui.statusbar.notification.collection.render.NotificationVisibilityProvider;
125 import com.android.systemui.statusbar.notification.interruption.VisualInterruptionDecisionProvider;
126 import com.android.systemui.statusbar.notification.people.PeopleHubModule;
127 import com.android.systemui.statusbar.notification.row.dagger.ExpandableNotificationRowComponent;
128 import com.android.systemui.statusbar.notification.row.dagger.NotificationRowComponent;
129 import com.android.systemui.statusbar.phone.CentralSurfaces;
130 import com.android.systemui.statusbar.phone.ConfigurationControllerModule;
131 import com.android.systemui.statusbar.phone.LetterboxModule;
132 import com.android.systemui.statusbar.phone.NotificationIconAreaControllerModule;
133 import com.android.systemui.statusbar.pipeline.dagger.StatusBarPipelineModule;
134 import com.android.systemui.statusbar.policy.HeadsUpManager;
135 import com.android.systemui.statusbar.policy.KeyguardStateController;
136 import com.android.systemui.statusbar.policy.PolicyModule;
137 import com.android.systemui.statusbar.policy.SensitiveNotificationProtectionController;
138 import com.android.systemui.statusbar.policy.ZenModeController;
139 import com.android.systemui.statusbar.policy.dagger.SmartRepliesInflationModule;
140 import com.android.systemui.statusbar.policy.dagger.StatusBarPolicyModule;
141 import com.android.systemui.statusbar.ui.binder.StatusBarViewBinderModule;
142 import com.android.systemui.statusbar.window.StatusBarWindowModule;
143 import com.android.systemui.telephony.data.repository.TelephonyRepositoryModule;
144 import com.android.systemui.temporarydisplay.dagger.TemporaryDisplayModule;
145 import com.android.systemui.tuner.dagger.TunerModule;
146 import com.android.systemui.user.UserModule;
147 import com.android.systemui.user.domain.UserDomainLayerModule;
148 import com.android.systemui.util.EventLogModule;
149 import com.android.systemui.util.concurrency.SysUIConcurrencyModule;
150 import com.android.systemui.util.dagger.UtilModule;
151 import com.android.systemui.util.kotlin.SysUICoroutinesModule;
152 import com.android.systemui.util.reference.ReferenceModule;
153 import com.android.systemui.util.sensors.SensorModule;
154 import com.android.systemui.util.settings.SettingsUtilModule;
155 import com.android.systemui.util.time.SystemClock;
156 import com.android.systemui.util.time.SystemClockImpl;
157 import com.android.systemui.wallet.dagger.WalletModule;
158 import com.android.systemui.wmshell.BubblesManager;
159 import com.android.wm.shell.bubbles.Bubbles;
160 
161 import dagger.Binds;
162 import dagger.BindsOptionalOf;
163 import dagger.Module;
164 import dagger.Provides;
165 import dagger.multibindings.ClassKey;
166 import dagger.multibindings.IntoMap;
167 import dagger.multibindings.Multibinds;
168 
169 import kotlinx.coroutines.CoroutineScope;
170 
171 import java.util.Collections;
172 import java.util.Map;
173 import java.util.Optional;
174 import java.util.Set;
175 import java.util.concurrent.Executor;
176 
177 import javax.inject.Named;
178 
179 /**
180  * A dagger module for injecting components of System UI that are required by System UI.
181  *
182  * If your feature can be excluded, subclassed, or re-implemented by a variant of SystemUI, put
183  * your Dagger Module in {@link ReferenceSystemUIModule} and/or any variant modules that
184  * rely on the feature.
185  *
186  * Adding an entry in this file means that _all_ variants of SystemUI will receive that code. They
187  * may not appreciate that.
188  */
189 @Module(includes = {
190         AccessibilityModule.class,
191         AccessibilityRepositoryModule.class,
192         AmbientModule.class,
193         AppOpsModule.class,
194         AssistModule.class,
195         AuthenticationModule.class,
196         BiometricsModule.class,
197         BiometricsDomainLayerModule.class,
198         BouncerInteractorModule.class,
199         BouncerRepositoryModule.class,
200         BouncerViewModule.class,
201         CameraProtectionModule.class,
202         ClipboardOverlayModule.class,
203         ClockRegistryModule.class,
204         CommunalModule.class,
205         CommonDataLayerModule.class,
206         ConfigurationControllerModule.class,
207         ConnectivityModule.class,
208         ControlsModule.class,
209         DemoModeModule.class,
210         DeviceEntryModule.class,
211         DisableFlagsModule.class,
212         DisplayModule.class,
213         DreamModule.class,
214         EventLogModule.class,
215         FalsingModule.class,
216         FlagsModule.class,
217         FlagDependenciesModule.class,
218         FooterActionsModule.class,
219         InputMethodModule.class,
220         KeyEventRepositoryModule.class,
221         KeyboardModule.class,
222         LetterboxModule.class,
223         LogModule.class,
224         MediaProjectionActivitiesModule.class,
225         MediaProjectionModule.class,
226         MediaProjectionTaskSwitcherModule.class,
227         MotionToolModule.class,
228         NotificationIconAreaControllerModule.class,
229         PeopleHubModule.class,
230         PeopleModule.class,
231         PluginModule.class,
232         PolicyModule.class,
233         PrivacyModule.class,
234         QRCodeScannerModule.class,
235         QSFragmentStartableModule.class,
236         RecordIssueModule.class,
237         ReferenceModule.class,
238         RetailModeModule.class,
239         ScreenBrightnessModule.class,
240         ScreenshotModule.class,
241         SensorModule.class,
242         SecurityRepositoryModule.class,
243         ScreenRecordModule.class,
244         SettingsUtilModule.class,
245         SmartRepliesInflationModule.class,
246         SmartspaceModule.class,
247         StatusBarEventsModule.class,
248         StatusBarModule.class,
249         StatusBarPipelineModule.class,
250         StatusBarPolicyModule.class,
251         StatusBarViewBinderModule.class,
252         StatusBarWindowModule.class,
253         SystemPropertiesFlagsModule.class,
254         SysUIConcurrencyModule.class,
255         SysUICoroutinesModule.class,
256         CommonSystemUIUnfoldModule.class,
257         TelephonyRepositoryModule.class,
258         TemporaryDisplayModule.class,
259         TunerModule.class,
260         UserDomainLayerModule.class,
261         UserModule.class,
262         UtilModule.class,
263         NoteTaskModule.class,
264         WalletModule.class
265         },
266         subcomponents = {
267             ComplicationComponent.class,
268             DozeComponent.class,
269             ExpandableNotificationRowComponent.class,
270             KeyguardBouncerComponent.class,
271             NavigationBarComponent.class,
272             NotificationRowComponent.class,
273             WindowRootViewComponent.class,
274         })
275 public abstract class SystemUIModule {
276 
277     @Multibinds
278     @Dependencies
startableDependencyMap()279     abstract Map<Class<?>, Set<Class<? extends CoreStartable>>> startableDependencyMap();
280 
281     @Binds
bindBootCompleteCache(BootCompleteCacheImpl bootCompleteCache)282     abstract BootCompleteCache bindBootCompleteCache(BootCompleteCacheImpl bootCompleteCache);
283 
284     /**
285      *
286      */
287     @Binds
bindComponentHelper( ContextComponentResolver componentHelper)288     public abstract ContextComponentHelper bindComponentHelper(
289             ContextComponentResolver componentHelper);
290 
291     /**
292      *
293      */
294     @Binds
bindNotificationRowBinder( NotificationRowBinderImpl notificationRowBinder)295     public abstract NotificationRowBinder bindNotificationRowBinder(
296             NotificationRowBinderImpl notificationRowBinder);
297 
298     @SysUISingleton
299     @Provides
provideSysUiState( DisplayTracker displayTracker, DumpManager dumpManager, SceneContainerPlugin sceneContainerPlugin)300     static SysUiState provideSysUiState(
301             DisplayTracker displayTracker,
302             DumpManager dumpManager,
303             SceneContainerPlugin sceneContainerPlugin) {
304         final SysUiState state = new SysUiState(displayTracker, sceneContainerPlugin);
305         dumpManager.registerDumpable(state);
306         return state;
307     }
308 
309     /**
310      * Provides the monitor for SystemUI that requires the process running as the system user.
311      */
312     @SysUISingleton
313     @Provides
314     @SystemUser
provideSystemUserMonitor(@ain Executor executor, SystemProcessCondition systemProcessCondition, @MonitorLog TableLogBuffer logBuffer)315     static Monitor provideSystemUserMonitor(@Main Executor executor,
316             SystemProcessCondition systemProcessCondition, @MonitorLog TableLogBuffer logBuffer) {
317         return new Monitor(executor, Collections.singleton(systemProcessCondition), logBuffer);
318     }
319 
320     /** Provides the package name for SystemUI. */
321     @SysUISingleton
322     @Provides
provideBackupManager(@pplication Context context)323     static BackupManager provideBackupManager(@Application Context context) {
324         return new BackupManager(context);
325     }
326 
327     @BindsOptionalOf
optionalCommandQueue()328     abstract CommandQueue optionalCommandQueue();
329 
330     @BindsOptionalOf
optionalHeadsUpManager()331     abstract HeadsUpManager optionalHeadsUpManager();
332 
333     @BindsOptionalOf
optionalBcSmartspaceDataPlugin()334     abstract BcSmartspaceDataPlugin optionalBcSmartspaceDataPlugin();
335 
336     @BindsOptionalOf
optionalBcSmartspaceConfigPlugin()337     abstract BcSmartspaceConfigPlugin optionalBcSmartspaceConfigPlugin();
338 
339     @BindsOptionalOf
340     @Named(SmartspaceModule.DATE_SMARTSPACE_DATA_PLUGIN)
optionalDateSmartspaceConfigPlugin()341     abstract BcSmartspaceDataPlugin optionalDateSmartspaceConfigPlugin();
342 
343     @BindsOptionalOf
344     @Named(SmartspaceModule.WEATHER_SMARTSPACE_DATA_PLUGIN)
optionalWeatherSmartspaceConfigPlugin()345     abstract BcSmartspaceDataPlugin optionalWeatherSmartspaceConfigPlugin();
346 
347     @BindsOptionalOf
optionalRecents()348     abstract Recents optionalRecents();
349 
350     @BindsOptionalOf
optionalCentralSurfaces()351     abstract CentralSurfaces optionalCentralSurfaces();
352 
353     @BindsOptionalOf
optionalUdfpsDisplayModeProvider()354     abstract UdfpsDisplayModeProvider optionalUdfpsDisplayModeProvider();
355 
356     @BindsOptionalOf
optionalFingerprintInteractiveToAuthProvider()357     abstract FingerprintInteractiveToAuthProvider optionalFingerprintInteractiveToAuthProvider();
358 
359     @BindsOptionalOf
optionalSystemStatusAnimationScheduler()360     abstract SystemStatusAnimationScheduler optionalSystemStatusAnimationScheduler();
361 
362     @BindsOptionalOf
optionalFingerprintReEnrollNotification()363     abstract FingerprintReEnrollNotification optionalFingerprintReEnrollNotification();
364 
365     @BindsOptionalOf
optionalLockscreenContent()366     abstract LockscreenContent optionalLockscreenContent();
367 
368     @SysUISingleton
369     @Binds
bindSystemClock(SystemClockImpl systemClock)370     abstract SystemClock bindSystemClock(SystemClockImpl systemClock);
371 
372     // TODO: This should provided by the WM component
373 
374     /** Provides Optional of BubbleManager */
375     @SysUISingleton
376     @Provides
provideBubblesManager(Context context, Optional<Bubbles> bubblesOptional, NotificationShadeWindowController notificationShadeWindowController, KeyguardStateController keyguardStateController, ShadeController shadeController, @Nullable IStatusBarService statusBarService, INotificationManager notificationManager, IDreamManager dreamManager, NotificationVisibilityProvider visibilityProvider, VisualInterruptionDecisionProvider visualInterruptionDecisionProvider, ZenModeController zenModeController, NotificationLockscreenUserManager notifUserManager, SensitiveNotificationProtectionController sensitiveNotificationProtectionController, CommonNotifCollection notifCollection, NotifPipeline notifPipeline, SysUiState sysUiState, FeatureFlags featureFlags, NotifPipelineFlags notifPipelineFlags, @Main Executor sysuiMainExecutor, @UiBackground Executor sysuiUiBgExecutor)377     static Optional<BubblesManager> provideBubblesManager(Context context,
378             Optional<Bubbles> bubblesOptional,
379             NotificationShadeWindowController notificationShadeWindowController,
380             KeyguardStateController keyguardStateController,
381             ShadeController shadeController,
382             @Nullable IStatusBarService statusBarService,
383             INotificationManager notificationManager,
384             IDreamManager dreamManager,
385             NotificationVisibilityProvider visibilityProvider,
386             VisualInterruptionDecisionProvider visualInterruptionDecisionProvider,
387             ZenModeController zenModeController,
388             NotificationLockscreenUserManager notifUserManager,
389             SensitiveNotificationProtectionController sensitiveNotificationProtectionController,
390             CommonNotifCollection notifCollection,
391             NotifPipeline notifPipeline,
392             SysUiState sysUiState,
393             FeatureFlags featureFlags,
394             NotifPipelineFlags notifPipelineFlags,
395             @Main Executor sysuiMainExecutor,
396             @UiBackground Executor sysuiUiBgExecutor) {
397         return Optional.ofNullable(BubblesManager.create(context,
398                 bubblesOptional,
399                 notificationShadeWindowController,
400                 keyguardStateController,
401                 shadeController,
402                 statusBarService,
403                 notificationManager,
404                 dreamManager,
405                 visibilityProvider,
406                 visualInterruptionDecisionProvider,
407                 zenModeController,
408                 notifUserManager,
409                 sensitiveNotificationProtectionController,
410                 notifCollection,
411                 notifPipeline,
412                 sysUiState,
413                 featureFlags,
414                 notifPipelineFlags,
415                 sysuiMainExecutor,
416                 sysuiUiBgExecutor));
417     }
418 
419     @Binds
bindFgsManagerController(FgsManagerControllerImpl impl)420     abstract FgsManagerController bindFgsManagerController(FgsManagerControllerImpl impl);
421 
422     @Binds
largeScreensShadeInterpolator( LargeScreenShadeInterpolatorImpl impl)423     abstract LargeScreenShadeInterpolator largeScreensShadeInterpolator(
424             LargeScreenShadeInterpolatorImpl impl);
425 
426     @Binds
427     @IntoMap
428     @ClassKey(SystemUISecondaryUserService.class)
bindsSystemUISecondaryUserService(SystemUISecondaryUserService service)429     abstract Service bindsSystemUISecondaryUserService(SystemUISecondaryUserService service);
430 
431     @Provides
432     @SysUISingleton
providesSceneDataSourceDelegator( @pplication CoroutineScope applicationScope, SceneContainerConfig config)433     static SceneDataSourceDelegator providesSceneDataSourceDelegator(
434             @Application CoroutineScope applicationScope, SceneContainerConfig config) {
435         return new SceneDataSourceDelegator(applicationScope, config);
436     }
437 
438     @Binds
bindSceneDataSource(SceneDataSourceDelegator delegator)439     abstract SceneDataSource bindSceneDataSource(SceneDataSourceDelegator delegator);
440 }
441