• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(
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 
logPendingUnscheduleTimeTicknull165     fun logPendingUnscheduleTimeTick(isPending: Boolean, isTimeTickScheduled: Boolean) {
166         buffer.log(TAG, INFO, {
167             bool1 = isPending
168             bool2 = isTimeTickScheduled
169         }, {
170             "Pending unschedule time tick, isPending=$bool1, isTimeTickScheduled:$bool2"
171         })
172     }
173 
logDozeStateChangednull174     fun logDozeStateChanged(state: DozeMachine.State) {
175         buffer.log(TAG, INFO, {
176             str1 = state.name
177         }, {
178             "Doze state changed to $str1"
179         })
180     }
181 
logStateChangedSentnull182     fun logStateChangedSent(state: DozeMachine.State) {
183         buffer.log(TAG, INFO, {
184             str1 = state.name
185         }, {
186             "Doze state sent to all DozeMachineParts stateSent=$str1"
187         })
188     }
189 
logDisplayStateDelayedByUdfpsnull190     fun logDisplayStateDelayedByUdfps(delayedDisplayState: Int) {
191         buffer.log(TAG, INFO, {
192             str1 = Display.stateToString(delayedDisplayState)
193         }, {
194             "Delaying display state change to: $str1 due to UDFPS activity"
195         })
196     }
197 
logDisplayStateChangednull198     fun logDisplayStateChanged(displayState: Int) {
199         buffer.log(TAG, INFO, {
200             str1 = Display.stateToString(displayState)
201         }, {
202             "Display state changed to $str1"
203         })
204     }
205 
logWakeDisplaynull206     fun logWakeDisplay(isAwake: Boolean, @Reason reason: Int) {
207         buffer.log(TAG, DEBUG, {
208             bool1 = isAwake
209             int1 = reason
210         }, {
211             "Display wakefulness changed, isAwake=$bool1, reason=${reasonToString(int1)}"
212         })
213     }
214 
logProximityResultnull215     fun logProximityResult(isNear: Boolean, millis: Long, @Reason reason: Int) {
216         buffer.log(TAG, DEBUG, {
217             bool1 = isNear
218             long1 = millis
219             int1 = reason
220         }, {
221             "Proximity result reason=${reasonToString(int1)} near=$bool1 millis=$long1"
222         })
223     }
224 
logPostureChangednull225     fun logPostureChanged(posture: Int, partUpdated: String) {
226         buffer.log(TAG, INFO, {
227             int1 = posture
228             str1 = partUpdated
229         }, {
230             "Posture changed, posture=${DevicePostureController.devicePostureToString(int1)}" +
231                 " partUpdated=$str1"
232         })
233     }
234 
235     /**
236      * Log why a pulse was dropped and the current doze machine state. The state can be null
237      * if the DozeMachine is the middle of transitioning between states.
238      */
logPulseDroppednull239     fun logPulseDropped(from: String, state: DozeMachine.State?) {
240         buffer.log(TAG, INFO, {
241             str1 = from
242             str2 = state?.name
243         }, {
244             "Pulse dropped, cannot pulse from=$str1 state=$str2"
245         })
246     }
247 
logSensorEventDroppednull248     fun logSensorEventDropped(sensorEvent: Int, reason: String) {
249         buffer.log(TAG, INFO, {
250             int1 = sensorEvent
251             str1 = reason
252         }, {
253             "SensorEvent [$int1] dropped, reason=$str1"
254         })
255     }
256 
logPulseEventnull257     fun logPulseEvent(pulseEvent: String, dozing: Boolean, pulseReason: String) {
258         buffer.log(TAG, DEBUG, {
259             str1 = pulseEvent
260             bool1 = dozing
261             str2 = pulseReason
262         }, {
263             "Pulse-$str1 dozing=$bool1 pulseReason=$str2"
264         })
265     }
266 
logPulseDroppednull267     fun logPulseDropped(reason: String) {
268         buffer.log(TAG, INFO, {
269             str1 = reason
270         }, {
271             "Pulse dropped, why=$str1"
272         })
273     }
274 
logPulseTouchDisabledByProxnull275     fun logPulseTouchDisabledByProx(disabled: Boolean) {
276         buffer.log(TAG, DEBUG, {
277             bool1 = disabled
278         }, {
279             "Pulse touch modified by prox, disabled=$bool1"
280         })
281     }
282 
logSensorTriggerednull283     fun logSensorTriggered(@Reason reason: Int) {
284         buffer.log(TAG, DEBUG, {
285             int1 = reason
286         }, {
287             "Sensor triggered, type=${reasonToString(int1)}"
288         })
289     }
290 
logAlwaysOnSuppressednull291     fun logAlwaysOnSuppressed(state: DozeMachine.State, reason: String) {
292         buffer.log(TAG, INFO, {
293             str1 = state.name
294             str2 = reason
295         }, {
296             "Always-on state suppressed, suppressed state=$str1 reason=$str2"
297         })
298     }
299 
logImmediatelyEndDozenull300     fun logImmediatelyEndDoze(reason: String) {
301         buffer.log(TAG, INFO, {
302             str1 = reason
303         }, {
304             "Doze immediately ended due to $str1"
305         })
306     }
307 
logDozeScreenBrightnessnull308     fun logDozeScreenBrightness(brightness: Int) {
309         buffer.log(TAG, INFO, {
310             int1 = brightness
311         }, {
312             "Doze screen brightness set, brightness=$int1"
313         })
314     }
315 
logSetAodDimmingScrimnull316     fun logSetAodDimmingScrim(scrimOpacity: Long) {
317         buffer.log(TAG, INFO, {
318             long1 = scrimOpacity
319         }, {
320             "Doze aod dimming scrim opacity set, opacity=$long1"
321         })
322     }
323 
logCarModeEndednull324     fun logCarModeEnded() {
325         buffer.log(TAG, INFO, {}, {
326             "Doze car mode ended"
327         })
328     }
329 
logCarModeStartednull330     fun logCarModeStarted() {
331         buffer.log(TAG, INFO, {}, {
332             "Doze car mode started"
333         })
334     }
335 
logSensorRegisterAttemptnull336     fun logSensorRegisterAttempt(sensorInfo: String, successfulRegistration: Boolean) {
337         buffer.log(TAG, INFO, {
338             str1 = sensorInfo
339             bool1 = successfulRegistration
340         }, {
341             "Register sensor. Success=$bool1 sensor=$str1"
342         })
343     }
344 
logSensorUnregisterAttemptnull345     fun logSensorUnregisterAttempt(sensorInfo: String, successfulUnregister: Boolean) {
346         buffer.log(TAG, INFO, {
347             str1 = sensorInfo
348             bool1 = successfulUnregister
349         }, {
350             "Unregister sensor. Success=$bool1 sensor=$str1"
351         })
352     }
353 
logSensorUnregisterAttemptnull354     fun logSensorUnregisterAttempt(
355             sensorInfo: String,
356             successfulUnregister: Boolean,
357             reason: String
358     ) {
359         buffer.log(TAG, INFO, {
360             str1 = sensorInfo
361             bool1 = successfulUnregister
362             str2 = reason
363         }, {
364             "Unregister sensor. reason=$str2. Success=$bool1 sensor=$str1"
365         })
366     }
367 
logSkipSensorRegistrationnull368     fun logSkipSensorRegistration(sensor: String) {
369         buffer.log(TAG, DEBUG, {
370             str1 = sensor
371         }, {
372             "Skipping sensor registration because its already registered. sensor=$str1"
373         })
374     }
375 
logSetIgnoreTouchWhilePulsingnull376     fun logSetIgnoreTouchWhilePulsing(ignoreTouchWhilePulsing: Boolean) {
377         buffer.log(TAG, DEBUG, {
378             bool1 = ignoreTouchWhilePulsing
379         }, {
380             "Prox changed while pulsing. setIgnoreTouchWhilePulsing=$bool1"
381         })
382     }
383 
lognull384     fun log(@CompileTimeConstant msg: String) {
385         buffer.log(TAG, DEBUG, msg)
386     }
387 }
388 
389 private const val TAG = "DozeLog"
390 
391 val DATE_FORMAT = SimpleDateFormat("MM-dd HH:mm:ss.S", Locale.US)
392