• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.systemui.statusbar;
2 
3 import androidx.annotation.NonNull;
4 
5 import com.android.systemui.statusbar.notification.collection.NotificationEntry;
6 
7 /**
8  * Interface for anything that may need to keep notifications managed even after
9  * {@link NotificationListener} removes it.  The lifetime extender is in charge of performing the
10  * callback when the notification is then safe to remove.
11  */
12 public interface NotificationLifetimeExtender {
13 
14     /**
15      * Set the handler to callback to when the notification is safe to remove.
16      *
17      * @param callback the handler to callback
18      */
setCallback(@onNull NotificationSafeToRemoveCallback callback)19     void setCallback(@NonNull NotificationSafeToRemoveCallback callback);
20 
21     /**
22      * Determines whether or not the extender needs the notification kept after removal.
23      *
24      * @param entry the entry containing the notification to check
25      * @return true if the notification lifetime should be extended
26      */
shouldExtendLifetime(@onNull NotificationEntry entry)27     boolean shouldExtendLifetime(@NonNull NotificationEntry entry);
28 
29     /**
30      * It's possible that a notification was canceled before it ever became visible. This callback
31      * gives lifetime extenders a chance to make sure it shows up. For example if a foreground
32      * service is canceled too quickly but we still want to make sure a FGS notification shows.
33      * @param pendingEntry the canceled (but pending) entry
34      * @return true if the notification lifetime should be extended
35      */
shouldExtendLifetimeForPendingNotification( @onNull NotificationEntry pendingEntry)36     default boolean shouldExtendLifetimeForPendingNotification(
37             @NonNull NotificationEntry pendingEntry) {
38         return false;
39     }
40 
41     /**
42      * Sets whether or not the lifetime should be managed by the extender.  In practice, if
43      * shouldManage is true, this is where the extender starts managing the entry internally and is
44      * now responsible for calling {@link NotificationSafeToRemoveCallback#onSafeToRemove(String)}
45      * when the entry is safe to remove.  If shouldManage is false, the extender no longer needs to
46      * worry about it (either because we will be removing it anyway or the entry is no longer
47      * removed due to an update).
48      *
49      * @param entry the entry that needs an extended lifetime
50      * @param shouldManage true if the extender should manage the entry now, false otherwise
51      */
setShouldManageLifetime(@onNull NotificationEntry entry, boolean shouldManage)52     void setShouldManageLifetime(@NonNull NotificationEntry entry, boolean shouldManage);
53 
54     /**
55      * The callback for when the notification is now safe to remove (i.e. its lifetime has ended).
56      */
57     interface NotificationSafeToRemoveCallback {
58         /**
59          * Called when the lifetime extender determines it's safe to remove.
60          *
61          * @param key key of the entry that is now safe to remove
62          */
onSafeToRemove(String key)63         void onSafeToRemove(String key);
64     }
65 }
66