1 /*
2  * Copyright (C) 2020 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 
17 package com.android.systemui.statusbar.notification.collection.notifcollection;
18 
19 import com.android.systemui.statusbar.notification.collection.NotifCollection;
20 import com.android.systemui.statusbar.notification.collection.NotifCollection.CancellationReason;
21 import com.android.systemui.statusbar.notification.collection.NotificationEntry;
22 
23 /**
24  * A way for other code to temporarily extend the lifetime of a notification after it has been
25  * retracted. See {@link NotifCollection#addNotificationLifetimeExtender(NotifLifetimeExtender)}.
26  */
27 public interface NotifLifetimeExtender {
28     /** Name to associate with this extender (for the purposes of debugging) */
getName()29     String getName();
30 
31     /**
32      * Called on the extender immediately after it has been registered. The extender should hang on
33      * to this callback and execute it whenever it no longer needs to extend the lifetime of a
34      * notification.
35      */
setCallback(OnEndLifetimeExtensionCallback callback)36     void setCallback(OnEndLifetimeExtensionCallback callback);
37 
38     /**
39      * Called by the NotifCollection whenever a notification has been retracted (by the app) or
40      * dismissed (by the user). If the extender returns true, it is considered to be extending the
41      * lifetime of that notification. Lifetime-extended notifications are kept around until all
42      * active extenders expire their extension by calling onEndLifetimeExtension(). This method is
43      * called on all lifetime extenders even if earlier ones return true (in other words, multiple
44      * lifetime extenders can be extending a notification at the same time).
45      */
shouldExtendLifetime(NotificationEntry entry, @CancellationReason int reason)46     boolean shouldExtendLifetime(NotificationEntry entry, @CancellationReason int reason);
47 
48     /**
49      * Called by the NotifCollection to inform a lifetime extender that its extension of a notif
50      * is no longer valid (usually because the notif has been reposted and so no longer needs
51      * lifetime extension). The extender should clean up any references it has to the notif in
52      * question.
53      */
cancelLifetimeExtension(NotificationEntry entry)54     void cancelLifetimeExtension(NotificationEntry entry);
55 
56     /** Callback for notifying the NotifCollection that a lifetime extension has expired. */
57     interface OnEndLifetimeExtensionCallback {
onEndLifetimeExtension(NotifLifetimeExtender extender, NotificationEntry entry)58         void onEndLifetimeExtension(NotifLifetimeExtender extender, NotificationEntry entry);
59     }
60 }
61