blob: 48e2923c97d991ceff2ec9424d2d092520dd32d4 [file] [log] [blame]
Kevina5ff1fa2018-08-21 16:35:48 -07001package com.android.systemui.statusbar;
2
Kevina5ff1fa2018-08-21 16:35:48 -07003import androidx.annotation.NonNull;
4
Ned Burnsf81c4c42019-01-07 14:10:43 -05005import com.android.systemui.statusbar.notification.collection.NotificationEntry;
Gus Prevasab336792018-11-14 13:52:20 -05006
Kevina5ff1fa2018-08-21 16:35:48 -07007/**
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 */
12public 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 */
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 */
Ned Burnsf81c4c42019-01-07 14:10:43 -050027 boolean shouldExtendLifetime(@NonNull NotificationEntry entry);
Kevina5ff1fa2018-08-21 16:35:48 -070028
29 /**
Evan Laird3ceaa9b2019-08-05 17:11:54 -040030 * 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 */
36 default boolean shouldExtendLifetimeForPendingNotification(
37 @NonNull NotificationEntry pendingEntry) {
38 return false;
39 }
40
41 /**
Kevine9e938c2018-09-06 13:38:11 -070042 * 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
Kevina5ff1fa2018-08-21 16:35:48 -070046 * worry about it (either because we will be removing it anyway or the entry is no longer
47 * removed due to an update).
48 *
Kevine9e938c2018-09-06 13:38:11 -070049 * @param entry the entry that needs an extended lifetime
50 * @param shouldManage true if the extender should manage the entry now, false otherwise
Kevina5ff1fa2018-08-21 16:35:48 -070051 */
Ned Burnsf81c4c42019-01-07 14:10:43 -050052 void setShouldManageLifetime(@NonNull NotificationEntry entry, boolean shouldManage);
Kevina5ff1fa2018-08-21 16:35:48 -070053
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 */
63 void onSafeToRemove(String key);
64 }
65}