2 * Copyright (C) 2019 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.systemui.statusbar;
19 import android.annotation.NonNull;
21 import com.android.systemui.statusbar.NotificationData;
24 * Interface for anything that may need to keep notifications managed even after
25 * {@link NotificationListener} removes it. The lifetime extender is in charge of performing the
26 * callback when the notification is then safe to remove.
28 public interface NotificationLifetimeExtender {
31 * Set the handler to callback to when the notification is safe to remove.
33 * @param callback the handler to callback
35 void setCallback(@NonNull NotificationSafeToRemoveCallback callback);
38 * Determines whether or not the extender needs the notification kept after removal.
40 * @param entry the entry containing the notification to check
41 * @return true if the notification lifetime should be extended
43 boolean shouldExtendLifetime(@NonNull NotificationData.Entry entry);
46 * It's possible that a notification was canceled before it ever became visible. This callback
47 * gives lifetime extenders a chance to make sure it shows up. For example if a foreground
48 * service is canceled too quickly but we still want to make sure a FGS notification shows.
49 * @param pendingEntry the canceled (but pending) entry
50 * @return true if the notification lifetime should be extended
52 default boolean shouldExtendLifetimeForPendingNotification(
53 @NonNull NotificationData.Entry pendingEntry) {
58 * Sets whether or not the lifetime should be managed by the extender. In practice, if
59 * shouldManage is true, this is where the extender starts managing the entry internally and is
60 * now responsible for calling {@link NotificationSafeToRemoveCallback#onSafeToRemove(String)}
61 * when the entry is safe to remove. If shouldManage is false, the extender no longer needs to
62 * worry about it (either because we will be removing it anyway or the entry is no longer
63 * removed due to an update).
65 * @param entry the entry that needs an extended lifetime
66 * @param shouldManage true if the extender should manage the entry now, false otherwise
68 void setShouldManageLifetime(@NonNull NotificationData.Entry entry, boolean shouldManage);
71 * The callback for when the notification is now safe to remove (i.e. its lifetime has ended).
73 interface NotificationSafeToRemoveCallback {
75 * Called when the lifetime extender determines it's safe to remove.
77 * @param key key of the entry that is now safe to remove
79 void onSafeToRemove(String key);