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 ) {
logHeadsUpFeatureChangednull34     fun logHeadsUpFeatureChanged(useHeadsUp: Boolean) {
35         buffer.log(TAG, INFO, {
36             bool1 = useHeadsUp
37         }, {
38             "heads up is enabled=$bool1"
39         })
40     }
41 
logWillDismissAllnull42     fun logWillDismissAll() {
43         buffer.log(TAG, INFO, {
44         }, {
45             "dismissing any existing heads up notification on disable event"
46         })
47     }
48 
logNoBubbleNotAllowednull49     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 
logNoAlertingAppSuspendednull59     fun logNoAlertingAppSuspended(entry: NotificationEntry) {
60         buffer.log(TAG, DEBUG, {
61             str1 = entry.logKey
62         }, {
63             "No alerting: app is suspended: $str1"
64         })
65     }
66 
logNoBubbleNoMetadatanull67     fun logNoBubbleNoMetadata(entry: NotificationEntry) {
68         buffer.log(TAG, DEBUG, {
69             str1 = entry.logKey
70         }, {
71             "No bubble up: notification: $str1 doesn't have valid metadata"
72         })
73     }
74 
logNoHeadsUpFeatureDisablednull75     fun logNoHeadsUpFeatureDisabled() {
76         buffer.log(TAG, DEBUG, {
77         }, {
78             "No heads up: no huns"
79         })
80     }
81 
logNoHeadsUpPackageSnoozednull82     fun logNoHeadsUpPackageSnoozed(entry: NotificationEntry) {
83         buffer.log(TAG, DEBUG, {
84             str1 = entry.logKey
85         }, {
86             "No heads up: snoozed package: $str1"
87         })
88     }
89 
logHeadsUpPackageSnoozeBypassedHasFsinull90     fun logHeadsUpPackageSnoozeBypassedHasFsi(entry: NotificationEntry) {
91         buffer.log(TAG, DEBUG, {
92             str1 = entry.logKey
93         }, {
94             "Heads up: package snooze bypassed because notification has full-screen intent: $str1"
95         })
96     }
97 
logNoHeadsUpAlreadyBubblednull98     fun logNoHeadsUpAlreadyBubbled(entry: NotificationEntry) {
99         buffer.log(TAG, DEBUG, {
100             str1 = entry.logKey
101         }, {
102             "No heads up: in unlocked shade where notification is shown as a bubble: $str1"
103         })
104     }
105 
logNoHeadsUpSuppressedByDndnull106     fun logNoHeadsUpSuppressedByDnd(entry: NotificationEntry) {
107         buffer.log(TAG, DEBUG, {
108             str1 = entry.logKey
109         }, {
110             "No heads up: suppressed by DND: $str1"
111         })
112     }
113 
logNoHeadsUpNotImportantnull114     fun logNoHeadsUpNotImportant(entry: NotificationEntry) {
115         buffer.log(TAG, DEBUG, {
116             str1 = entry.logKey
117         }, {
118             "No heads up: unimportant notification: $str1"
119         })
120     }
121 
logNoHeadsUpNotInUsenull122     fun logNoHeadsUpNotInUse(entry: NotificationEntry) {
123         buffer.log(TAG, DEBUG, {
124             str1 = entry.logKey
125         }, {
126             "No heads up: not in use: $str1"
127         })
128     }
129 
logNoHeadsUpOldWhennull130     fun logNoHeadsUpOldWhen(
131         entry: NotificationEntry,
132         notifWhen: Long,
133         notifAge: Long
134     ) {
135         buffer.log(TAG, DEBUG, {
136             str1 = entry.logKey
137             long1 = notifWhen
138             long2 = notifAge
139         }, {
140             "No heads up: old when $long1 (age=$long2 ms): $str1"
141         })
142     }
143 
logMaybeHeadsUpDespiteOldWhennull144     fun logMaybeHeadsUpDespiteOldWhen(
145         entry: NotificationEntry,
146         notifWhen: Long,
147         notifAge: Long,
148         reason: String
149     ) {
150         buffer.log(TAG, DEBUG, {
151             str1 = entry.logKey
152             str2 = reason
153             long1 = notifWhen
154             long2 = notifAge
155         }, {
156             "Maybe heads up: old when $long1 (age=$long2 ms) but $str2: $str1"
157         })
158     }
159 
logNoHeadsUpSuppressedBynull160     fun logNoHeadsUpSuppressedBy(
161         entry: NotificationEntry,
162         suppressor: NotificationInterruptSuppressor
163     ) {
164         buffer.log(TAG, DEBUG, {
165             str1 = entry.logKey
166             str2 = suppressor.name
167         }, {
168             "No heads up: aborted by suppressor: $str2 sbnKey=$str1"
169         })
170     }
171 
logHeadsUpnull172     fun logHeadsUp(entry: NotificationEntry) {
173         buffer.log(TAG, DEBUG, {
174             str1 = entry.logKey
175         }, {
176             "Heads up: $str1"
177         })
178     }
179 
logNoAlertingFilteredOutnull180     fun logNoAlertingFilteredOut(entry: NotificationEntry) {
181         buffer.log(TAG, DEBUG, {
182             str1 = entry.logKey
183         }, {
184             "No alerting: filtered notification: $str1"
185         })
186     }
187 
logNoAlertingGroupAlertBehaviornull188     fun logNoAlertingGroupAlertBehavior(entry: NotificationEntry) {
189         buffer.log(TAG, DEBUG, {
190             str1 = entry.logKey
191         }, {
192             "No alerting: suppressed due to group alert behavior: $str1"
193         })
194     }
195 
logNoAlertingSuppressedBynull196     fun logNoAlertingSuppressedBy(
197         entry: NotificationEntry,
198         suppressor: NotificationInterruptSuppressor,
199         awake: Boolean
200     ) {
201         buffer.log(TAG, DEBUG, {
202             str1 = entry.logKey
203             str2 = suppressor.name
204             bool1 = awake
205         }, {
206             "No alerting: aborted by suppressor: $str2 awake=$bool1 sbnKey=$str1"
207         })
208     }
209 
logNoAlertingRecentFullscreennull210     fun logNoAlertingRecentFullscreen(entry: NotificationEntry) {
211         buffer.log(TAG, DEBUG, {
212             str1 = entry.logKey
213         }, {
214             "No alerting: recent fullscreen: $str1"
215         })
216     }
217 
logNoPulsingSettingDisablednull218     fun logNoPulsingSettingDisabled(entry: NotificationEntry) {
219         buffer.log(TAG, DEBUG, {
220             str1 = entry.logKey
221         }, {
222             "No pulsing: disabled by setting: $str1"
223         })
224     }
225 
logNoPulsingBatteryDisablednull226     fun logNoPulsingBatteryDisabled(entry: NotificationEntry) {
227         buffer.log(TAG, DEBUG, {
228             str1 = entry.logKey
229         }, {
230             "No pulsing: disabled by battery saver: $str1"
231         })
232     }
233 
logNoPulsingNoAlertnull234     fun logNoPulsingNoAlert(entry: NotificationEntry) {
235         buffer.log(TAG, DEBUG, {
236             str1 = entry.logKey
237         }, {
238             "No pulsing: notification shouldn't alert: $str1"
239         })
240     }
241 
logNoPulsingNoAmbientEffectnull242     fun logNoPulsingNoAmbientEffect(entry: NotificationEntry) {
243         buffer.log(TAG, DEBUG, {
244             str1 = entry.logKey
245         }, {
246             "No pulsing: ambient effect suppressed: $str1"
247         })
248     }
249 
logNoPulsingNotificationHiddenOverridenull250     fun logNoPulsingNotificationHiddenOverride(entry: NotificationEntry) {
251         buffer.log(TAG, DEBUG, {
252             str1 = entry.logKey
253         }, {
254             "No pulsing: notification hidden on lock screen by override: $str1"
255         })
256     }
257 
logNoPulsingNotImportantnull258     fun logNoPulsingNotImportant(entry: NotificationEntry) {
259         buffer.log(TAG, DEBUG, {
260             str1 = entry.logKey
261         }, {
262             "No pulsing: not important enough: $str1"
263         })
264     }
265 
logPulsingnull266     fun logPulsing(entry: NotificationEntry) {
267         buffer.log(TAG, DEBUG, {
268             str1 = entry.logKey
269         }, {
270             "Pulsing: $str1"
271         })
272     }
273 
logNoFullscreennull274     fun logNoFullscreen(entry: NotificationEntry, reason: String) {
275         buffer.log(TAG, DEBUG, {
276             str1 = entry.logKey
277             str2 = reason
278         }, {
279             "No FullScreenIntent: $str2: $str1"
280         })
281     }
282 
logNoFullscreenWarningnull283     fun logNoFullscreenWarning(entry: NotificationEntry, reason: String) {
284         buffer.log(TAG, WARNING, {
285             str1 = entry.logKey
286             str2 = reason
287         }, {
288             "No FullScreenIntent: WARNING: $str2: $str1"
289         })
290     }
291 
logFullscreennull292     fun logFullscreen(entry: NotificationEntry, reason: String) {
293         buffer.log(TAG, DEBUG, {
294             str1 = entry.logKey
295             str2 = reason
296         }, {
297             "FullScreenIntent: $str2: $str1"
298         })
299     }
300 
logNoAlertingNotificationHiddennull301     fun logNoAlertingNotificationHidden(entry: NotificationEntry) {
302         buffer.log(TAG, DEBUG, {
303             str1 = entry.logKey
304         }, {
305             "No alerting: notification hidden on lock screen: $str1"
306         })
307     }
308 }
309 
310 private const val TAG = "InterruptionStateProvider"
311