• 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.systemui.statusbar.notification.collection.NotifCollection
24 import com.android.systemui.statusbar.notification.collection.NotificationEntry
25 
26 /**
27  * Set of classes that represent the various events that [NotifCollection] can dispatch to
28  * [NotifCollectionListener]s.
29  *
30  * These events build up in a queue and are periodically emitted in chunks by the collection.
31  */
32 
33 sealed class NotifEvent {
dispatchTonull34     fun dispatchTo(listeners: List<NotifCollectionListener>) {
35         for (i in listeners.indices) {
36             dispatchToListener(listeners[i])
37         }
38     }
39 
dispatchToListenernull40     abstract fun dispatchToListener(listener: NotifCollectionListener)
41 }
42 
43 data class BindEntryEvent(
44     val entry: NotificationEntry,
45     val sbn: StatusBarNotification
46 ) : NotifEvent() {
47     override fun dispatchToListener(listener: NotifCollectionListener) {
48         listener.onEntryBind(entry, sbn)
49     }
50 }
51 
52 data class InitEntryEvent(
53     val entry: NotificationEntry
54 ) : NotifEvent() {
dispatchToListenernull55     override fun dispatchToListener(listener: NotifCollectionListener) {
56         listener.onEntryInit(entry)
57     }
58 }
59 
60 data class EntryAddedEvent(
61     val entry: NotificationEntry
62 ) : NotifEvent() {
dispatchToListenernull63     override fun dispatchToListener(listener: NotifCollectionListener) {
64         listener.onEntryAdded(entry)
65     }
66 }
67 
68 data class EntryUpdatedEvent(
69     val entry: NotificationEntry,
70     val fromSystem: Boolean
71 ) : NotifEvent() {
dispatchToListenernull72     override fun dispatchToListener(listener: NotifCollectionListener) {
73         listener.onEntryUpdated(entry, fromSystem)
74     }
75 }
76 
77 data class EntryRemovedEvent(
78     val entry: NotificationEntry,
79     val reason: Int
80 ) : NotifEvent() {
dispatchToListenernull81     override fun dispatchToListener(listener: NotifCollectionListener) {
82         listener.onEntryRemoved(entry, reason)
83     }
84 }
85 
86 data class CleanUpEntryEvent(
87     val entry: NotificationEntry
88 ) : NotifEvent() {
dispatchToListenernull89     override fun dispatchToListener(listener: NotifCollectionListener) {
90         listener.onEntryCleanUp(entry)
91     }
92 }
93 
94 data class RankingUpdatedEvent(
95     val rankingMap: RankingMap
96 ) : NotifEvent() {
dispatchToListenernull97     override fun dispatchToListener(listener: NotifCollectionListener) {
98         listener.onRankingUpdate(rankingMap)
99     }
100 }
101 
102 class RankingAppliedEvent() : NotifEvent() {
dispatchToListenernull103     override fun dispatchToListener(listener: NotifCollectionListener) {
104         listener.onRankingApplied()
105     }
106 }
107 
108 data class ChannelChangedEvent(
109     val pkgName: String,
110     val user: UserHandle,
111     val channel: NotificationChannel,
112     val modificationType: Int
113 ) : NotifEvent() {
dispatchToListenernull114     override fun dispatchToListener(listener: NotifCollectionListener) {
115         listener.onNotificationChannelModified(pkgName, user, channel, modificationType)
116     }
117 }
118