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.NotificationEntry;
21 
22 /**
23  * A way for coordinators to temporarily intercept a user-dismissed notification before a message
24  * is sent to system server to officially remove this notification.
25  * See {@link NotifCollection#addNotificationDismissInterceptor(NotifDismissInterceptor)}.
26  */
27 public interface NotifDismissInterceptor {
28     /** Name to associate with this interceptor (for the purposes of debugging) */
getName()29     String getName();
30 
31     /**
32      * Called on the interceptor immediately after it has been registered. The interceptor should
33      * hang on to this callback and execute it whenever it no longer needs to intercept the
34      * dismissal of the notification.
35      */
setCallback(OnEndDismissInterception callback)36     void setCallback(OnEndDismissInterception callback);
37 
38     /**
39      * Called by the NotifCollection whenever a notification has been dismissed (by the user).
40      * If the interceptor returns true, it is considered to be intercepting the notification.
41      * Intercepted notifications will not be sent to system server for removal until it is no
42      * longer being intercepted. However, the notification can still be cancelled by the app.
43      * This method is called on all interceptors even if earlier ones return true.
44      */
shouldInterceptDismissal(NotificationEntry entry)45     boolean shouldInterceptDismissal(NotificationEntry entry);
46 
47 
48     /**
49      * Called by the NotifCollection to inform a DismissInterceptor that its interception of a notif
50      * is no longer valid (usually because the notif has been removed by means other than the
51      * user dismissing the notification from the shade, or the notification has been updated). The
52      * interceptor should clean up any references it has to the notif in question.
53      */
cancelDismissInterception(NotificationEntry entry)54     void cancelDismissInterception(NotificationEntry entry);
55 
56     /**
57      * Callback for notifying the NotifCollection that it no longer is intercepting the dismissal.
58      * If the end of this dismiss interception triggers a dismiss (ie: no other
59      * NotifDismissInterceptors are intercepting the entry), NotifCollection will use stats
60      * in the message sent to system server for the notification's dismissal.
61      */
62     interface OnEndDismissInterception {
onEndDismissInterception( NotifDismissInterceptor interceptor, NotificationEntry entry, DismissedByUserStats stats)63         void onEndDismissInterception(
64                 NotifDismissInterceptor interceptor,
65                 NotificationEntry entry,
66                 DismissedByUserStats stats);
67     }
68 }
69