• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     /** Whether the interruption is spammy and should be dropped under normal circumstances. */
63     val isSpammy: Boolean
64         get() = false
65 
66     /**
67      * Called after the suppressor is added to the [VisualInterruptionDecisionProvider] but before
68      * any other methods are called on the suppressor.
69      */
startnull70     fun start() {}
71 }
72 
73 /** A reason why visual interruptions might be suppressed regardless of the notification. */
74 abstract class VisualInterruptionCondition(
75     override val types: Set<VisualInterruptionType>,
76     override val reason: String,
77     override val uiEventId: UiEventEnum? = null,
78     override val eventLogData: EventLogData? = null
79 ) : VisualInterruptionSuppressor {
80     constructor(
81         types: Set<VisualInterruptionType>,
82         reason: String
83     ) : this(types, reason, /* uiEventId= */ null)
84 
85     /** @return true if these interruptions should be suppressed right now. */
shouldSuppressnull86     abstract fun shouldSuppress(): Boolean
87 }
88 
89 /** A reason why visual interruptions might be suppressed based on the notification. */
90 abstract class VisualInterruptionFilter(
91     override val types: Set<VisualInterruptionType>,
92     override val reason: String,
93     override val uiEventId: UiEventEnum? = null,
94     override val eventLogData: EventLogData? = null,
95     override val isSpammy: Boolean = false,
96 ) : VisualInterruptionSuppressor {
97     constructor(
98         types: Set<VisualInterruptionType>,
99         reason: String
100     ) : this(types, reason, /* uiEventId= */ null)
101 
102     /**
103      * @param entry the notification to consider suppressing
104      * @return true if these interruptions should be suppressed for this notification right now
105      */
106     abstract fun shouldSuppress(entry: NotificationEntry): Boolean
107 }
108