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.annotation.NonNull; 20 import android.app.NotificationChannel; 21 import android.os.UserHandle; 22 import android.service.notification.NotificationListenerService; 23 import android.service.notification.StatusBarNotification; 24 25 import com.android.systemui.statusbar.notification.collection.NotifCollection.CancellationReason; 26 import com.android.systemui.statusbar.notification.collection.NotificationEntry; 27 28 /** 29 * Listener interface for {@link NotificationEntry} events. 30 */ 31 public interface NotifCollectionListener { 32 33 /** 34 * Called when the entry is having a new status bar notification bound to it. This should 35 * be used to initialize any derivative state on the entry that needs to update when the 36 * notification is updated. 37 */ onEntryBind(NotificationEntry entry, StatusBarNotification sbn)38 default void onEntryBind(NotificationEntry entry, StatusBarNotification sbn) { 39 } 40 41 /** 42 * Called whenever a new {@link NotificationEntry} is initialized. This should be used for 43 * initializing any decorated state tied to the notification. 44 * 45 * Do not reference other registered {@link NotifCollectionListener} implementations here as 46 * there is no guarantee of order and they may not have had a chance to initialize yet. Instead, 47 * use {@link #onEntryAdded} which is called after all initialization. 48 */ onEntryInit(@onNull NotificationEntry entry)49 default void onEntryInit(@NonNull NotificationEntry entry) { 50 } 51 52 /** 53 * Called whenever a notification with a new key is posted. 54 */ onEntryAdded(@onNull NotificationEntry entry)55 default void onEntryAdded(@NonNull NotificationEntry entry) { 56 } 57 58 /** 59 * Called whenever a notification with the same key as an existing notification is posted. By 60 * the time this listener is called, the entry's SBN and Ranking will already have been updated. 61 * This delegates to {@link #onEntryUpdated(NotificationEntry)} by default. 62 * @param fromSystem If true, this update came from the NotificationManagerService. 63 * If false, the notification update is an internal change within systemui. 64 */ onEntryUpdated(@onNull NotificationEntry entry, boolean fromSystem)65 default void onEntryUpdated(@NonNull NotificationEntry entry, boolean fromSystem) { 66 onEntryUpdated(entry); 67 } 68 69 /** 70 * Called whenever a notification with the same key as an existing notification is posted. By 71 * the time this listener is called, the entry's SBN and Ranking will already have been updated. 72 */ onEntryUpdated(@onNull NotificationEntry entry)73 default void onEntryUpdated(@NonNull NotificationEntry entry) { 74 } 75 76 /** 77 * Called whenever a notification is retracted by system server. This method is not called 78 * immediately after a user dismisses a notification: we wait until we receive confirmation from 79 * system server before considering the notification removed. 80 */ onEntryRemoved(@onNull NotificationEntry entry, @CancellationReason int reason)81 default void onEntryRemoved(@NonNull NotificationEntry entry, @CancellationReason int reason) { 82 } 83 84 /** 85 * Called whenever a {@link NotificationEntry} is considered deleted. This should be used for 86 * cleaning up any state tied to the notification. 87 * 88 * This is the deletion parallel of {@link #onEntryInit} and similarly means that you cannot 89 * expect other {@link NotifCollectionListener} implementations to still have valid state for 90 * the entry during this call. Instead, use {@link #onEntryRemoved} which will be called before 91 * deletion. 92 */ onEntryCleanUp(@onNull NotificationEntry entry)93 default void onEntryCleanUp(@NonNull NotificationEntry entry) { 94 } 95 96 /** 97 * Called whenever a ranking update is applied. During a ranking update, all active, 98 * non-lifetime-extended notification entries will have their ranking object updated. 99 * 100 * Ranking updates occur whenever a notification is added, updated, or removed, or when a 101 * standalone ranking is sent from the server. If a non-standalone ranking is applied, the event 102 * that accompanied the ranking is emitted first (e.g. {@link #onEntryAdded}), followed by the 103 * ranking event. 104 */ onRankingApplied()105 default void onRankingApplied() { 106 } 107 108 /** 109 * Called whenever system server sends a standalone ranking update (i.e. one that isn't 110 * associated with a notification being added or removed). 111 * 112 * In general it is unsafe to depend on this method as rankings can change for other reasons. 113 * Instead, listen for {@link #onRankingApplied()}, which is called whenever ANY ranking update 114 * is applied, regardless of source. 115 * 116 * @deprecated Use {@link #onRankingApplied()} instead. 117 */ onRankingUpdate(NotificationListenerService.RankingMap rankingMap)118 default void onRankingUpdate(NotificationListenerService.RankingMap rankingMap) { 119 } 120 121 /** 122 * Called when a notification channel is modified, in response to 123 * {@link NotificationListenerService#onNotificationChannelModified}. 124 * 125 * @param pkgName the package the notification channel belongs to. 126 * @param user the user the notification channel belongs to. 127 * @param channel the channel being modified. 128 * @param modificationType the type of modification that occurred to the channel. 129 */ onNotificationChannelModified( String pkgName, UserHandle user, NotificationChannel channel, int modificationType)130 default void onNotificationChannelModified( 131 String pkgName, 132 UserHandle user, 133 NotificationChannel channel, 134 int modificationType) { 135 } 136 } 137