1 /*
2  * Copyright (C) 2022 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 android.util.Log
20 
21 import com.android.systemui.log.dagger.NotificationInterruptLog
22 import com.android.systemui.log.LogBuffer
23 import com.android.systemui.log.core.LogLevel.DEBUG
24 import com.android.systemui.log.core.LogLevel.INFO
25 import com.android.systemui.log.core.LogLevel.WARNING
26 import com.android.systemui.statusbar.notification.collection.NotificationEntry
27 import com.android.systemui.statusbar.notification.logKey
28 import com.android.systemui.util.Compile
29 import javax.inject.Inject
30 
31 class NotificationInterruptLogger @Inject constructor(
32     @NotificationInterruptLog val buffer: LogBuffer
33 ) {
34     fun logHeadsUpFeatureChanged(useHeadsUp: Boolean) {
35         buffer.log(TAG, INFO, {
36             bool1 = useHeadsUp
37         }, {
38             "heads up is enabled=$bool1"
39         })
40     }
41 
42     fun logWillDismissAll() {
43         buffer.log(TAG, INFO, {
44         }, {
45             "dismissing any existing heads up notification on disable event"
46         })
47     }
48 
49     fun logNoBubbleNotAllowed(entry: NotificationEntry) {
50         if (Compile.IS_DEBUG && Log.isLoggable(TAG, Log.DEBUG)) {
51             buffer.log(TAG, DEBUG, {
52                 str1 = entry.logKey
53             }, {
54                 "No bubble up: not allowed to bubble: $str1"
55             })
56         }
57     }
58 
59     fun logNoBubbleNoMetadata(entry: NotificationEntry) {
60         buffer.log(TAG, DEBUG, {
61             str1 = entry.logKey
62         }, {
63             "No bubble up: notification: $str1 doesn't have valid metadata"
64         })
65     }
66 
67     fun logNoHeadsUpFeatureDisabled() {
68         buffer.log(TAG, DEBUG, {
69         }, {
70             "No heads up: no huns"
71         })
72     }
73 
74     fun logNoHeadsUpPackageSnoozed(entry: NotificationEntry) {
75         buffer.log(TAG, DEBUG, {
76             str1 = entry.logKey
77         }, {
78             "No heads up: snoozed package: $str1"
79         })
80     }
81 
82     fun logHeadsUpPackageSnoozeBypassedHasFsi(entry: NotificationEntry) {
83         buffer.log(TAG, DEBUG, {
84             str1 = entry.logKey
85         }, {
86             "Heads up: package snooze bypassed because notification has full-screen intent: $str1"
87         })
88     }
89 
90     fun logNoHeadsUpAlreadyBubbled(entry: NotificationEntry) {
91         buffer.log(TAG, DEBUG, {
92             str1 = entry.logKey
93         }, {
94             "No heads up: in unlocked shade where notification is shown as a bubble: $str1"
95         })
96     }
97 
98     fun logNoHeadsUpSuppressedByDnd(entry: NotificationEntry) {
99         buffer.log(TAG, DEBUG, {
100             str1 = entry.logKey
101         }, {
102             "No heads up: suppressed by DND: $str1"
103         })
104     }
105 
106     fun logNoHeadsUpNotImportant(entry: NotificationEntry) {
107         buffer.log(TAG, DEBUG, {
108             str1 = entry.logKey
109         }, {
110             "No heads up: unimportant notification: $str1"
111         })
112     }
113 
114     fun logNoHeadsUpNotInUse(entry: NotificationEntry) {
115         buffer.log(TAG, DEBUG, {
116             str1 = entry.logKey
117         }, {
118             "No heads up: not in use: $str1"
119         })
120     }
121 
122     fun logNoHeadsUpOldWhen(
123         entry: NotificationEntry,
124         notifWhen: Long,
125         notifAge: Long
126     ) {
127         buffer.log(TAG, DEBUG, {
128             str1 = entry.logKey
129             long1 = notifWhen
130             long2 = notifAge
131         }, {
132             "No heads up: old when $long1 (age=$long2 ms): $str1"
133         })
134     }
135 
136     fun logMaybeHeadsUpDespiteOldWhen(
137         entry: NotificationEntry,
138         notifWhen: Long,
139         notifAge: Long,
140         reason: String
141     ) {
142         buffer.log(TAG, DEBUG, {
143             str1 = entry.logKey
144             str2 = reason
145             long1 = notifWhen
146             long2 = notifAge
147         }, {
148             "Maybe heads up: old when $long1 (age=$long2 ms) but $str2: $str1"
149         })
150     }
151 
152     fun logNoHeadsUpSuppressedBy(
153         entry: NotificationEntry,
154         suppressor: NotificationInterruptSuppressor
155     ) {
156         buffer.log(TAG, DEBUG, {
157             str1 = entry.logKey
158             str2 = suppressor.name
159         }, {
160             "No heads up: aborted by suppressor: $str2 sbnKey=$str1"
161         })
162     }
163 
164     fun logHeadsUp(entry: NotificationEntry) {
165         buffer.log(TAG, DEBUG, {
166             str1 = entry.logKey
167         }, {
168             "Heads up: $str1"
169         })
170     }
171 
172     fun logNoAlertingFilteredOut(entry: NotificationEntry) {
173         buffer.log(TAG, DEBUG, {
174             str1 = entry.logKey
175         }, {
176             "No alerting: filtered notification: $str1"
177         })
178     }
179 
180     fun logNoAlertingGroupAlertBehavior(entry: NotificationEntry) {
181         buffer.log(TAG, DEBUG, {
182             str1 = entry.logKey
183         }, {
184             "No alerting: suppressed due to group alert behavior: $str1"
185         })
186     }
187 
188     fun logNoAlertingSuppressedBy(
189         entry: NotificationEntry,
190         suppressor: NotificationInterruptSuppressor,
191         awake: Boolean
192     ) {
193         buffer.log(TAG, DEBUG, {
194             str1 = entry.logKey
195             str2 = suppressor.name
196             bool1 = awake
197         }, {
198             "No alerting: aborted by suppressor: $str2 awake=$bool1 sbnKey=$str1"
199         })
200     }
201 
202     fun logNoAlertingRecentFullscreen(entry: NotificationEntry) {
203         buffer.log(TAG, DEBUG, {
204             str1 = entry.logKey
205         }, {
206             "No alerting: recent fullscreen: $str1"
207         })
208     }
209 
210     fun logNoPulsingSettingDisabled(entry: NotificationEntry) {
211         buffer.log(TAG, DEBUG, {
212             str1 = entry.logKey
213         }, {
214             "No pulsing: disabled by setting: $str1"
215         })
216     }
217 
218     fun logNoPulsingBatteryDisabled(entry: NotificationEntry) {
219         buffer.log(TAG, DEBUG, {
220             str1 = entry.logKey
221         }, {
222             "No pulsing: disabled by battery saver: $str1"
223         })
224     }
225 
226     fun logNoPulsingNoAlert(entry: NotificationEntry) {
227         buffer.log(TAG, DEBUG, {
228             str1 = entry.logKey
229         }, {
230             "No pulsing: notification shouldn't alert: $str1"
231         })
232     }
233 
234     fun logNoPulsingNoAmbientEffect(entry: NotificationEntry) {
235         buffer.log(TAG, DEBUG, {
236             str1 = entry.logKey
237         }, {
238             "No pulsing: ambient effect suppressed: $str1"
239         })
240     }
241 
242     fun logNoPulsingNotificationHidden(entry: NotificationEntry) {
243         buffer.log(TAG, DEBUG, {
244             str1 = entry.logKey
245         }, {
246             "No pulsing: notification hidden on lock screen: $str1"
247         })
248     }
249 
250     fun logNoPulsingNotImportant(entry: NotificationEntry) {
251         buffer.log(TAG, DEBUG, {
252             str1 = entry.logKey
253         }, {
254             "No pulsing: not important enough: $str1"
255         })
256     }
257 
258     fun logPulsing(entry: NotificationEntry) {
259         buffer.log(TAG, DEBUG, {
260             str1 = entry.logKey
261         }, {
262             "Pulsing: $str1"
263         })
264     }
265 
266     fun logNoFullscreen(entry: NotificationEntry, reason: String) {
267         buffer.log(TAG, DEBUG, {
268             str1 = entry.logKey
269             str2 = reason
270         }, {
271             "No FullScreenIntent: $str2: $str1"
272         })
273     }
274 
275     fun logNoFullscreenWarning(entry: NotificationEntry, reason: String) {
276         buffer.log(TAG, WARNING, {
277             str1 = entry.logKey
278             str2 = reason
279         }, {
280             "No FullScreenIntent: WARNING: $str2: $str1"
281         })
282     }
283 
284     fun logFullscreen(entry: NotificationEntry, reason: String) {
285         buffer.log(TAG, DEBUG, {
286             str1 = entry.logKey
287             str2 = reason
288         }, {
289             "FullScreenIntent: $str2: $str1"
290         })
291     }
292 
293     fun keyguardHideNotification(entry: NotificationEntry) {
294         buffer.log(TAG, DEBUG, {
295             str1 = entry.logKey
296         }, {
297             "Keyguard Hide Notification: $str1"
298         })
299     }
300 }
301 
302 private const val TAG = "InterruptionStateProvider"
303