Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 1 | package com.android.systemui.statusbar; |
| 2 | |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 3 | import androidx.annotation.NonNull; |
| 4 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 5 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 6 | |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 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 | */ |
| 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 Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 27 | boolean shouldExtendLifetime(@NonNull NotificationEntry entry); |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 28 | |
| 29 | /** |
Evan Laird | 3ceaa9b | 2019-08-05 17:11:54 -0400 | [diff] [blame] | 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 | */ |
| 36 | default boolean shouldExtendLifetimeForPendingNotification( |
| 37 | @NonNull NotificationEntry pendingEntry) { |
| 38 | return false; |
| 39 | } |
| 40 | |
| 41 | /** |
Kevin | e9e938c | 2018-09-06 13:38:11 -0700 | [diff] [blame] | 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 |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 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 | * |
Kevin | e9e938c | 2018-09-06 13:38:11 -0700 | [diff] [blame] | 49 | * @param entry the entry that needs an extended lifetime |
| 50 | * @param shouldManage true if the extender should manage the entry now, false otherwise |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 51 | */ |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 52 | void setShouldManageLifetime(@NonNull NotificationEntry entry, boolean shouldManage); |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 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 | */ |
| 63 | void onSafeToRemove(String key); |
| 64 | } |
| 65 | } |