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