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 com.android.systemui.doze.DozeLog.Reason 20 import com.android.systemui.doze.DozeLog.reasonToString 21 import com.android.systemui.log.LogBuffer 22 import com.android.systemui.log.LogLevel.DEBUG 23 import com.android.systemui.log.LogLevel.ERROR 24 import com.android.systemui.log.LogLevel.INFO 25 import com.android.systemui.log.dagger.DozeLog 26 import java.text.SimpleDateFormat 27 import java.util.Date 28 import java.util.Locale 29 import javax.inject.Inject 30 31 /** Interface for logging messages to the [DozeLog]. */ 32 class DozeLogger @Inject constructor( 33 @DozeLog private val buffer: LogBuffer 34 ) { logPickupWakeupnull35 fun logPickupWakeup(isWithinVibrationThreshold: Boolean) { 36 buffer.log(TAG, DEBUG, { 37 bool1 = isWithinVibrationThreshold 38 }, { 39 "PickupWakeup withinVibrationThreshold=$bool1" 40 }) 41 } 42 logPulseStartnull43 fun logPulseStart(@Reason reason: Int) { 44 buffer.log(TAG, INFO, { 45 int1 = reason 46 }, { 47 "Pulse start, reason=${reasonToString(int1)}" 48 }) 49 } 50 logPulseFinishnull51 fun logPulseFinish() { 52 buffer.log(TAG, INFO, {}, { "Pulse finish" }) 53 } 54 logNotificationPulsenull55 fun logNotificationPulse() { 56 buffer.log(TAG, INFO, {}, { "Notification pulse" }) 57 } 58 logDozingnull59 fun logDozing(isDozing: Boolean) { 60 buffer.log(TAG, INFO, { 61 bool1 = isDozing 62 }, { 63 "Dozing=$bool1" 64 }) 65 } 66 logFlingnull67 fun logFling( 68 expand: Boolean, 69 aboveThreshold: Boolean, 70 thresholdNeeded: Boolean, 71 screenOnFromTouch: Boolean 72 ) { 73 buffer.log(TAG, DEBUG, { 74 bool1 = expand 75 bool2 = aboveThreshold 76 bool3 = thresholdNeeded 77 bool4 = screenOnFromTouch 78 }, { 79 "Fling expand=$bool1 aboveThreshold=$bool2 thresholdNeeded=$bool3 " + 80 "screenOnFromTouch=$bool4" 81 }) 82 } 83 logEmergencyCallnull84 fun logEmergencyCall() { 85 buffer.log(TAG, INFO, {}, { "Emergency call" }) 86 } 87 logKeyguardBouncerChangednull88 fun logKeyguardBouncerChanged(isShowing: Boolean) { 89 buffer.log(TAG, INFO, { 90 bool1 = isShowing 91 }, { 92 "Keyguard bouncer changed, showing=$bool1" 93 }) 94 } 95 logScreenOnnull96 fun logScreenOn(isPulsing: Boolean) { 97 buffer.log(TAG, INFO, { 98 bool1 = isPulsing 99 }, { 100 "Screen on, pulsing=$bool1" 101 }) 102 } 103 logScreenOffnull104 fun logScreenOff(why: Int) { 105 buffer.log(TAG, INFO, { 106 int1 = why 107 }, { 108 "Screen off, why=$int1" 109 }) 110 } 111 logMissedTicknull112 fun logMissedTick(delay: String) { 113 buffer.log(TAG, ERROR, { 114 str1 = delay 115 }, { 116 "Missed AOD time tick by $str1" 117 }) 118 } 119 logTimeTickSchedulednull120 fun logTimeTickScheduled(whenAt: Long, triggerAt: Long) { 121 buffer.log(TAG, DEBUG, { 122 long1 = whenAt 123 long2 = triggerAt 124 }, { 125 "Time tick scheduledAt=${DATE_FORMAT.format(Date(long1))} " + 126 "triggerAt=${DATE_FORMAT.format(Date(long2))}" 127 }) 128 } 129 logKeyguardVisibilityChangenull130 fun logKeyguardVisibilityChange(isShowing: Boolean) { 131 buffer.log(TAG, INFO, { 132 bool1 = isShowing 133 }, { 134 "Keyguard visibility change, isShowing=$bool1" 135 }) 136 } 137 logDozeStateChangednull138 fun logDozeStateChanged(state: DozeMachine.State) { 139 buffer.log(TAG, INFO, { 140 str1 = state.name 141 }, { 142 "Doze state changed to $str1" 143 }) 144 } 145 logWakeDisplaynull146 fun logWakeDisplay(isAwake: Boolean) { 147 buffer.log(TAG, DEBUG, { 148 bool1 = isAwake 149 }, { 150 "Display wakefulness changed, isAwake=$bool1" 151 }) 152 } 153 logProximityResultnull154 fun logProximityResult(isNear: Boolean, millis: Long, @Reason reason: Int) { 155 buffer.log(TAG, DEBUG, { 156 bool1 = isNear 157 long1 = millis 158 int1 = reason 159 }, { 160 "Proximity result reason=${reasonToString(int1)} near=$bool1 millis=$long1" 161 }) 162 } 163 logPulseDroppednull164 fun logPulseDropped(pulsePending: Boolean, state: DozeMachine.State, blocked: Boolean) { 165 buffer.log(TAG, INFO, { 166 bool1 = pulsePending 167 str1 = state.name 168 bool2 = blocked 169 }, { 170 "Pulse dropped, pulsePending=$bool1 state=$str1 blocked=$bool2" 171 }) 172 } 173 logPulseDroppednull174 fun logPulseDropped(reason: String) { 175 buffer.log(TAG, INFO, { 176 str1 = reason 177 }, { 178 "Pulse dropped, why=$str1" 179 }) 180 } 181 logPulseTouchDisabledByProxnull182 fun logPulseTouchDisabledByProx(disabled: Boolean) { 183 buffer.log(TAG, DEBUG, { 184 bool1 = disabled 185 }, { 186 "Pulse touch modified by prox, disabled=$bool1" 187 }) 188 } 189 logSensorTriggerednull190 fun logSensorTriggered(@Reason reason: Int) { 191 buffer.log(TAG, DEBUG, { 192 int1 = reason 193 }, { 194 "Sensor triggered, type=${reasonToString(int1)}" 195 }) 196 } 197 logDozeSuppressednull198 fun logDozeSuppressed(state: DozeMachine.State) { 199 buffer.log(TAG, INFO, { 200 str1 = state.name 201 }, { 202 "Doze state suppressed, state=$str1" 203 }) 204 } 205 } 206 207 private const val TAG = "DozeLog" 208 209 val DATE_FORMAT = SimpleDateFormat("MM-dd HH:mm:ss.S", Locale.US) 210