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 static com.android.systemui.Dependency.ALLOW_NOTIFICATION_LONG_PRESS_NAME;
20 import static com.android.systemui.Dependency.LEAK_REPORT_EMAIL_NAME;
21 
22 import android.content.Context;
23 import android.os.Handler;
24 import android.os.PowerManager;
25 
26 import androidx.annotation.Nullable;
27 
28 import com.android.keyguard.KeyguardViewController;
29 import com.android.systemui.broadcast.BroadcastDispatcher;
30 import com.android.systemui.dagger.qualifiers.Background;
31 import com.android.systemui.dagger.qualifiers.Main;
32 import com.android.systemui.dock.DockManager;
33 import com.android.systemui.dock.DockManagerImpl;
34 import com.android.systemui.doze.DozeHost;
35 import com.android.systemui.plugins.qs.QSFactory;
36 import com.android.systemui.plugins.statusbar.StatusBarStateController;
37 import com.android.systemui.power.EnhancedEstimates;
38 import com.android.systemui.power.EnhancedEstimatesImpl;
39 import com.android.systemui.qs.tileimpl.QSFactoryImpl;
40 import com.android.systemui.recents.Recents;
41 import com.android.systemui.recents.RecentsImplementation;
42 import com.android.systemui.stackdivider.DividerModule;
43 import com.android.systemui.statusbar.CommandQueue;
44 import com.android.systemui.statusbar.NotificationLockscreenUserManager;
45 import com.android.systemui.statusbar.NotificationLockscreenUserManagerImpl;
46 import com.android.systemui.statusbar.notification.NotificationEntryManager;
47 import com.android.systemui.statusbar.phone.DozeServiceHost;
48 import com.android.systemui.statusbar.phone.HeadsUpManagerPhone;
49 import com.android.systemui.statusbar.phone.KeyguardBypassController;
50 import com.android.systemui.statusbar.phone.KeyguardEnvironmentImpl;
51 import com.android.systemui.statusbar.phone.NotificationGroupManager;
52 import com.android.systemui.statusbar.phone.ShadeController;
53 import com.android.systemui.statusbar.phone.ShadeControllerImpl;
54 import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
55 import com.android.systemui.statusbar.policy.BatteryController;
56 import com.android.systemui.statusbar.policy.BatteryControllerImpl;
57 import com.android.systemui.statusbar.policy.ConfigurationController;
58 import com.android.systemui.statusbar.policy.DeviceProvisionedController;
59 import com.android.systemui.statusbar.policy.DeviceProvisionedControllerImpl;
60 import com.android.systemui.statusbar.policy.HeadsUpManager;
61 
62 import javax.inject.Named;
63 import javax.inject.Singleton;
64 
65 import dagger.Binds;
66 import dagger.Module;
67 import dagger.Provides;
68 
69 /**
70  * A dagger module for injecting default implementations of components of System UI that may be
71  * overridden by the System UI implementation.
72  */
73 @Module(includes = {DividerModule.class})
74 public abstract class SystemUIDefaultModule {
75 
76     @Singleton
77     @Provides
78     @Named(LEAK_REPORT_EMAIL_NAME)
79     @Nullable
provideLeakReportEmail()80     static String provideLeakReportEmail() {
81         return null;
82     }
83 
84     @Binds
bindEnhancedEstimates(EnhancedEstimatesImpl enhancedEstimates)85     abstract EnhancedEstimates bindEnhancedEstimates(EnhancedEstimatesImpl enhancedEstimates);
86 
87     @Binds
bindNotificationLockscreenUserManager( NotificationLockscreenUserManagerImpl notificationLockscreenUserManager)88     abstract NotificationLockscreenUserManager bindNotificationLockscreenUserManager(
89             NotificationLockscreenUserManagerImpl notificationLockscreenUserManager);
90 
91     @Provides
92     @Singleton
provideBatteryController(Context context, EnhancedEstimates enhancedEstimates, PowerManager powerManager, BroadcastDispatcher broadcastDispatcher, @Main Handler mainHandler, @Background Handler bgHandler)93     static BatteryController provideBatteryController(Context context,
94             EnhancedEstimates enhancedEstimates, PowerManager powerManager,
95             BroadcastDispatcher broadcastDispatcher, @Main Handler mainHandler,
96             @Background Handler bgHandler) {
97         BatteryController bC = new BatteryControllerImpl(context, enhancedEstimates, powerManager,
98                 broadcastDispatcher, mainHandler, bgHandler);
99         bC.init();
100         return bC;
101     }
102 
103     @Binds
104     @Singleton
provideQSFactory(QSFactoryImpl qsFactoryImpl)105     public abstract QSFactory provideQSFactory(QSFactoryImpl qsFactoryImpl);
106 
107     @Binds
bindDockManager(DockManagerImpl dockManager)108     abstract DockManager bindDockManager(DockManagerImpl dockManager);
109 
110     @Binds
bindKeyguardEnvironment( KeyguardEnvironmentImpl keyguardEnvironment)111     abstract NotificationEntryManager.KeyguardEnvironment bindKeyguardEnvironment(
112             KeyguardEnvironmentImpl keyguardEnvironment);
113 
114     @Binds
provideShadeController(ShadeControllerImpl shadeController)115     abstract ShadeController provideShadeController(ShadeControllerImpl shadeController);
116 
117     @Singleton
118     @Provides
119     @Named(ALLOW_NOTIFICATION_LONG_PRESS_NAME)
provideAllowNotificationLongPress()120     static boolean provideAllowNotificationLongPress() {
121         return true;
122     }
123 
124     @Singleton
125     @Provides
provideHeadsUpManagerPhone( Context context, StatusBarStateController statusBarStateController, KeyguardBypassController bypassController, NotificationGroupManager groupManager, ConfigurationController configurationController)126     static HeadsUpManagerPhone provideHeadsUpManagerPhone(
127             Context context,
128             StatusBarStateController statusBarStateController,
129             KeyguardBypassController bypassController,
130             NotificationGroupManager groupManager,
131             ConfigurationController configurationController) {
132         return new HeadsUpManagerPhone(context, statusBarStateController, bypassController,
133                 groupManager, configurationController);
134     }
135 
136     @Binds
bindHeadsUpManagerPhone(HeadsUpManagerPhone headsUpManagerPhone)137     abstract HeadsUpManager bindHeadsUpManagerPhone(HeadsUpManagerPhone headsUpManagerPhone);
138 
139     @Provides
140     @Singleton
provideRecents(Context context, RecentsImplementation recentsImplementation, CommandQueue commandQueue)141     static Recents provideRecents(Context context, RecentsImplementation recentsImplementation,
142             CommandQueue commandQueue) {
143         return new Recents(context, recentsImplementation, commandQueue);
144     }
145 
146     @Binds
bindDeviceProvisionedController( DeviceProvisionedControllerImpl deviceProvisionedController)147     abstract DeviceProvisionedController bindDeviceProvisionedController(
148             DeviceProvisionedControllerImpl deviceProvisionedController);
149 
150     @Binds
bindKeyguardViewController( StatusBarKeyguardViewManager statusBarKeyguardViewManager)151     abstract KeyguardViewController bindKeyguardViewController(
152             StatusBarKeyguardViewManager statusBarKeyguardViewManager);
153 
154     @Binds
provideDozeHost(DozeServiceHost dozeServiceHost)155     abstract DozeHost provideDozeHost(DozeServiceHost dozeServiceHost);
156 }
157