1 /*
2  * Copyright (C) 2020 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.dagger;
18 
19 import static com.android.systemui.Flags.predictiveBackAnimateDialogs;
20 
21 import android.content.Context;
22 import android.os.Handler;
23 import android.os.RemoteException;
24 import android.service.dreams.IDreamManager;
25 import android.util.Log;
26 
27 import com.android.internal.jank.InteractionJankMonitor;
28 import com.android.internal.statusbar.IStatusBarService;
29 import com.android.systemui.CoreStartable;
30 import com.android.systemui.animation.ActivityTransitionAnimator;
31 import com.android.systemui.animation.AnimationFeatureFlags;
32 import com.android.systemui.animation.DialogTransitionAnimator;
33 import com.android.systemui.bouncer.domain.interactor.AlternateBouncerInteractor;
34 import com.android.systemui.dagger.SysUISingleton;
35 import com.android.systemui.dagger.qualifiers.Background;
36 import com.android.systemui.dagger.qualifiers.Main;
37 import com.android.systemui.dump.DumpHandler;
38 import com.android.systemui.dump.DumpManager;
39 import com.android.systemui.media.controls.domain.pipeline.MediaDataManager;
40 import com.android.systemui.power.domain.interactor.PowerInteractor;
41 import com.android.systemui.scene.shared.flag.SceneContainerFlag;
42 import com.android.systemui.settings.DisplayTracker;
43 import com.android.systemui.shade.NotificationPanelViewController;
44 import com.android.systemui.shade.ShadeSurface;
45 import com.android.systemui.shade.ShadeSurfaceImpl;
46 import com.android.systemui.shade.carrier.ShadeCarrierGroupController;
47 import com.android.systemui.statusbar.CommandQueue;
48 import com.android.systemui.statusbar.NotificationClickNotifier;
49 import com.android.systemui.statusbar.NotificationMediaManager;
50 import com.android.systemui.statusbar.NotificationRemoteInputManager;
51 import com.android.systemui.statusbar.SmartReplyController;
52 import com.android.systemui.statusbar.StatusBarStateControllerImpl;
53 import com.android.systemui.statusbar.SysuiStatusBarStateController;
54 import com.android.systemui.statusbar.commandline.CommandRegistry;
55 import com.android.systemui.statusbar.notification.collection.NotifCollection;
56 import com.android.systemui.statusbar.notification.collection.NotifPipeline;
57 import com.android.systemui.statusbar.notification.collection.render.NotificationVisibilityProvider;
58 import com.android.systemui.statusbar.phone.CentralSurfacesImpl;
59 import com.android.systemui.statusbar.phone.ManagedProfileController;
60 import com.android.systemui.statusbar.phone.ManagedProfileControllerImpl;
61 import com.android.systemui.statusbar.phone.StatusBarRemoteInputCallback;
62 import com.android.systemui.statusbar.phone.ui.StatusBarIconController;
63 import com.android.systemui.statusbar.phone.ui.StatusBarIconControllerImpl;
64 import com.android.systemui.statusbar.phone.ui.StatusBarIconList;
65 import com.android.systemui.statusbar.policy.KeyguardStateController;
66 
67 import dagger.Binds;
68 import dagger.Lazy;
69 import dagger.Module;
70 import dagger.Provides;
71 import dagger.multibindings.ClassKey;
72 import dagger.multibindings.IntoMap;
73 
74 import java.util.concurrent.Executor;
75 
76 import javax.inject.Provider;
77 
78 /**
79  * This module provides instances needed to construct {@link CentralSurfacesImpl}. These are moved to
80  * this separate from {@link CentralSurfacesModule} module so that components that wish to build
81  * their own version of CentralSurfaces can include just dependencies, without injecting
82  * CentralSurfaces itself.
83  */
84 @Module
85 public interface CentralSurfacesDependenciesModule {
86 
87     /** */
88     @Binds
89     @IntoMap
90     @ClassKey(NotificationRemoteInputManager.class)
bindsStartNotificationRemoteInputManager(NotificationRemoteInputManager nrim)91     CoreStartable bindsStartNotificationRemoteInputManager(NotificationRemoteInputManager nrim);
92 
93     /** */
94     @SysUISingleton
95     @Provides
provideNotificationMediaManager( Context context, NotificationVisibilityProvider visibilityProvider, NotifPipeline notifPipeline, NotifCollection notifCollection, MediaDataManager mediaDataManager, DumpManager dumpManager, @Background Executor backgroundExecutor, @Main Handler handler)96     static NotificationMediaManager provideNotificationMediaManager(
97             Context context,
98             NotificationVisibilityProvider visibilityProvider,
99             NotifPipeline notifPipeline,
100             NotifCollection notifCollection,
101             MediaDataManager mediaDataManager,
102             DumpManager dumpManager,
103             @Background Executor backgroundExecutor,
104             @Main Handler handler) {
105         return new NotificationMediaManager(
106                 context,
107                 visibilityProvider,
108                 notifPipeline,
109                 notifCollection,
110                 mediaDataManager,
111                 dumpManager,
112                 backgroundExecutor,
113                 handler);
114     }
115 
116     /** */
117     @SysUISingleton
118     @Provides
provideSmartReplyController( DumpManager dumpManager, NotificationVisibilityProvider visibilityProvider, IStatusBarService statusBarService, NotificationClickNotifier clickNotifier)119     static SmartReplyController provideSmartReplyController(
120             DumpManager dumpManager,
121             NotificationVisibilityProvider visibilityProvider,
122             IStatusBarService statusBarService,
123             NotificationClickNotifier clickNotifier) {
124         return new SmartReplyController(
125                 dumpManager,
126                 visibilityProvider,
127                 statusBarService,
128                 clickNotifier);
129     }
130 
131 
132     /** */
133     @Binds
provideNotificationRemoteInputManagerCallback( StatusBarRemoteInputCallback callbackImpl)134     NotificationRemoteInputManager.Callback provideNotificationRemoteInputManagerCallback(
135             StatusBarRemoteInputCallback callbackImpl);
136 
137     /**
138      * Provides our instance of CommandQueue which is considered optional.
139      */
140     @Provides
141     @SysUISingleton
provideCommandQueue( Context context, DisplayTracker displayTracker, CommandRegistry registry, DumpHandler dumpHandler, Lazy<PowerInteractor> powerInteractor )142     static CommandQueue provideCommandQueue(
143             Context context,
144             DisplayTracker displayTracker,
145             CommandRegistry registry,
146             DumpHandler dumpHandler,
147             Lazy<PowerInteractor> powerInteractor
148     ) {
149         return new CommandQueue(context, displayTracker, registry, dumpHandler, powerInteractor);
150     }
151 
152     /** */
153     @Binds
provideManagedProfileController( ManagedProfileControllerImpl controllerImpl)154     ManagedProfileController provideManagedProfileController(
155             ManagedProfileControllerImpl controllerImpl);
156 
157     /** */
158     @Binds
providesSysuiStatusBarStateController( StatusBarStateControllerImpl statusBarStateControllerImpl)159     SysuiStatusBarStateController providesSysuiStatusBarStateController(
160             StatusBarStateControllerImpl statusBarStateControllerImpl);
161 
162     /** */
163     @Binds
164     @IntoMap
165     @ClassKey(SysuiStatusBarStateController.class)
bindsStartStatusBarStateController(StatusBarStateControllerImpl sbsc)166     CoreStartable bindsStartStatusBarStateController(StatusBarStateControllerImpl sbsc);
167 
168     /** */
169     @Binds
provideStatusBarIconController( StatusBarIconControllerImpl controllerImpl)170     StatusBarIconController provideStatusBarIconController(
171             StatusBarIconControllerImpl controllerImpl);
172 
173     /**
174      */
175     @Provides
176     @SysUISingleton
provideStatusBarIconList(Context context)177     static StatusBarIconList provideStatusBarIconList(Context context) {
178         return new StatusBarIconList(
179                 context.getResources().getStringArray(
180                         com.android.internal.R.array.config_statusBarIcons));
181     }
182 
183     /**
184      * {@link NotificationPanelViewController} implements two interfaces:
185      *  - {@link com.android.systemui.shade.ShadeViewController}, which can be used by any class
186      *    needing access to the shade.
187      *  - {@link ShadeSurface}, which should *only* be used by {@link CentralSurfacesImpl}.
188      *
189      * Since {@link ShadeSurface} should only be accessible by {@link CentralSurfacesImpl}, it's
190      * *only* bound in this CentralSurfaces dependencies module.
191      * The {@link com.android.systemui.shade.ShadeViewController} interface is bound in
192      * {@link com.android.systemui.shade.ShadeModule} so others can access it.
193      */
194     @Provides
195     @SysUISingleton
provideShadeSurface( Provider<ShadeSurfaceImpl> sceneContainerOn, Provider<NotificationPanelViewController> sceneContainerOff)196     static ShadeSurface provideShadeSurface(
197             Provider<ShadeSurfaceImpl> sceneContainerOn,
198             Provider<NotificationPanelViewController> sceneContainerOff) {
199         if (SceneContainerFlag.isEnabled()) {
200             return sceneContainerOn.get();
201         } else {
202             return sceneContainerOff.get();
203         }
204 
205     }
206 
207 
208     /** */
209     @Binds
provideSlotIndexResolver( ShadeCarrierGroupController.SubscriptionManagerSlotIndexResolver impl)210     ShadeCarrierGroupController.SlotIndexResolver provideSlotIndexResolver(
211             ShadeCarrierGroupController.SubscriptionManagerSlotIndexResolver impl);
212 
213     /** */
214     @Provides
215     @SysUISingleton
provideActivityTransitionAnimator( @ain Executor mainExecutor)216     static ActivityTransitionAnimator provideActivityTransitionAnimator(
217             @Main Executor mainExecutor) {
218         return new ActivityTransitionAnimator(mainExecutor);
219     }
220 
221     /** */
222     @Provides
223     @SysUISingleton
provideDialogTransitionAnimator(@ain Executor mainExecutor, IDreamManager dreamManager, KeyguardStateController keyguardStateController, Lazy<AlternateBouncerInteractor> alternateBouncerInteractor, InteractionJankMonitor interactionJankMonitor, AnimationFeatureFlags animationFeatureFlags)224     static DialogTransitionAnimator provideDialogTransitionAnimator(@Main Executor mainExecutor,
225             IDreamManager dreamManager,
226             KeyguardStateController keyguardStateController,
227             Lazy<AlternateBouncerInteractor> alternateBouncerInteractor,
228             InteractionJankMonitor interactionJankMonitor,
229             AnimationFeatureFlags animationFeatureFlags) {
230         DialogTransitionAnimator.Callback callback = new DialogTransitionAnimator.Callback() {
231             @Override
232             public boolean isDreaming() {
233                 try {
234                     return dreamManager.isDreaming();
235                 } catch (RemoteException e) {
236                     Log.e("DialogTransitionAnimator.Callback", "dreamManager.isDreaming failed", e);
237                     return false;
238                 }
239             }
240 
241             @Override
242             public boolean isUnlocked() {
243                 return keyguardStateController.isUnlocked();
244             }
245 
246             @Override
247             public boolean isShowingAlternateAuthOnUnlock() {
248                 return alternateBouncerInteractor.get().canShowAlternateBouncerForFingerprint();
249             }
250         };
251         return new DialogTransitionAnimator(
252                 mainExecutor, callback, interactionJankMonitor, animationFeatureFlags);
253     }
254 
255     /** */
256     @Provides
257     @SysUISingleton
provideAnimationFeatureFlags()258     static AnimationFeatureFlags provideAnimationFeatureFlags() {
259         return new AnimationFeatureFlags() {
260             @Override
261             public boolean isPredictiveBackQsDialogAnim() {
262                 return predictiveBackAnimateDialogs();
263             }
264         };
265     }
266 }
267