1 /*
2  * Copyright (C) 2018 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;
17 
18 import android.annotation.Nullable;
19 import android.service.notification.NotificationListenerService;
20 import android.service.notification.NotificationListenerService.RankingMap;
21 import android.service.notification.StatusBarNotification;
22 
23 import androidx.annotation.NonNull;
24 
25 import com.android.internal.statusbar.NotificationVisibility;
26 import com.android.systemui.statusbar.notification.collection.NotificationEntry;
27 
28 /**
29  * Listener interface for changes sent by NotificationEntryManager.
30  */
31 public interface NotificationEntryListener {
32     /**
33      * Called when a new notification is posted. At this point, the notification is "pending": its
34      * views haven't been inflated yet and most of the system pretends like it doesn't exist yet.
35      */
onPendingEntryAdded(NotificationEntry entry)36     default void onPendingEntryAdded(NotificationEntry entry) {
37     }
38 
39     /**
40      * Called when a new entry is created.
41      */
onNotificationAdded(@onNull NotificationEntry entry)42     default void onNotificationAdded(@NonNull NotificationEntry entry) {
43     }
44 
45     /**
46      * Called when a notification is about to be updated. Notification- and ranking-derived fields
47      * on the entry have already been updated but the following have not yet occurred:
48      * (a) View binding (i.e. the associated view has not yet been updated / inflation has not yet
49      *      been kicked off.
50      * (b) Notification filtering
51      */
onPreEntryUpdated(NotificationEntry entry)52     default void onPreEntryUpdated(NotificationEntry entry) {
53     }
54 
55     /**
56      * Called when a notification was updated, after any filtering of notifications have occurred.
57      */
onPostEntryUpdated(@onNull NotificationEntry entry)58     default void onPostEntryUpdated(@NonNull NotificationEntry entry) {
59     }
60 
61     /**
62      * Called when a notification's views are inflated for the first time.
63      */
onEntryInflated(NotificationEntry entry)64     default void onEntryInflated(NotificationEntry entry) {
65     }
66 
67     /**
68      * Called when an existing notification's views are reinflated (usually due to an update being
69      * posted to that notification).
70      *
71      * @param entry notification data entry that was reinflated.
72      */
onEntryReinflated(NotificationEntry entry)73     default void onEntryReinflated(NotificationEntry entry) {
74     }
75 
76     /**
77      * Called when an error occurred inflating the views for a notification.
78      */
onInflationError(StatusBarNotification notification, Exception exception)79     default void onInflationError(StatusBarNotification notification, Exception exception) {
80     }
81 
82     /**
83      * Called when a notification has been removed (either because the user swiped it away or
84      * because the developer retracted it).
85      * @param entry notification data entry that was removed.  Null if no entry existed for the
86      *              removed key at the time of removal.
87      * @param visibility logging data related to the visibility of the notification at the time of
88      *                   removal, if it was removed by a user action.  Null if it was not removed by
89      *                   a user action.
90      * @param removedByUser true if the notification was removed by a user action
91      */
onEntryRemoved( @onNull NotificationEntry entry, @Nullable NotificationVisibility visibility, boolean removedByUser, int reason)92     default void onEntryRemoved(
93             @NonNull NotificationEntry entry,
94             @Nullable NotificationVisibility visibility,
95             boolean removedByUser,
96             int reason) {
97     }
98 
99     /**
100      * Called whenever notification ranking changes, in response to
101      * {@link NotificationListenerService#onNotificationRankingUpdate}. This is called after
102      * NotificationEntryManager has processed the update and notifications have been re-sorted
103      * and filtered.
104      *
105      * @param rankingMap provides access to ranking information on currently active notifications
106      */
onNotificationRankingUpdated(RankingMap rankingMap)107     default void onNotificationRankingUpdated(RankingMap rankingMap) {
108     }
109 }
110