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