• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * 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.init
18 
19 import android.service.notification.StatusBarNotification
20 import com.android.systemui.dagger.SysUISingleton
21 import com.android.systemui.media.NotificationMediaManager
22 import com.android.systemui.people.widget.PeopleSpaceWidgetManager
23 import com.android.systemui.plugins.statusbar.NotificationSwipeActionHelper.SnoozeOption
24 import com.android.systemui.statusbar.NotificationListener
25 import com.android.systemui.statusbar.NotificationPresenter
26 import com.android.systemui.statusbar.notification.AnimatedImageNotificationManager
27 import com.android.systemui.statusbar.notification.NotificationActivityStarter
28 import com.android.systemui.statusbar.notification.NotificationClicker
29 import com.android.systemui.statusbar.notification.collection.NotifLiveDataStore
30 import com.android.systemui.statusbar.notification.collection.NotifPipeline
31 import com.android.systemui.statusbar.notification.collection.NotificationEntry
32 import com.android.systemui.statusbar.notification.collection.TargetSdkResolver
33 import com.android.systemui.statusbar.notification.collection.inflation.NotificationRowBinderImpl
34 import com.android.systemui.statusbar.notification.collection.init.NotifPipelineInitializer
35 import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection
36 import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener
37 import com.android.systemui.statusbar.notification.interruption.HeadsUpViewBinder
38 import com.android.systemui.statusbar.notification.logging.NotificationLogger
39 import com.android.systemui.statusbar.notification.row.NotifBindPipelineInitializer
40 import com.android.systemui.statusbar.notification.shared.NotificationsLiveDataStoreRefactor
41 import com.android.systemui.statusbar.notification.stack.NotificationListContainer
42 import com.android.wm.shell.bubbles.Bubbles
43 import dagger.Lazy
44 import java.util.Optional
45 import javax.inject.Inject
46 
47 /**
48  * Master controller for all notifications-related work
49  *
50  * At the moment exposes a number of event-handler-esque methods; these are for historical reasons.
51  * Once we migrate away from the need for such things, this class becomes primarily a place to do
52  * any initialization work that notifications require.
53  */
54 @SysUISingleton
55 class NotificationsControllerImpl
56 @Inject
57 constructor(
58     private val notificationListener: NotificationListener,
59     private val commonNotifCollection: Lazy<CommonNotifCollection>,
60     private val notifPipeline: Lazy<NotifPipeline>,
61     private val notifLiveDataStore: NotifLiveDataStore,
62     private val targetSdkResolver: TargetSdkResolver,
63     private val notifPipelineInitializer: Lazy<NotifPipelineInitializer>,
64     private val notifBindPipelineInitializer: NotifBindPipelineInitializer,
65     private val notificationLoggerOptional: Optional<NotificationLogger>,
66     private val notificationRowBinder: NotificationRowBinderImpl,
67     private val notificationsMediaManager: NotificationMediaManager,
68     private val headsUpViewBinder: HeadsUpViewBinder,
69     private val clickerBuilder: NotificationClicker.Builder,
70     private val animatedImageNotificationManager: AnimatedImageNotificationManager,
71     private val peopleSpaceWidgetManager: PeopleSpaceWidgetManager,
72     private val bubblesOptional: Optional<Bubbles>,
73 ) : NotificationsController {
74 
75     override fun initialize(
76         presenter: NotificationPresenter,
77         listContainer: NotificationListContainer,
78         notificationActivityStarter: NotificationActivityStarter,
79     ) {
80         notificationListener.registerAsSystemService()
81 
82         notifPipeline
83             .get()
84             .addCollectionListener(
85                 object : NotifCollectionListener {
86                     override fun onEntryRemoved(entry: NotificationEntry, reason: Int) {
87                         listContainer.cleanUpViewStateForEntry(entry)
88                     }
89                 }
90             )
91 
92         notificationRowBinder.setNotificationClicker(
93             clickerBuilder.build(bubblesOptional, notificationActivityStarter)
94         )
95         notificationRowBinder.setUpWithPresenter(presenter, listContainer)
96         notifBindPipelineInitializer.initialize()
97         animatedImageNotificationManager.bind()
98 
99         notifPipelineInitializer
100             .get()
101             .initialize(notificationListener, notificationRowBinder, listContainer)
102 
103         targetSdkResolver.initialize(notifPipeline.get())
104         notificationsMediaManager.setUpWithPresenter(presenter)
105         if (!NotificationsLiveDataStoreRefactor.isEnabled) {
106             notificationLoggerOptional.ifPresent { logger ->
107                 logger.setUpWithContainer(listContainer)
108             }
109         }
110         peopleSpaceWidgetManager.attach(notificationListener)
111     }
112 
113     // TODO: Convert all functions below this line into listeners instead of public methods
114 
115     override fun resetUserExpandedStates() {
116         // TODO: this is a view thing that should be done through the views, but that means doing it
117         //  both when this event is fired and any time a row is attached.
118         for (entry in commonNotifCollection.get().allNotifs) {
119             entry.resetUserExpansion()
120         }
121     }
122 
123     override fun setNotificationSnoozed(sbn: StatusBarNotification, snoozeOption: SnoozeOption) {
124         if (snoozeOption.snoozeCriterion != null) {
125             notificationListener.snoozeNotification(sbn.key, snoozeOption.snoozeCriterion.id)
126         } else {
127             notificationListener.snoozeNotification(
128                 sbn.key,
129                 snoozeOption.minutesToSnoozeFor * 60 * 1000.toLong(),
130             )
131         }
132     }
133 
134     override fun getActiveNotificationsCount(): Int {
135         NotificationsLiveDataStoreRefactor.assertInLegacyMode()
136         return notifLiveDataStore.activeNotifCount.value
137     }
138 }
139