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.notification.dagger;
18 
19 import android.app.NotificationManager;
20 import android.content.Context;
21 import android.service.notification.NotificationListenerService;
22 
23 import com.android.internal.jank.InteractionJankMonitor;
24 import com.android.settingslib.statusbar.notification.data.repository.NotificationsSoundPolicyRepository;
25 import com.android.settingslib.statusbar.notification.data.repository.NotificationsSoundPolicyRepositoryImpl;
26 import com.android.settingslib.statusbar.notification.domain.interactor.NotificationsSoundPolicyInteractor;
27 import com.android.systemui.CoreStartable;
28 import com.android.systemui.dagger.SysUISingleton;
29 import com.android.systemui.dagger.qualifiers.Application;
30 import com.android.systemui.dagger.qualifiers.Background;
31 import com.android.systemui.res.R;
32 import com.android.systemui.statusbar.NotificationListener;
33 import com.android.systemui.statusbar.notification.NotificationActivityStarter;
34 import com.android.systemui.statusbar.notification.NotificationLaunchAnimatorControllerProvider;
35 import com.android.systemui.statusbar.notification.VisibilityLocationProvider;
36 import com.android.systemui.statusbar.notification.collection.NotifInflaterImpl;
37 import com.android.systemui.statusbar.notification.collection.NotifLiveDataStore;
38 import com.android.systemui.statusbar.notification.collection.NotifLiveDataStoreImpl;
39 import com.android.systemui.statusbar.notification.collection.NotifPipeline;
40 import com.android.systemui.statusbar.notification.collection.NotifPipelineChoreographerModule;
41 import com.android.systemui.statusbar.notification.collection.coordinator.ShadeEventCoordinator;
42 import com.android.systemui.statusbar.notification.collection.coordinator.dagger.CoordinatorsModule;
43 import com.android.systemui.statusbar.notification.collection.inflation.BindEventManager;
44 import com.android.systemui.statusbar.notification.collection.inflation.BindEventManagerImpl;
45 import com.android.systemui.statusbar.notification.collection.inflation.NotifInflater;
46 import com.android.systemui.statusbar.notification.collection.inflation.OnUserInteractionCallbackImpl;
47 import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection;
48 import com.android.systemui.statusbar.notification.collection.provider.NotificationDismissibilityProvider;
49 import com.android.systemui.statusbar.notification.collection.provider.NotificationDismissibilityProviderImpl;
50 import com.android.systemui.statusbar.notification.collection.provider.NotificationVisibilityProviderImpl;
51 import com.android.systemui.statusbar.notification.collection.provider.VisibilityLocationProviderDelegator;
52 import com.android.systemui.statusbar.notification.collection.render.GroupExpansionManager;
53 import com.android.systemui.statusbar.notification.collection.render.GroupExpansionManagerImpl;
54 import com.android.systemui.statusbar.notification.collection.render.GroupMembershipManager;
55 import com.android.systemui.statusbar.notification.collection.render.GroupMembershipManagerImpl;
56 import com.android.systemui.statusbar.notification.collection.render.NotifGutsViewManager;
57 import com.android.systemui.statusbar.notification.collection.render.NotifShadeEventSource;
58 import com.android.systemui.statusbar.notification.collection.render.NotificationVisibilityProvider;
59 import com.android.systemui.statusbar.notification.data.NotificationDataLayerModule;
60 import com.android.systemui.statusbar.notification.domain.NotificationDomainLayerModule;
61 import com.android.systemui.statusbar.notification.domain.interactor.NotificationLaunchAnimationInteractor;
62 import com.android.systemui.statusbar.notification.footer.ui.viewmodel.FooterViewModelModule;
63 import com.android.systemui.statusbar.notification.icon.ConversationIconManager;
64 import com.android.systemui.statusbar.notification.icon.IconManager;
65 import com.android.systemui.statusbar.notification.init.NotificationsController;
66 import com.android.systemui.statusbar.notification.init.NotificationsControllerImpl;
67 import com.android.systemui.statusbar.notification.init.NotificationsControllerStub;
68 import com.android.systemui.statusbar.notification.interruption.KeyguardNotificationVisibilityProviderModule;
69 import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProvider;
70 import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProviderImpl;
71 import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProviderWrapper;
72 import com.android.systemui.statusbar.notification.interruption.VisualInterruptionDecisionProvider;
73 import com.android.systemui.statusbar.notification.interruption.VisualInterruptionDecisionProviderImpl;
74 import com.android.systemui.statusbar.notification.interruption.VisualInterruptionRefactor;
75 import com.android.systemui.statusbar.notification.logging.NotificationPanelLogger;
76 import com.android.systemui.statusbar.notification.logging.NotificationPanelLoggerImpl;
77 import com.android.systemui.statusbar.notification.row.NotificationEntryProcessorFactory;
78 import com.android.systemui.statusbar.notification.row.NotificationEntryProcessorFactoryLooperImpl;
79 import com.android.systemui.statusbar.notification.row.NotificationGutsManager;
80 import com.android.systemui.statusbar.notification.row.OnUserInteractionCallback;
81 import com.android.systemui.statusbar.notification.row.ui.viewmodel.ActivatableNotificationViewModelModule;
82 import com.android.systemui.statusbar.notification.stack.NotificationListContainer;
83 import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager;
84 import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayoutController;
85 import com.android.systemui.statusbar.notification.stack.StackScrollAlgorithm;
86 import com.android.systemui.statusbar.phone.KeyguardBypassController;
87 import com.android.systemui.statusbar.phone.StatusBarNotificationActivityStarter;
88 import com.android.systemui.statusbar.policy.HeadsUpManager;
89 
90 import dagger.Binds;
91 import dagger.Module;
92 import dagger.Provides;
93 import dagger.multibindings.ClassKey;
94 import dagger.multibindings.IntoMap;
95 
96 import kotlin.coroutines.CoroutineContext;
97 
98 import kotlinx.coroutines.CoroutineScope;
99 
100 import javax.inject.Provider;
101 
102 /**
103  * Dagger Module for classes found within the com.android.systemui.statusbar.notification package.
104  */
105 @Module(includes = {
106         CoordinatorsModule.class,
107         FooterViewModelModule.class,
108         KeyguardNotificationVisibilityProviderModule.class,
109         NotificationDataLayerModule.class,
110         NotificationDomainLayerModule.class,
111         NotifPipelineChoreographerModule.class,
112         NotificationSectionHeadersModule.class,
113         ActivatableNotificationViewModelModule.class,
114         NotificationMemoryModule.class,
115         NotificationStatsLoggerModule.class,
116 })
117 public interface NotificationsModule {
118     @Binds
bindSectionProvider(NotificationSectionsManager impl)119     StackScrollAlgorithm.SectionProvider bindSectionProvider(NotificationSectionsManager impl);
120 
121     @Binds
bindBypassController(KeyguardBypassController impl)122     StackScrollAlgorithm.BypassController bindBypassController(KeyguardBypassController impl);
123 
124     /** Provides an instance of {@link NotifGutsViewManager} */
125     @Binds
bindNotifGutsViewManager(NotificationGutsManager notificationGutsManager)126     NotifGutsViewManager bindNotifGutsViewManager(NotificationGutsManager notificationGutsManager);
127 
128     /** Binds {@link NotificationGutsManager} as a {@link CoreStartable}. */
129     @Binds
130     @IntoMap
131     @ClassKey(NotificationGutsManager.class)
bindsNotificationGutsManager(NotificationGutsManager notificationGutsManager)132     CoreStartable bindsNotificationGutsManager(NotificationGutsManager notificationGutsManager);
133 
134 
135     /** Provides an instance of {@link VisibilityLocationProvider} */
136     @Binds
bindVisibilityLocationProvider( VisibilityLocationProviderDelegator visibilityLocationProviderDelegator)137     VisibilityLocationProvider bindVisibilityLocationProvider(
138             VisibilityLocationProviderDelegator visibilityLocationProviderDelegator);
139 
140     /** Provides an instance of {@link NotificationPanelLogger} */
141     @SysUISingleton
142     @Provides
provideNotificationPanelLogger()143     static NotificationPanelLogger provideNotificationPanelLogger() {
144         return new NotificationPanelLoggerImpl();
145     }
146 
147     /** Provides an instance of {@link GroupMembershipManager} */
148     @Binds
provideGroupMembershipManager(GroupMembershipManagerImpl impl)149     GroupMembershipManager provideGroupMembershipManager(GroupMembershipManagerImpl impl);
150 
151     /** Provides an instance of {@link GroupExpansionManager} */
152     @Binds
provideGroupExpansionManager(GroupExpansionManagerImpl impl)153     GroupExpansionManager provideGroupExpansionManager(GroupExpansionManagerImpl impl);
154 
155     /** Provides an instance of {@link NotificationActivityStarter}. */
156     @Binds
bindActivityStarter(StatusBarNotificationActivityStarter impl)157     NotificationActivityStarter bindActivityStarter(StatusBarNotificationActivityStarter impl);
158 
159     /** Initializes the notification data pipeline (can be disabled via config). */
160     @SysUISingleton
161     @Provides
provideNotificationsController( Context context, Provider<NotificationsControllerImpl> realController, Provider<NotificationsControllerStub> stubController)162     static NotificationsController provideNotificationsController(
163             Context context,
164             Provider<NotificationsControllerImpl> realController,
165             Provider<NotificationsControllerStub> stubController) {
166         if (context.getResources().getBoolean(R.bool.config_renderNotifications)) {
167             return realController.get();
168         } else {
169             return stubController.get();
170         }
171     }
172 
173     /** Provides the container for the notification list. */
174     @Provides
175     @SysUISingleton
provideListContainer( NotificationStackScrollLayoutController nsslController)176     static NotificationListContainer provideListContainer(
177             NotificationStackScrollLayoutController nsslController) {
178         return nsslController.getNotificationListContainer();
179     }
180 
181     /** Provides notification launch animator. */
182     @Provides
183     @SysUISingleton
184     static NotificationLaunchAnimatorControllerProvider
provideNotificationTransitionAnimatorControllerProvider( NotificationLaunchAnimationInteractor notificationLaunchAnimationInteractor, NotificationListContainer notificationListContainer, HeadsUpManager headsUpManager, InteractionJankMonitor jankMonitor)185             provideNotificationTransitionAnimatorControllerProvider(
186                     NotificationLaunchAnimationInteractor notificationLaunchAnimationInteractor,
187                     NotificationListContainer notificationListContainer,
188                     HeadsUpManager headsUpManager,
189                     InteractionJankMonitor jankMonitor) {
190         return new NotificationLaunchAnimatorControllerProvider(
191                 notificationLaunchAnimationInteractor,
192                 notificationListContainer,
193                 headsUpManager,
194                 jankMonitor);
195     }
196 
197     /**
198      * Provide the active notification collection managing the notifications to render.
199      */
200     @Binds
provideCommonNotifCollection(NotifPipeline pipeline)201     CommonNotifCollection provideCommonNotifCollection(NotifPipeline pipeline);
202 
203     /**
204      * Provide the object which can be used to obtain dismissibility of a Notification.
205      */
206     @Binds
provideNotificationDismissibilityProvider( NotificationDismissibilityProviderImpl impl)207     NotificationDismissibilityProvider provideNotificationDismissibilityProvider(
208             NotificationDismissibilityProviderImpl impl);
209 
210     /**
211      * Provide the object which can be used to obtain NotificationVisibility objects.
212      */
213     @Binds
provideNotificationVisibilityProvider( NotificationVisibilityProviderImpl impl)214     NotificationVisibilityProvider provideNotificationVisibilityProvider(
215             NotificationVisibilityProviderImpl impl);
216 
217     /**
218      * Provide the active implementation for presenting notifications.
219      */
220     @Binds
provideNotifShadeEventSource(ShadeEventCoordinator shadeEventCoordinator)221     NotifShadeEventSource provideNotifShadeEventSource(ShadeEventCoordinator shadeEventCoordinator);
222 
223     /**
224      * Provide a dismissal callback that's triggered when a user manually dismissed a notification
225      * from the notification shade or it gets auto-cancelled by click.
226      */
227     @Binds
provideOnUserInteractionCallback(OnUserInteractionCallbackImpl impl)228     OnUserInteractionCallback provideOnUserInteractionCallback(OnUserInteractionCallbackImpl impl);
229 
230     /** */
231     @Binds
bindNotificationInterruptStateProvider( NotificationInterruptStateProviderImpl notificationInterruptStateProviderImpl)232     NotificationInterruptStateProvider bindNotificationInterruptStateProvider(
233             NotificationInterruptStateProviderImpl notificationInterruptStateProviderImpl);
234 
235     /** */
236     @Binds
bindNotifInflater(NotifInflaterImpl notifInflaterImpl)237     NotifInflater bindNotifInflater(NotifInflaterImpl notifInflaterImpl);
238 
239     /** */
240     @Binds
bindNotificationEntryProcessorFactory( NotificationEntryProcessorFactoryLooperImpl factoryImpl)241     NotificationEntryProcessorFactory bindNotificationEntryProcessorFactory(
242             NotificationEntryProcessorFactoryLooperImpl factoryImpl);
243 
244     /** */
245     @Binds
bindConversationIconManager(IconManager iconManager)246     ConversationIconManager bindConversationIconManager(IconManager iconManager);
247 
248     /** */
249     @Binds
bindBindEventManagerImpl(BindEventManagerImpl bindEventManagerImpl)250     BindEventManager bindBindEventManagerImpl(BindEventManagerImpl bindEventManagerImpl);
251 
252     /** */
253     @Binds
bindNotifLiveDataStore(NotifLiveDataStoreImpl notifLiveDataStoreImpl)254     NotifLiveDataStore bindNotifLiveDataStore(NotifLiveDataStoreImpl notifLiveDataStoreImpl);
255 
256     /** */
257     @Binds
bindNotificationListener(NotificationListener notificationListener)258     NotificationListenerService bindNotificationListener(NotificationListener notificationListener);
259 
260     /** */
261     @Provides
262     @SysUISingleton
provideVisualInterruptionDecisionProvider( Provider<NotificationInterruptStateProviderImpl> oldImplProvider, Provider<VisualInterruptionDecisionProviderImpl> newImplProvider)263     static VisualInterruptionDecisionProvider provideVisualInterruptionDecisionProvider(
264             Provider<NotificationInterruptStateProviderImpl> oldImplProvider,
265             Provider<VisualInterruptionDecisionProviderImpl> newImplProvider) {
266         if (VisualInterruptionRefactor.isEnabled()) {
267             return newImplProvider.get();
268         } else {
269             return new NotificationInterruptStateProviderWrapper(oldImplProvider.get());
270         }
271     }
272 
273     /** */
274     @Binds
275     @IntoMap
276     @ClassKey(VisualInterruptionDecisionProvider.class)
startVisualInterruptionDecisionProvider( VisualInterruptionDecisionProvider provider)277     CoreStartable startVisualInterruptionDecisionProvider(
278             VisualInterruptionDecisionProvider provider);
279 
280     @Provides
281     @SysUISingleton
provideNotificationsSoundPolicyRepository( Context context, NotificationManager notificationManager, @Application CoroutineScope coroutineScope, @Background CoroutineContext coroutineContext)282     public static NotificationsSoundPolicyRepository provideNotificationsSoundPolicyRepository(
283             Context context,
284             NotificationManager notificationManager,
285             @Application CoroutineScope coroutineScope,
286             @Background CoroutineContext coroutineContext) {
287         return new NotificationsSoundPolicyRepositoryImpl(context, notificationManager,
288                 coroutineScope, coroutineContext);
289     }
290 
291     @Provides
292     @SysUISingleton
provideNotificationsSoundPolicyInteractror( NotificationsSoundPolicyRepository repository)293     public static NotificationsSoundPolicyInteractor provideNotificationsSoundPolicyInteractror(
294             NotificationsSoundPolicyRepository repository) {
295         return new NotificationsSoundPolicyInteractor(repository);
296     }
297 }
298