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.systemui.log.LogBuffer
20 import com.android.systemui.log.core.LogLevel.DEBUG
21 import com.android.systemui.log.core.LogLevel.INFO
22 import com.android.systemui.log.core.LogLevel.WARNING
23 import com.android.systemui.log.dagger.NotificationInterruptLog
24 import com.android.systemui.statusbar.notification.collection.NotificationEntry
25 import com.android.systemui.statusbar.notification.interruption.VisualInterruptionDecisionProvider.FullScreenIntentDecision
26 import com.android.systemui.statusbar.notification.logKey
27 import javax.inject.Inject
28 
29 class VisualInterruptionDecisionLogger
30 @Inject
31 constructor(@NotificationInterruptLog val buffer: LogBuffer) {
logHeadsUpFeatureChangednull32     fun logHeadsUpFeatureChanged(isEnabled: Boolean) {
33         buffer.log(
34             TAG,
35             INFO,
36             { bool1 = isEnabled },
37             { "HUN feature is now ${if (bool1) "enabled" else "disabled"}" }
38         )
39     }
40 
logWillDismissAllnull41     fun logWillDismissAll() {
42         buffer.log(TAG, INFO, {}, { "dismissing all HUNs since feature was disabled" })
43     }
44 
logDecisionnull45     fun logDecision(
46         type: String,
47         entry: NotificationEntry,
48         decision: VisualInterruptionDecisionProvider.Decision
49     ) {
50         buffer.log(
51             TAG,
52             DEBUG,
53             {
54                 str1 = type
55                 bool1 = decision.shouldInterrupt
56                 str2 = decision.logReason
57                 str3 = entry.logKey
58             },
59             {
60                 val outcome = if (bool1) "allowed" else "suppressed"
61                 "$str1 $outcome: $str2 (key=$str3)"
62             }
63         )
64     }
65 
logFullScreenIntentDecisionnull66     fun logFullScreenIntentDecision(
67         entry: NotificationEntry,
68         decision: FullScreenIntentDecision,
69         warning: Boolean
70     ) {
71         buffer.log(
72             TAG,
73             if (warning) WARNING else DEBUG,
74             {
75                 bool1 = decision.shouldInterrupt
76                 bool2 = decision.wouldInterruptWithoutDnd
77                 str1 = decision.logReason
78                 str2 = entry.logKey
79             },
80             {
81                 val outcome =
82                     when {
83                         bool1 -> "allowed"
84                         bool2 -> "suppressed only by DND"
85                         else -> "suppressed"
86                     }
87                 "FSI $outcome: $str1 (key=$str2)"
88             }
89         )
90     }
91 }
92 
93 private const val TAG = "VisualInterruptionDecisionProvider"
94