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.log.LogBuffer 23 import com.android.systemui.log.core.LogLevel.DEBUG 24 import com.android.systemui.log.core.LogLevel.ERROR 25 import com.android.systemui.log.core.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(@DozeLog private val buffer: LogBuffer) { logPickupWakeupnull36 fun logPickupWakeup(isWithinVibrationThreshold: Boolean) { 37 buffer.log( 38 TAG, 39 DEBUG, 40 { bool1 = isWithinVibrationThreshold }, 41 { "PickupWakeup withinVibrationThreshold=$bool1" } 42 ) 43 } 44 logPulseStartnull45 fun logPulseStart(@Reason reason: Int) { 46 buffer.log(TAG, INFO, { int1 = reason }, { "Pulse start, reason=${reasonToString(int1)}" }) 47 } 48 logPulseFinishnull49 fun logPulseFinish() { 50 buffer.log(TAG, INFO, {}, { "Pulse finish" }) 51 } 52 logNotificationPulsenull53 fun logNotificationPulse() { 54 buffer.log(TAG, INFO, {}, { "Notification pulse" }) 55 } 56 logDozingnull57 fun logDozing(isDozing: Boolean) { 58 buffer.log(TAG, INFO, { bool1 = isDozing }, { "Dozing=$bool1" }) 59 } 60 logDozingChangednull61 fun logDozingChanged(isDozing: Boolean) { 62 buffer.log(TAG, INFO, { bool1 = isDozing }, { "Dozing changed dozing=$bool1" }) 63 } 64 logPowerSaveChangednull65 fun logPowerSaveChanged(powerSaveActive: Boolean, nextState: DozeMachine.State) { 66 buffer.log( 67 TAG, 68 INFO, 69 { 70 bool1 = powerSaveActive 71 str1 = nextState.name 72 }, 73 { "Power save active=$bool1 nextState=$str1" } 74 ) 75 } 76 logAlwaysOnSuppressedChangenull77 fun logAlwaysOnSuppressedChange(isAodSuppressed: Boolean, nextState: DozeMachine.State) { 78 buffer.log( 79 TAG, 80 INFO, 81 { 82 bool1 = isAodSuppressed 83 str1 = nextState.name 84 }, 85 { "Always on (AOD) suppressed changed, suppressed=$bool1 nextState=$str1" } 86 ) 87 } 88 logFlingnull89 fun logFling(expand: Boolean, aboveThreshold: Boolean, screenOnFromTouch: Boolean) { 90 buffer.log( 91 TAG, 92 DEBUG, 93 { 94 bool1 = expand 95 bool2 = aboveThreshold 96 bool4 = screenOnFromTouch 97 }, 98 { 99 "Fling expand=$bool1 aboveThreshold=$bool2 thresholdNeeded=$bool3 " + 100 "screenOnFromTouch=$bool4" 101 } 102 ) 103 } 104 logEmergencyCallnull105 fun logEmergencyCall() { 106 buffer.log(TAG, INFO, {}, { "Emergency call" }) 107 } 108 logKeyguardBouncerChangednull109 fun logKeyguardBouncerChanged(isShowing: Boolean) { 110 buffer.log(TAG, INFO, { bool1 = isShowing }, { "Keyguard bouncer changed, showing=$bool1" }) 111 } 112 logScreenOnnull113 fun logScreenOn(isPulsing: Boolean) { 114 buffer.log(TAG, INFO, { bool1 = isPulsing }, { "Screen on, pulsing=$bool1" }) 115 } 116 logScreenOffnull117 fun logScreenOff(why: Int) { 118 buffer.log(TAG, INFO, { int1 = why }, { "Screen off, why=$int1" }) 119 } 120 logMissedTicknull121 fun logMissedTick(delay: String) { 122 buffer.log(TAG, ERROR, { str1 = delay }, { "Missed AOD time tick by $str1" }) 123 } 124 logTimeTickSchedulednull125 fun logTimeTickScheduled(whenAt: Long, triggerAt: Long) { 126 buffer.log( 127 TAG, 128 DEBUG, 129 { 130 long1 = whenAt 131 long2 = triggerAt 132 }, 133 { 134 "Time tick scheduledAt=${DATE_FORMAT.format(Date(long1))} " + 135 "triggerAt=${DATE_FORMAT.format(Date(long2))}" 136 } 137 ) 138 } 139 logKeyguardVisibilityChangenull140 fun logKeyguardVisibilityChange(isVisible: Boolean) { 141 buffer.log( 142 TAG, 143 INFO, 144 { bool1 = isVisible }, 145 { "Keyguard visibility change, isVisible=$bool1" } 146 ) 147 } 148 logPendingUnscheduleTimeTicknull149 fun logPendingUnscheduleTimeTick(isPending: Boolean, isTimeTickScheduled: Boolean) { 150 buffer.log( 151 TAG, 152 INFO, 153 { 154 bool1 = isPending 155 bool2 = isTimeTickScheduled 156 }, 157 { "Pending unschedule time tick, isPending=$bool1, isTimeTickScheduled:$bool2" } 158 ) 159 } 160 logDozeStateChangednull161 fun logDozeStateChanged(state: DozeMachine.State) { 162 buffer.log(TAG, INFO, { str1 = state.name }, { "Doze state changed to $str1" }) 163 } 164 logStateChangedSentnull165 fun logStateChangedSent(state: DozeMachine.State) { 166 buffer.log( 167 TAG, 168 INFO, 169 { str1 = state.name }, 170 { "Doze state sent to all DozeMachineParts stateSent=$str1" } 171 ) 172 } 173 logDisplayStateDelayedByUdfpsnull174 fun logDisplayStateDelayedByUdfps(delayedDisplayState: Int) { 175 buffer.log( 176 TAG, 177 INFO, 178 { str1 = Display.stateToString(delayedDisplayState) }, 179 { "Delaying display state change to: $str1 due to UDFPS activity" } 180 ) 181 } 182 logDisplayStateChangednull183 fun logDisplayStateChanged(displayState: Int, afterRequest: Boolean) { 184 buffer.log( 185 TAG, 186 INFO, 187 { 188 str1 = Display.stateToString(displayState) 189 bool1 = afterRequest 190 }, 191 { "Display state ${if (bool1) "changed" else "requested"} to $str1" } 192 ) 193 } 194 logWakeDisplaynull195 fun logWakeDisplay(isAwake: Boolean, @Reason reason: Int) { 196 buffer.log( 197 TAG, 198 DEBUG, 199 { 200 bool1 = isAwake 201 int1 = reason 202 }, 203 { "Display wakefulness changed, isAwake=$bool1, reason=${reasonToString(int1)}" } 204 ) 205 } 206 logProximityResultnull207 fun logProximityResult(isNear: Boolean, millis: Long, @Reason reason: Int) { 208 buffer.log( 209 TAG, 210 DEBUG, 211 { 212 bool1 = isNear 213 long1 = millis 214 int1 = reason 215 }, 216 { "Proximity result reason=${reasonToString(int1)} near=$bool1 millis=$long1" } 217 ) 218 } 219 logPostureChangednull220 fun logPostureChanged(posture: Int, partUpdated: String) { 221 buffer.log( 222 TAG, 223 INFO, 224 { 225 int1 = posture 226 str1 = partUpdated 227 }, 228 { 229 "Posture changed, posture=${DevicePostureController.devicePostureToString(int1)}" + 230 " partUpdated=$str1" 231 } 232 ) 233 } 234 235 /** 236 * Log why a pulse was dropped and the current doze machine state. The state can be null if the 237 * DozeMachine is the middle of transitioning between states. 238 */ logPulseDroppednull239 fun logPulseDropped(from: String, state: DozeMachine.State?) { 240 buffer.log( 241 TAG, 242 INFO, 243 { 244 str1 = from 245 str2 = state?.name 246 }, 247 { "Pulse dropped, cannot pulse from=$str1 state=$str2" } 248 ) 249 } 250 logSensorEventDroppednull251 fun logSensorEventDropped(sensorEvent: Int, reason: String) { 252 buffer.log( 253 TAG, 254 INFO, 255 { 256 int1 = sensorEvent 257 str1 = reason 258 }, 259 { "SensorEvent [$int1] dropped, reason=$str1" } 260 ) 261 } 262 logPulseEventnull263 fun logPulseEvent(pulseEvent: String, dozing: Boolean, pulseReason: String) { 264 buffer.log( 265 TAG, 266 DEBUG, 267 { 268 str1 = pulseEvent 269 bool1 = dozing 270 str2 = pulseReason 271 }, 272 { "Pulse-$str1 dozing=$bool1 pulseReason=$str2" } 273 ) 274 } 275 logPulseDroppednull276 fun logPulseDropped(reason: String) { 277 buffer.log(TAG, INFO, { str1 = reason }, { "Pulse dropped, why=$str1" }) 278 } 279 logPulseTouchDisabledByProxnull280 fun logPulseTouchDisabledByProx(disabled: Boolean) { 281 buffer.log( 282 TAG, 283 DEBUG, 284 { bool1 = disabled }, 285 { "Pulse touch modified by prox, disabled=$bool1" } 286 ) 287 } 288 logSensorTriggerednull289 fun logSensorTriggered(@Reason reason: Int) { 290 buffer.log( 291 TAG, 292 DEBUG, 293 { int1 = reason }, 294 { "Sensor triggered, type=${reasonToString(int1)}" } 295 ) 296 } 297 logAlwaysOnSuppressednull298 fun logAlwaysOnSuppressed(state: DozeMachine.State, reason: String) { 299 buffer.log( 300 TAG, 301 INFO, 302 { 303 str1 = state.name 304 str2 = reason 305 }, 306 { "Always-on state suppressed, suppressed state=$str1 reason=$str2" } 307 ) 308 } 309 logImmediatelyEndDozenull310 fun logImmediatelyEndDoze(reason: String) { 311 buffer.log(TAG, INFO, { str1 = reason }, { "Doze immediately ended due to $str1" }) 312 } 313 logDozeScreenBrightnessnull314 fun logDozeScreenBrightness(brightness: Int, afterRequest: Boolean) { 315 buffer.log( 316 TAG, 317 INFO, 318 { 319 int1 = brightness 320 bool1 = afterRequest 321 }, 322 { 323 "Doze screen brightness ${if (bool1) "set" else "requested"}" + 324 " (int), brightness=$int1" 325 } 326 ) 327 } 328 logDozeScreenBrightnessFloatnull329 fun logDozeScreenBrightnessFloat(brightness: Float, afterRequest: Boolean) { 330 buffer.log( 331 TAG, 332 INFO, 333 { 334 double1 = brightness.toDouble() 335 bool1 = afterRequest 336 }, 337 { 338 "Doze screen brightness ${if (bool1) "set" else "requested"}" + 339 " (float), brightness=$double1" 340 } 341 ) 342 } 343 logSetAodDimmingScrimnull344 fun logSetAodDimmingScrim(scrimOpacity: Long) { 345 buffer.log( 346 TAG, 347 INFO, 348 { long1 = scrimOpacity }, 349 { "Doze aod dimming scrim opacity set, opacity=$long1" } 350 ) 351 } 352 logCarModeEndednull353 fun logCarModeEnded() { 354 buffer.log(TAG, INFO, {}, { "Doze car mode ended" }) 355 } 356 logCarModeStartednull357 fun logCarModeStarted() { 358 buffer.log(TAG, INFO, {}, { "Doze car mode started" }) 359 } 360 logSensorRegisterAttemptnull361 fun logSensorRegisterAttempt(sensorInfo: String, successfulRegistration: Boolean) { 362 buffer.log( 363 TAG, 364 INFO, 365 { 366 str1 = sensorInfo 367 bool1 = successfulRegistration 368 }, 369 { "Register sensor. Success=$bool1 sensor=$str1" } 370 ) 371 } 372 logSensorUnregisterAttemptnull373 fun logSensorUnregisterAttempt(sensorInfo: String, successfulUnregister: Boolean) { 374 buffer.log( 375 TAG, 376 INFO, 377 { 378 str1 = sensorInfo 379 bool1 = successfulUnregister 380 }, 381 { "Unregister sensor. Success=$bool1 sensor=$str1" } 382 ) 383 } 384 logSensorUnregisterAttemptnull385 fun logSensorUnregisterAttempt( 386 sensorInfo: String, 387 successfulUnregister: Boolean, 388 reason: String 389 ) { 390 buffer.log( 391 TAG, 392 INFO, 393 { 394 str1 = sensorInfo 395 bool1 = successfulUnregister 396 str2 = reason 397 }, 398 { "Unregister sensor. reason=$str2. Success=$bool1 sensor=$str1" } 399 ) 400 } 401 logSkipSensorRegistrationnull402 fun logSkipSensorRegistration(sensor: String) { 403 buffer.log( 404 TAG, 405 DEBUG, 406 { str1 = sensor }, 407 { "Skipping sensor registration because its already registered. sensor=$str1" } 408 ) 409 } 410 logSetIgnoreTouchWhilePulsingnull411 fun logSetIgnoreTouchWhilePulsing(ignoreTouchWhilePulsing: Boolean) { 412 buffer.log( 413 TAG, 414 DEBUG, 415 { bool1 = ignoreTouchWhilePulsing }, 416 { "Prox changed while pulsing. setIgnoreTouchWhilePulsing=$bool1" } 417 ) 418 } 419 lognull420 fun log(@CompileTimeConstant msg: String) { 421 buffer.log(TAG, DEBUG, msg) 422 } 423 } 424 425 private const val TAG = "DozeLog" 426 427 val DATE_FORMAT = SimpleDateFormat("MM-dd HH:mm:ss.S", Locale.US) 428