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 distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 * See the License for the specific language governing permissions and limitations under the License. 12 */ 13 14 package com.android.systemui.statusbar.notification 15 16 import com.android.systemui.log.LogBuffer 17 import com.android.systemui.log.core.LogLevel.DEBUG 18 import com.android.systemui.log.dagger.NotificationLockscreenLog 19 import com.android.systemui.statusbar.StatusBarState 20 import javax.inject.Inject 21 22 class NotificationWakeUpCoordinatorLogger 23 @Inject 24 constructor(@NotificationLockscreenLog private val buffer: LogBuffer) { 25 private var allowThrottle = true 26 private var lastSetDozeAmountLogInputWasFractional = false 27 private var lastSetDozeAmountLogState = -1 28 private var lastSetHardOverride: Float? = null 29 private var lastOnDozeAmountChangedLogWasFractional = false 30 private var lastSetVisibilityAmountLogWasFractional = false 31 private var lastSetHideAmountLogWasFractional = false 32 private var lastSetHideAmount = -1f 33 logUpdateDozeAmountnull34 fun logUpdateDozeAmount( 35 inputLinear: Float, 36 hardOverride: Float?, 37 outputLinear: Float, 38 state: Int, 39 changed: Boolean, 40 ) { 41 // Avoid logging on every frame of the animation if important values are not changing 42 val isInputFractional = inputLinear != 1f && inputLinear != 0f 43 if ( 44 (isInputFractional) && 45 lastSetDozeAmountLogInputWasFractional == isInputFractional && 46 lastSetDozeAmountLogState == state && 47 lastSetHardOverride == hardOverride && 48 allowThrottle 49 ) { 50 return 51 } 52 lastSetDozeAmountLogInputWasFractional = isInputFractional 53 lastSetDozeAmountLogState = state 54 lastSetHardOverride = hardOverride 55 56 buffer.log( 57 TAG, 58 DEBUG, 59 { 60 double1 = inputLinear.toDouble() 61 str1 = hardOverride.toString() 62 str2 = outputLinear.toString() 63 int1 = state 64 bool1 = changed 65 }, 66 { 67 "updateDozeAmount() inputLinear=$double1" + 68 " hardOverride=$str1 outputLinear=$str2" + 69 " state=${StatusBarState.toString(int1)} changed=$bool1" 70 }, 71 ) 72 } 73 logSetDozeAmountOverridenull74 fun logSetDozeAmountOverride(dozing: Boolean, source: String) { 75 buffer.log( 76 TAG, 77 DEBUG, 78 { 79 bool1 = dozing 80 str1 = source 81 }, 82 { "setDozeAmountOverride(dozing=$bool1, source=\"$str1\")" }, 83 ) 84 } 85 logMaybeClearHardDozeAmountOverrideHidingNotifsnull86 fun logMaybeClearHardDozeAmountOverrideHidingNotifs( 87 willRemove: Boolean, 88 onKeyguard: Boolean, 89 dozing: Boolean, 90 bypass: Boolean, 91 idleOnCommunal: Boolean, 92 animating: Boolean, 93 ) { 94 buffer.log( 95 TAG, 96 DEBUG, 97 { 98 str1 = 99 "willRemove=$willRemove onKeyguard=$onKeyguard dozing=$dozing" + 100 " bypass=$bypass animating=$animating idleOnCommunal=$idleOnCommunal" 101 }, 102 { "maybeClearHardDozeAmountOverrideHidingNotifs() $str1" }, 103 ) 104 } 105 logOnDozeAmountChangednull106 fun logOnDozeAmountChanged(linear: Float, eased: Float) { 107 // Avoid logging on every frame of the animation when values are fractional 108 val isFractional = linear != 1f && linear != 0f 109 if (lastOnDozeAmountChangedLogWasFractional && isFractional && allowThrottle) return 110 lastOnDozeAmountChangedLogWasFractional = isFractional 111 buffer.log( 112 TAG, 113 DEBUG, 114 { 115 double1 = linear.toDouble() 116 str2 = eased.toString() 117 }, 118 { "onDozeAmountChanged(linear=$double1, eased=$str2)" }, 119 ) 120 } 121 logSetVisibilityAmountnull122 fun logSetVisibilityAmount(linear: Float) { 123 // Avoid logging on every frame of the animation when values are fractional 124 val isFractional = linear != 1f && linear != 0f 125 if (lastSetVisibilityAmountLogWasFractional && isFractional && allowThrottle) return 126 lastSetVisibilityAmountLogWasFractional = isFractional 127 buffer.log(TAG, DEBUG, { double1 = linear.toDouble() }, { "setVisibilityAmount($double1)" }) 128 } 129 logSetHideAmountnull130 fun logSetHideAmount(linear: Float) { 131 // Avoid logging the same value repeatedly 132 if (lastSetHideAmount == linear && allowThrottle) return 133 lastSetHideAmount = linear 134 // Avoid logging on every frame of the animation when values are fractional 135 val isFractional = linear != 1f && linear != 0f 136 if (lastSetHideAmountLogWasFractional && isFractional && allowThrottle) return 137 lastSetHideAmountLogWasFractional = isFractional 138 buffer.log(TAG, DEBUG, { double1 = linear.toDouble() }, { "setHideAmount($double1)" }) 139 } 140 logOnStateChangednull141 fun logOnStateChanged(newState: Int, storedState: Int) { 142 buffer.log( 143 TAG, 144 DEBUG, 145 { 146 int1 = newState 147 int2 = storedState 148 }, 149 { 150 "onStateChanged(newState=${StatusBarState.toString(int1)})" + 151 " stored=${StatusBarState.toString(int2)}" 152 }, 153 ) 154 } 155 logOnPanelExpansionChangednull156 fun logOnPanelExpansionChanged( 157 fraction: Float, 158 wasCollapsedEnoughToHide: Boolean, 159 isCollapsedEnoughToHide: Boolean, 160 couldShowPulsingHuns: Boolean, 161 canShowPulsingHuns: Boolean, 162 ) { 163 buffer.log( 164 TAG, 165 DEBUG, 166 { 167 double1 = fraction.toDouble() 168 bool1 = wasCollapsedEnoughToHide 169 bool2 = isCollapsedEnoughToHide 170 bool3 = couldShowPulsingHuns 171 bool4 = canShowPulsingHuns 172 }, 173 { 174 "onPanelExpansionChanged($double1):" + 175 " collapsedEnoughToHide: $bool1 -> $bool2," + 176 " canShowPulsingHuns: $bool3 -> $bool4" 177 }, 178 ) 179 } 180 logSetWakingUpnull181 fun logSetWakingUp(wakingUp: Boolean) { 182 buffer.log(TAG, DEBUG, { bool1 = wakingUp }, { "setWakingUp(wakingUp=$bool1)" }) 183 } 184 } 185 186 private const val TAG = "NotificationWakeUpCoordinator" 187