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