1 /*
2  * Copyright (C) 2023 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.interruption
18 
19 import com.android.internal.logging.UiEventLogger.UiEventEnum
20 import com.android.systemui.statusbar.notification.collection.NotificationEntry
21 import com.android.systemui.statusbar.notification.interruption.VisualInterruptionSuppressor.EventLogData
22 
23 /**
24  * A reason why visual interruptions might be suppressed.
25  *
26  * @see VisualInterruptionCondition
27  * @see VisualInterruptionFilter
28  */
29 enum class VisualInterruptionType {
30     /* HUN when awake */
31     PEEK,
32 
33     /* HUN when dozing */
34     PULSE,
35 
36     /* Bubble */
37     BUBBLE
38 }
39 
40 /**
41  * A reason why visual interruptions might be suppressed.
42  *
43  * @see VisualInterruptionCondition
44  * @see VisualInterruptionFilter
45  */
46 sealed interface VisualInterruptionSuppressor {
47     /** Data to be logged in the EventLog when an interruption is suppressed. */
48     data class EventLogData(val number: String, val description: String)
49 
50     /** The type(s) of interruption that this suppresses. */
51     val types: Set<VisualInterruptionType>
52 
53     /** A human-readable string to be logged to explain why this suppressed an interruption. */
54     val reason: String
55 
56     /** An optional UiEvent ID to be recorded when this suppresses an interruption. */
57     val uiEventId: UiEventEnum?
58 
59     /** Optional data to be logged in the EventLog when this suppresses an interruption. */
60     val eventLogData: EventLogData?
61 
62     /**
63      * Called after the suppressor is added to the [VisualInterruptionDecisionProvider] but before
64      * any other methods are called on the suppressor.
65      */
startnull66     fun start() {}
67 }
68 
69 /** A reason why visual interruptions might be suppressed regardless of the notification. */
70 abstract class VisualInterruptionCondition(
71     override val types: Set<VisualInterruptionType>,
72     override val reason: String,
73     override val uiEventId: UiEventEnum? = null,
74     override val eventLogData: EventLogData? = null
75 ) : VisualInterruptionSuppressor {
76     constructor(
77         types: Set<VisualInterruptionType>,
78         reason: String
79     ) : this(types, reason, /* uiEventId = */ null)
80 
81     /** @return true if these interruptions should be suppressed right now. */
shouldSuppressnull82     abstract fun shouldSuppress(): Boolean
83 }
84 
85 /** A reason why visual interruptions might be suppressed based on the notification. */
86 abstract class VisualInterruptionFilter(
87     override val types: Set<VisualInterruptionType>,
88     override val reason: String,
89     override val uiEventId: UiEventEnum? = null,
90     override val eventLogData: EventLogData? = null
91 ) : VisualInterruptionSuppressor {
92     constructor(
93         types: Set<VisualInterruptionType>,
94         reason: String
95     ) : this(types, reason, /* uiEventId = */ null)
96 
97     /**
98      * @param entry the notification to consider suppressing
99      * @return true if these interruptions should be suppressed for this notification right now
100      */
101     abstract fun shouldSuppress(entry: NotificationEntry): Boolean
102 }
103