1 /* 2 * Copyright (C) 2020 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.doze 18 19 import android.view.Display 20 import com.android.systemui.doze.DozeLog.Reason 21 import com.android.systemui.doze.DozeLog.reasonToString 22 import com.android.systemui.plugins.log.LogBuffer 23 import com.android.systemui.plugins.log.LogLevel.DEBUG 24 import com.android.systemui.plugins.log.LogLevel.ERROR 25 import com.android.systemui.plugins.log.LogLevel.INFO 26 import com.android.systemui.log.dagger.DozeLog 27 import com.android.systemui.statusbar.policy.DevicePostureController 28 import com.google.errorprone.annotations.CompileTimeConstant 29 import java.text.SimpleDateFormat 30 import java.util.Date 31 import java.util.Locale 32 import javax.inject.Inject 33 34 /** Interface for logging messages to the [DozeLog]. */ 35 class DozeLogger @Inject constructor( 36 @DozeLog private val buffer: LogBuffer 37 ) { logPickupWakeupnull38 fun logPickupWakeup(isWithinVibrationThreshold: Boolean) { 39 buffer.log(TAG, DEBUG, { 40 bool1 = isWithinVibrationThreshold 41 }, { 42 "PickupWakeup withinVibrationThreshold=$bool1" 43 }) 44 } 45 logPulseStartnull46 fun logPulseStart(@Reason reason: Int) { 47 buffer.log(TAG, INFO, { 48 int1 = reason 49 }, { 50 "Pulse start, reason=${reasonToString(int1)}" 51 }) 52 } 53 logPulseFinishnull54 fun logPulseFinish() { 55 buffer.log(TAG, INFO, {}, { "Pulse finish" }) 56 } 57 logNotificationPulsenull58 fun logNotificationPulse() { 59 buffer.log(TAG, INFO, {}, { "Notification pulse" }) 60 } 61 logDozingnull62 fun logDozing(isDozing: Boolean) { 63 buffer.log(TAG, INFO, { 64 bool1 = isDozing 65 }, { 66 "Dozing=$bool1" 67 }) 68 } 69 logDozingChangednull70 fun logDozingChanged(isDozing: Boolean) { 71 buffer.log(TAG, INFO, { 72 bool1 = isDozing 73 }, { 74 "Dozing changed dozing=$bool1" 75 }) 76 } 77 logPowerSaveChangednull78 fun logPowerSaveChanged(powerSaveActive: Boolean, nextState: DozeMachine.State) { 79 buffer.log(TAG, INFO, { 80 bool1 = powerSaveActive 81 str1 = nextState.name 82 }, { 83 "Power save active=$bool1 nextState=$str1" 84 }) 85 } 86 logAlwaysOnSuppressedChangenull87 fun logAlwaysOnSuppressedChange(isAodSuppressed: Boolean, nextState: DozeMachine.State) { 88 buffer.log(TAG, INFO, { 89 bool1 = isAodSuppressed 90 str1 = nextState.name 91 }, { 92 "Always on (AOD) suppressed changed, suppressed=$bool1 nextState=$str1" 93 }) 94 } 95 logFlingnull96 fun logFling( 97 expand: Boolean, 98 aboveThreshold: Boolean, 99 screenOnFromTouch: Boolean 100 ) { 101 buffer.log(TAG, DEBUG, { 102 bool1 = expand 103 bool2 = aboveThreshold 104 bool4 = screenOnFromTouch 105 }, { 106 "Fling expand=$bool1 aboveThreshold=$bool2 thresholdNeeded=$bool3 " + 107 "screenOnFromTouch=$bool4" 108 }) 109 } 110 logEmergencyCallnull111 fun logEmergencyCall() { 112 buffer.log(TAG, INFO, {}, { "Emergency call" }) 113 } 114 logKeyguardBouncerChangednull115 fun logKeyguardBouncerChanged(isShowing: Boolean) { 116 buffer.log(TAG, INFO, { 117 bool1 = isShowing 118 }, { 119 "Keyguard bouncer changed, showing=$bool1" 120 }) 121 } 122 logScreenOnnull123 fun logScreenOn(isPulsing: Boolean) { 124 buffer.log(TAG, INFO, { 125 bool1 = isPulsing 126 }, { 127 "Screen on, pulsing=$bool1" 128 }) 129 } 130 logScreenOffnull131 fun logScreenOff(why: Int) { 132 buffer.log(TAG, INFO, { 133 int1 = why 134 }, { 135 "Screen off, why=$int1" 136 }) 137 } 138 logMissedTicknull139 fun logMissedTick(delay: String) { 140 buffer.log(TAG, ERROR, { 141 str1 = delay 142 }, { 143 "Missed AOD time tick by $str1" 144 }) 145 } 146 logTimeTickSchedulednull147 fun logTimeTickScheduled(whenAt: Long, triggerAt: Long) { 148 buffer.log(TAG, DEBUG, { 149 long1 = whenAt 150 long2 = triggerAt 151 }, { 152 "Time tick scheduledAt=${DATE_FORMAT.format(Date(long1))} " + 153 "triggerAt=${DATE_FORMAT.format(Date(long2))}" 154 }) 155 } 156 logKeyguardVisibilityChangenull157 fun logKeyguardVisibilityChange(isVisible: Boolean) { 158 buffer.log(TAG, INFO, { 159 bool1 = isVisible 160 }, { 161 "Keyguard visibility change, isVisible=$bool1" 162 }) 163 } 164 logDozeStateChangednull165 fun logDozeStateChanged(state: DozeMachine.State) { 166 buffer.log(TAG, INFO, { 167 str1 = state.name 168 }, { 169 "Doze state changed to $str1" 170 }) 171 } 172 logStateChangedSentnull173 fun logStateChangedSent(state: DozeMachine.State) { 174 buffer.log(TAG, INFO, { 175 str1 = state.name 176 }, { 177 "Doze state sent to all DozeMachineParts stateSent=$str1" 178 }) 179 } 180 logDisplayStateDelayedByUdfpsnull181 fun logDisplayStateDelayedByUdfps(delayedDisplayState: Int) { 182 buffer.log(TAG, INFO, { 183 str1 = Display.stateToString(delayedDisplayState) 184 }, { 185 "Delaying display state change to: $str1 due to UDFPS activity" 186 }) 187 } 188 logDisplayStateChangednull189 fun logDisplayStateChanged(displayState: Int) { 190 buffer.log(TAG, INFO, { 191 str1 = Display.stateToString(displayState) 192 }, { 193 "Display state changed to $str1" 194 }) 195 } 196 logWakeDisplaynull197 fun logWakeDisplay(isAwake: Boolean, @Reason reason: Int) { 198 buffer.log(TAG, DEBUG, { 199 bool1 = isAwake 200 int1 = reason 201 }, { 202 "Display wakefulness changed, isAwake=$bool1, reason=${reasonToString(int1)}" 203 }) 204 } 205 logProximityResultnull206 fun logProximityResult(isNear: Boolean, millis: Long, @Reason reason: Int) { 207 buffer.log(TAG, DEBUG, { 208 bool1 = isNear 209 long1 = millis 210 int1 = reason 211 }, { 212 "Proximity result reason=${reasonToString(int1)} near=$bool1 millis=$long1" 213 }) 214 } 215 logPostureChangednull216 fun logPostureChanged(posture: Int, partUpdated: String) { 217 buffer.log(TAG, INFO, { 218 int1 = posture 219 str1 = partUpdated 220 }, { 221 "Posture changed, posture=${DevicePostureController.devicePostureToString(int1)}" + 222 " partUpdated=$str1" 223 }) 224 } 225 226 /** 227 * Log why a pulse was dropped and the current doze machine state. The state can be null 228 * if the DozeMachine is the middle of transitioning between states. 229 */ logPulseDroppednull230 fun logPulseDropped(from: String, state: DozeMachine.State?) { 231 buffer.log(TAG, INFO, { 232 str1 = from 233 str2 = state?.name 234 }, { 235 "Pulse dropped, cannot pulse from=$str1 state=$str2" 236 }) 237 } 238 logSensorEventDroppednull239 fun logSensorEventDropped(sensorEvent: Int, reason: String) { 240 buffer.log(TAG, INFO, { 241 int1 = sensorEvent 242 str1 = reason 243 }, { 244 "SensorEvent [$int1] dropped, reason=$str1" 245 }) 246 } 247 logPulseEventnull248 fun logPulseEvent(pulseEvent: String, dozing: Boolean, pulseReason: String) { 249 buffer.log(TAG, DEBUG, { 250 str1 = pulseEvent 251 bool1 = dozing 252 str2 = pulseReason 253 }, { 254 "Pulse-$str1 dozing=$bool1 pulseReason=$str2" 255 }) 256 } 257 logPulseDroppednull258 fun logPulseDropped(reason: String) { 259 buffer.log(TAG, INFO, { 260 str1 = reason 261 }, { 262 "Pulse dropped, why=$str1" 263 }) 264 } 265 logPulseTouchDisabledByProxnull266 fun logPulseTouchDisabledByProx(disabled: Boolean) { 267 buffer.log(TAG, DEBUG, { 268 bool1 = disabled 269 }, { 270 "Pulse touch modified by prox, disabled=$bool1" 271 }) 272 } 273 logSensorTriggerednull274 fun logSensorTriggered(@Reason reason: Int) { 275 buffer.log(TAG, DEBUG, { 276 int1 = reason 277 }, { 278 "Sensor triggered, type=${reasonToString(int1)}" 279 }) 280 } 281 logAlwaysOnSuppressednull282 fun logAlwaysOnSuppressed(state: DozeMachine.State, reason: String) { 283 buffer.log(TAG, INFO, { 284 str1 = state.name 285 str2 = reason 286 }, { 287 "Always-on state suppressed, suppressed state=$str1 reason=$str2" 288 }) 289 } 290 logImmediatelyEndDozenull291 fun logImmediatelyEndDoze(reason: String) { 292 buffer.log(TAG, INFO, { 293 str1 = reason 294 }, { 295 "Doze immediately ended due to $str1" 296 }) 297 } 298 logDozeScreenBrightnessnull299 fun logDozeScreenBrightness(brightness: Int) { 300 buffer.log(TAG, INFO, { 301 int1 = brightness 302 }, { 303 "Doze screen brightness set, brightness=$int1" 304 }) 305 } 306 logSetAodDimmingScrimnull307 fun logSetAodDimmingScrim(scrimOpacity: Long) { 308 buffer.log(TAG, INFO, { 309 long1 = scrimOpacity 310 }, { 311 "Doze aod dimming scrim opacity set, opacity=$long1" 312 }) 313 } 314 logCarModeEndednull315 fun logCarModeEnded() { 316 buffer.log(TAG, INFO, {}, { 317 "Doze car mode ended" 318 }) 319 } 320 logCarModeStartednull321 fun logCarModeStarted() { 322 buffer.log(TAG, INFO, {}, { 323 "Doze car mode started" 324 }) 325 } 326 logSensorRegisterAttemptnull327 fun logSensorRegisterAttempt(sensorInfo: String, successfulRegistration: Boolean) { 328 buffer.log(TAG, INFO, { 329 str1 = sensorInfo 330 bool1 = successfulRegistration 331 }, { 332 "Register sensor. Success=$bool1 sensor=$str1" 333 }) 334 } 335 logSensorUnregisterAttemptnull336 fun logSensorUnregisterAttempt(sensorInfo: String, successfulUnregister: Boolean) { 337 buffer.log(TAG, INFO, { 338 str1 = sensorInfo 339 bool1 = successfulUnregister 340 }, { 341 "Unregister sensor. Success=$bool1 sensor=$str1" 342 }) 343 } 344 logSensorUnregisterAttemptnull345 fun logSensorUnregisterAttempt( 346 sensorInfo: String, 347 successfulUnregister: Boolean, 348 reason: String 349 ) { 350 buffer.log(TAG, INFO, { 351 str1 = sensorInfo 352 bool1 = successfulUnregister 353 str2 = reason 354 }, { 355 "Unregister sensor. reason=$str2. Success=$bool1 sensor=$str1" 356 }) 357 } 358 logSkipSensorRegistrationnull359 fun logSkipSensorRegistration(sensor: String) { 360 buffer.log(TAG, DEBUG, { 361 str1 = sensor 362 }, { 363 "Skipping sensor registration because its already registered. sensor=$str1" 364 }) 365 } 366 logSetIgnoreTouchWhilePulsingnull367 fun logSetIgnoreTouchWhilePulsing(ignoreTouchWhilePulsing: Boolean) { 368 buffer.log(TAG, DEBUG, { 369 bool1 = ignoreTouchWhilePulsing 370 }, { 371 "Prox changed while pulsing. setIgnoreTouchWhilePulsing=$bool1" 372 }) 373 } 374 lognull375 fun log(@CompileTimeConstant msg: String) { 376 buffer.log(TAG, DEBUG, msg) 377 } 378 } 379 380 private const val TAG = "DozeLog" 381 382 val DATE_FORMAT = SimpleDateFormat("MM-dd HH:mm:ss.S", Locale.US) 383