• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.collection.notifcollection
18 
19 import android.app.NotificationChannel
20 import android.os.UserHandle
21 import android.service.notification.NotificationListenerService.RankingMap
22 import android.service.notification.StatusBarNotification
23 import com.android.app.tracing.traceSection
24 import com.android.systemui.statusbar.notification.collection.NotifCollection
25 import com.android.systemui.statusbar.notification.collection.NotificationEntry
26 import com.android.systemui.util.NamedListenerSet
27 
28 /**
29  * Set of classes that represent the various events that [NotifCollection] can dispatch to
30  * [NotifCollectionListener]s.
31  *
32  * These events build up in a queue and are periodically emitted in chunks by the collection.
33  */
34 sealed class NotifEvent(private val traceName: String) {
dispatchTonull35     fun dispatchTo(listeners: NamedListenerSet<NotifCollectionListener>) {
36         traceSection(traceName) { listeners.forEachTraced(::dispatchToListener) }
37     }
38 
dispatchToListenernull39     abstract fun dispatchToListener(listener: NotifCollectionListener)
40 }
41 
42 data class BindEntryEvent(val entry: NotificationEntry, val sbn: StatusBarNotification) :
43     NotifEvent("onEntryBind") {
44     override fun dispatchToListener(listener: NotifCollectionListener) {
45         listener.onEntryBind(entry, sbn)
46     }
47 }
48 
49 data class InitEntryEvent(val entry: NotificationEntry) : NotifEvent("onEntryInit") {
dispatchToListenernull50     override fun dispatchToListener(listener: NotifCollectionListener) {
51         listener.onEntryInit(entry)
52     }
53 }
54 
55 data class EntryAddedEvent(val entry: NotificationEntry) : NotifEvent("onEntryAdded") {
dispatchToListenernull56     override fun dispatchToListener(listener: NotifCollectionListener) {
57         listener.onEntryAdded(entry)
58     }
59 }
60 
61 data class EntryUpdatedEvent(val entry: NotificationEntry, val source: UpdateSource) :
62     NotifEvent(
63         if (source == UpdateSource.SystemUi) "onEntryUpdated" else "onEntryUpdated fromSystem=true"
64     ) {
dispatchToListenernull65     override fun dispatchToListener(listener: NotifCollectionListener) {
66         listener.onEntryUpdated(entry, source)
67     }
68 }
69 
70 /** Source of an entry update. */
71 enum class UpdateSource {
72     /** From the app that posted the notification. */
73     App,
74     /** From the NotificationManagerService. */
75     SystemServer,
76     /** From SystemUi for rendering purpose. */
77     SystemUi,
78 }
79 
80 data class EntryRemovedEvent(val entry: NotificationEntry, val reason: Int) :
81     NotifEvent("onEntryRemoved ${cancellationReasonDebugString(reason)}") {
dispatchToListenernull82     override fun dispatchToListener(listener: NotifCollectionListener) {
83         listener.onEntryRemoved(entry, reason)
84     }
85 }
86 
87 data class CleanUpEntryEvent(val entry: NotificationEntry) : NotifEvent("onEntryCleanUp") {
dispatchToListenernull88     override fun dispatchToListener(listener: NotifCollectionListener) {
89         listener.onEntryCleanUp(entry)
90     }
91 }
92 
93 data class RankingUpdatedEvent(val rankingMap: RankingMap) : NotifEvent("onRankingUpdate") {
dispatchToListenernull94     override fun dispatchToListener(listener: NotifCollectionListener) {
95         listener.onRankingUpdate(rankingMap)
96     }
97 }
98 
99 class RankingAppliedEvent : NotifEvent("onRankingApplied") {
dispatchToListenernull100     override fun dispatchToListener(listener: NotifCollectionListener) {
101         listener.onRankingApplied()
102     }
103 }
104 
105 data class ChannelChangedEvent(
106     val pkgName: String,
107     val user: UserHandle,
108     val channel: NotificationChannel,
109     val modificationType: Int,
110 ) : NotifEvent("onNotificationChannelModified") {
dispatchToListenernull111     override fun dispatchToListener(listener: NotifCollectionListener) {
112         listener.onNotificationChannelModified(pkgName, user, channel, modificationType)
113     }
114 }
115