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 lastSetDozeAmountLogDelayWasFractional = false 28 private var lastSetDozeAmountLogState = -1 29 private var lastSetHardOverride: Float? = null 30 private var lastOnDozeAmountChangedLogWasFractional = false 31 private var lastSetDelayDozeAmountOverrideLogWasFractional = false 32 private var lastSetVisibilityAmountLogWasFractional = false 33 private var lastSetHideAmountLogWasFractional = false 34 private var lastSetHideAmount = -1f 35 logUpdateDozeAmountnull36 fun logUpdateDozeAmount( 37 inputLinear: Float, 38 delayLinear: Float, 39 hardOverride: Float?, 40 outputLinear: Float, 41 state: Int, 42 changed: Boolean, 43 ) { 44 // Avoid logging on every frame of the animation if important values are not changing 45 val isInputFractional = inputLinear != 1f && inputLinear != 0f 46 val isDelayFractional = delayLinear != 1f && delayLinear != 0f 47 if ( 48 (isInputFractional || isDelayFractional) && 49 lastSetDozeAmountLogInputWasFractional == isInputFractional && 50 lastSetDozeAmountLogDelayWasFractional == isDelayFractional && 51 lastSetDozeAmountLogState == state && 52 lastSetHardOverride == hardOverride && 53 allowThrottle 54 ) { 55 return 56 } 57 lastSetDozeAmountLogInputWasFractional = isInputFractional 58 lastSetDozeAmountLogDelayWasFractional = isDelayFractional 59 lastSetDozeAmountLogState = state 60 lastSetHardOverride = hardOverride 61 62 buffer.log( 63 TAG, 64 DEBUG, 65 { 66 double1 = inputLinear.toDouble() 67 str1 = hardOverride.toString() 68 str2 = outputLinear.toString() 69 str3 = delayLinear.toString() 70 int1 = state 71 bool1 = changed 72 }, 73 { 74 "updateDozeAmount() inputLinear=$double1 delayLinear=$str3" + 75 " hardOverride=$str1 outputLinear=$str2" + 76 " state=${StatusBarState.toString(int1)} changed=$bool1" 77 } 78 ) 79 } 80 logSetDozeAmountOverridenull81 fun logSetDozeAmountOverride(dozing: Boolean, source: String) { 82 buffer.log( 83 TAG, 84 DEBUG, 85 { 86 bool1 = dozing 87 str1 = source 88 }, 89 { "setDozeAmountOverride(dozing=$bool1, source=\"$str1\")" } 90 ) 91 } 92 logMaybeClearHardDozeAmountOverrideHidingNotifsnull93 fun logMaybeClearHardDozeAmountOverrideHidingNotifs( 94 willRemove: Boolean, 95 onKeyguard: Boolean, 96 dozing: Boolean, 97 bypass: Boolean, 98 idleOnCommunal: Boolean, 99 animating: Boolean, 100 ) { 101 buffer.log( 102 TAG, 103 DEBUG, 104 { 105 str1 = 106 "willRemove=$willRemove onKeyguard=$onKeyguard dozing=$dozing" + 107 " bypass=$bypass animating=$animating idleOnCommunal=$idleOnCommunal" 108 }, 109 { "maybeClearHardDozeAmountOverrideHidingNotifs() $str1" } 110 ) 111 } 112 logOnDozeAmountChangednull113 fun logOnDozeAmountChanged(linear: Float, eased: Float) { 114 // Avoid logging on every frame of the animation when values are fractional 115 val isFractional = linear != 1f && linear != 0f 116 if (lastOnDozeAmountChangedLogWasFractional && isFractional && allowThrottle) return 117 lastOnDozeAmountChangedLogWasFractional = isFractional 118 buffer.log( 119 TAG, 120 DEBUG, 121 { 122 double1 = linear.toDouble() 123 str2 = eased.toString() 124 }, 125 { "onDozeAmountChanged(linear=$double1, eased=$str2)" } 126 ) 127 } 128 logSetDelayDozeAmountOverridenull129 fun logSetDelayDozeAmountOverride(linear: Float) { 130 // Avoid logging on every frame of the animation when values are fractional 131 val isFractional = linear != 1f && linear != 0f 132 if (lastSetDelayDozeAmountOverrideLogWasFractional && isFractional && allowThrottle) return 133 lastSetDelayDozeAmountOverrideLogWasFractional = isFractional 134 buffer.log( 135 TAG, 136 DEBUG, 137 { double1 = linear.toDouble() }, 138 { "setDelayDozeAmountOverride($double1)" } 139 ) 140 } 141 logSetVisibilityAmountnull142 fun logSetVisibilityAmount(linear: Float) { 143 // Avoid logging on every frame of the animation when values are fractional 144 val isFractional = linear != 1f && linear != 0f 145 if (lastSetVisibilityAmountLogWasFractional && isFractional && allowThrottle) return 146 lastSetVisibilityAmountLogWasFractional = isFractional 147 buffer.log(TAG, DEBUG, { double1 = linear.toDouble() }, { "setVisibilityAmount($double1)" }) 148 } 149 logSetHideAmountnull150 fun logSetHideAmount(linear: Float) { 151 // Avoid logging the same value repeatedly 152 if (lastSetHideAmount == linear && allowThrottle) return 153 lastSetHideAmount = linear 154 // Avoid logging on every frame of the animation when values are fractional 155 val isFractional = linear != 1f && linear != 0f 156 if (lastSetHideAmountLogWasFractional && isFractional && allowThrottle) return 157 lastSetHideAmountLogWasFractional = isFractional 158 buffer.log(TAG, DEBUG, { double1 = linear.toDouble() }, { "setHideAmount($double1)" }) 159 } 160 logStartDelayedDozeAmountAnimationnull161 fun logStartDelayedDozeAmountAnimation(alreadyRunning: Boolean) { 162 buffer.log( 163 TAG, 164 DEBUG, 165 { bool1 = alreadyRunning }, 166 { "startDelayedDozeAmountAnimation() alreadyRunning=$bool1" } 167 ) 168 } 169 logOnStateChangednull170 fun logOnStateChanged(newState: Int, storedState: Int) { 171 buffer.log( 172 TAG, 173 DEBUG, 174 { 175 int1 = newState 176 int2 = storedState 177 }, 178 { 179 "onStateChanged(newState=${StatusBarState.toString(int1)})" + 180 " stored=${StatusBarState.toString(int2)}" 181 } 182 ) 183 } 184 logSetWakingUpnull185 fun logSetWakingUp(wakingUp: Boolean, requestDelayedAnimation: Boolean) { 186 buffer.log( 187 TAG, 188 DEBUG, 189 { 190 bool1 = wakingUp 191 bool2 = requestDelayedAnimation 192 }, 193 { "setWakingUp(wakingUp=$bool1, requestDelayedAnimation=$bool2)" } 194 ) 195 } 196 logDelayingClockWakeUpAnimationnull197 fun logDelayingClockWakeUpAnimation(delayingAnimation: Boolean) { 198 buffer.log( 199 TAG, 200 DEBUG, 201 { bool1 = delayingAnimation }, 202 { "logDelayingClockWakeUpAnimation($bool1)" } 203 ) 204 } 205 } 206 207 private const val TAG = "NotificationWakeUpCoordinator" 208