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