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 package com.android.systemui.statusbar.notification.collection.coordinator
17 
18 import com.android.systemui.flags.FeatureFlags
19 import com.android.systemui.flags.Flags.LOCKSCREEN_WALLPAPER_DREAM_ENABLED
20 import com.android.systemui.statusbar.notification.collection.NotifPipeline
21 import com.android.systemui.statusbar.notification.collection.PipelineDumpable
22 import com.android.systemui.statusbar.notification.collection.PipelineDumper
23 import com.android.systemui.statusbar.notification.collection.SortBySectionTimeFlag
24 import com.android.systemui.statusbar.notification.collection.coordinator.dagger.CoordinatorScope
25 import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifSectioner
26 import com.android.systemui.statusbar.notification.collection.provider.SectionStyleProvider
27 import com.android.systemui.statusbar.notification.shared.NotificationMinimalismPrototype
28 import com.android.systemui.statusbar.notification.shared.NotificationsLiveDataStoreRefactor
29 import com.android.systemui.statusbar.notification.shared.PriorityPeopleSection
30 import javax.inject.Inject
31 
32 /**
33  * Handles the attachment of [Coordinator]s to the [NotifPipeline] so that the Coordinators can
34  * register their respective callbacks.
35  */
36 interface NotifCoordinators : Coordinator, PipelineDumpable
37 
38 @CoordinatorScope
39 class NotifCoordinatorsImpl
40 @Inject
41 constructor(
42     sectionStyleProvider: SectionStyleProvider,
43     featureFlags: FeatureFlags,
44     dataStoreCoordinator: DataStoreCoordinator,
45     hideLocallyDismissedNotifsCoordinator: HideLocallyDismissedNotifsCoordinator,
46     hideNotifsForOtherUsersCoordinator: HideNotifsForOtherUsersCoordinator,
47     keyguardCoordinator: KeyguardCoordinator,
48     rankingCoordinator: RankingCoordinator,
49     colorizedFgsCoordinator: ColorizedFgsCoordinator,
50     deviceProvisionedCoordinator: DeviceProvisionedCoordinator,
51     bubbleCoordinator: BubbleCoordinator,
52     headsUpCoordinator: HeadsUpCoordinator,
53     gutsCoordinator: GutsCoordinator,
54     conversationCoordinator: ConversationCoordinator,
55     debugModeCoordinator: DebugModeCoordinator,
56     groupCountCoordinator: GroupCountCoordinator,
57     groupWhenCoordinator: GroupWhenCoordinator,
58     mediaCoordinator: MediaCoordinator,
59     preparationCoordinator: PreparationCoordinator,
60     remoteInputCoordinator: RemoteInputCoordinator,
61     rowAlertTimeCoordinator: RowAlertTimeCoordinator,
62     rowAppearanceCoordinator: RowAppearanceCoordinator,
63     stackCoordinator: StackCoordinator,
64     shadeEventCoordinator: ShadeEventCoordinator,
65     smartspaceDedupingCoordinator: SmartspaceDedupingCoordinator,
66     viewConfigCoordinator: ViewConfigCoordinator,
67     visualStabilityCoordinator: VisualStabilityCoordinator,
68     sensitiveContentCoordinator: SensitiveContentCoordinator,
69     dismissibilityCoordinator: DismissibilityCoordinator,
70     dreamCoordinator: DreamCoordinator,
71     statsLoggerCoordinator: NotificationStatsLoggerCoordinator,
72 ) : NotifCoordinators {
73 
74     private val mCoreCoordinators: MutableList<CoreCoordinator> = ArrayList()
75     private val mCoordinators: MutableList<Coordinator> = ArrayList()
76     private val mOrderedSections: MutableList<NotifSectioner> = ArrayList()
77 
78     /** Creates all the coordinators. */
79     init {
80         // Attach core coordinators.
81         mCoreCoordinators.add(dataStoreCoordinator)
82 
83         // Attach normal coordinators.
84         mCoordinators.add(hideLocallyDismissedNotifsCoordinator)
85         mCoordinators.add(hideNotifsForOtherUsersCoordinator)
86         mCoordinators.add(keyguardCoordinator)
87         mCoordinators.add(rankingCoordinator)
88         mCoordinators.add(colorizedFgsCoordinator)
89         mCoordinators.add(deviceProvisionedCoordinator)
90         mCoordinators.add(bubbleCoordinator)
91         mCoordinators.add(debugModeCoordinator)
92         mCoordinators.add(conversationCoordinator)
93         mCoordinators.add(groupCountCoordinator)
94         mCoordinators.add(groupWhenCoordinator)
95         mCoordinators.add(mediaCoordinator)
96         mCoordinators.add(rowAlertTimeCoordinator)
97         mCoordinators.add(rowAppearanceCoordinator)
98         mCoordinators.add(stackCoordinator)
99         mCoordinators.add(shadeEventCoordinator)
100         mCoordinators.add(viewConfigCoordinator)
101         mCoordinators.add(visualStabilityCoordinator)
102         mCoordinators.add(sensitiveContentCoordinator)
103         mCoordinators.add(smartspaceDedupingCoordinator)
104         mCoordinators.add(headsUpCoordinator)
105         mCoordinators.add(gutsCoordinator)
106         mCoordinators.add(preparationCoordinator)
107         mCoordinators.add(remoteInputCoordinator)
108         mCoordinators.add(dismissibilityCoordinator)
109 
110         if (featureFlags.isEnabled(LOCKSCREEN_WALLPAPER_DREAM_ENABLED)) {
111             mCoordinators.add(dreamCoordinator)
112         }
113 
114         if (NotificationsLiveDataStoreRefactor.isEnabled) {
115             mCoordinators.add(statsLoggerCoordinator)
116         }
117 
118         // Manually add Ordered Sections
119         if (NotificationMinimalismPrototype.V2.isEnabled) {
120             mOrderedSections.add(keyguardCoordinator.topOngoingSectioner) // Top Ongoing
121         }
122         mOrderedSections.add(headsUpCoordinator.sectioner) // HeadsUp
123         if (NotificationMinimalismPrototype.V2.isEnabled) {
124             mOrderedSections.add(keyguardCoordinator.topUnseenSectioner) // Top Unseen
125         }
126         mOrderedSections.add(colorizedFgsCoordinator.sectioner) // ForegroundService
127         if (PriorityPeopleSection.isEnabled) {
128             mOrderedSections.add(conversationCoordinator.priorityPeopleSectioner) // Priority People
129         }
130         mOrderedSections.add(conversationCoordinator.peopleAlertingSectioner) // People Alerting
131         if (!SortBySectionTimeFlag.isEnabled) {
132             mOrderedSections.add(conversationCoordinator.peopleSilentSectioner) // People Silent
133         }
134         mOrderedSections.add(rankingCoordinator.alertingSectioner) // Alerting
135         mOrderedSections.add(rankingCoordinator.silentSectioner) // Silent
136         mOrderedSections.add(rankingCoordinator.minimizedSectioner) // Minimized
137 
138         sectionStyleProvider.setMinimizedSections(setOf(rankingCoordinator.minimizedSectioner))
139         if (SortBySectionTimeFlag.isEnabled) {
140             sectionStyleProvider.setSilentSections(
141                 listOf(
142                     rankingCoordinator.silentSectioner,
143                     rankingCoordinator.minimizedSectioner,
144                 )
145             )
146         } else {
147             sectionStyleProvider.setSilentSections(
148                 listOf(
149                     conversationCoordinator.peopleSilentSectioner,
150                     rankingCoordinator.silentSectioner,
151                     rankingCoordinator.minimizedSectioner,
152                 )
153             )
154         }
155     }
156 
157     /**
158      * Sends the pipeline to each coordinator when the pipeline is ready to accept [Pluggable]s,
159      * [NotifCollectionListener]s and [NotifLifetimeExtender]s.
160      */
attachnull161     override fun attach(pipeline: NotifPipeline) {
162         for (c in mCoreCoordinators) {
163             c.attach(pipeline)
164         }
165         for (c in mCoordinators) {
166             c.attach(pipeline)
167         }
168         pipeline.setSections(mOrderedSections)
169     }
170 
171     /*
172      * As part of the NotifPipeline dumpable, dumps the list of coordinators; sections are omitted
173      * as they are dumped in the RenderStageManager instead.
174      */
dumpPipelinenull175     override fun dumpPipeline(d: PipelineDumper) =
176         with(d) {
177             dump("core coordinators", mCoreCoordinators)
178             dump("normal coordinators", mCoordinators)
179         }
180 
181     companion object {
182         private const val TAG = "NotifCoordinators"
183     }
184 }
185