• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
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.keyguard.logging
18 
19 import android.content.Intent
20 import android.hardware.biometrics.BiometricConstants.LockoutMode
21 import android.hardware.biometrics.BiometricSourceType
22 import android.os.PowerManager
23 import android.telephony.ServiceState
24 import android.telephony.SubscriptionInfo
25 import android.telephony.SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX
26 import android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID
27 import android.telephony.TelephonyManager
28 import com.android.keyguard.ActiveUnlockConfig
29 import com.android.keyguard.KeyguardListenModel
30 import com.android.keyguard.KeyguardUpdateMonitorCallback
31 import com.android.keyguard.TrustGrantFlags
32 import com.android.settingslib.fuelgauge.BatteryStatus
33 import com.android.systemui.log.LogBuffer
34 import com.android.systemui.log.core.LogLevel
35 import com.android.systemui.log.core.LogLevel.DEBUG
36 import com.android.systemui.log.core.LogLevel.ERROR
37 import com.android.systemui.log.core.LogLevel.INFO
38 import com.android.systemui.log.core.LogLevel.VERBOSE
39 import com.android.systemui.log.core.LogLevel.WARNING
40 import com.android.systemui.log.dagger.KeyguardUpdateMonitorLog
41 import com.google.errorprone.annotations.CompileTimeConstant
42 import javax.inject.Inject
43 
44 private const val TAG = "KeyguardUpdateMonitorLog"
45 private const val FP_LOG_TAG = "KeyguardFingerprintLog"
46 
47 /** Helper class for logging for [com.android.keyguard.KeyguardUpdateMonitor] */
48 class KeyguardUpdateMonitorLogger
49 @Inject
50 constructor(@KeyguardUpdateMonitorLog private val logBuffer: LogBuffer) {
dnull51     fun d(@CompileTimeConstant msg: String) = log(msg, DEBUG)
52 
53     fun e(@CompileTimeConstant msg: String) = log(msg, ERROR)
54 
55     fun v(@CompileTimeConstant msg: String) = log(msg, VERBOSE)
56 
57     fun w(@CompileTimeConstant msg: String) = log(msg, WARNING)
58 
59     fun log(@CompileTimeConstant msg: String, level: LogLevel) = logBuffer.log(TAG, level, msg)
60 
61     fun logActiveUnlockTriggered(reason: String?) {
62         logBuffer.log(
63             "ActiveUnlock",
64             DEBUG,
65             { str1 = reason },
66             { "initiate active unlock triggerReason=$str1" }
67         )
68     }
69 
logActiveUnlockRequestSkippedForWakeReasonDueToFaceConfignull70     fun logActiveUnlockRequestSkippedForWakeReasonDueToFaceConfig(wakeReason: Int) {
71         logBuffer.log(
72             "ActiveUnlock",
73             DEBUG,
74             { int1 = wakeReason },
75             {
76                 "Skip requesting active unlock from wake reason that doesn't trigger face auth" +
77                     " reason=${PowerManager.wakeReasonToString(int1)}"
78             }
79         )
80     }
81 
logAuthInterruptDetectednull82     fun logAuthInterruptDetected(active: Boolean) {
83         logBuffer.log(TAG, DEBUG, { bool1 = active }, { "onAuthInterruptDetected($bool1)" })
84     }
85 
logBroadcastReceivednull86     fun logBroadcastReceived(action: String?) {
87         logBuffer.log(TAG, DEBUG, { str1 = action }, { "received broadcast $str1" })
88     }
89 
logDeviceProvisionedStatenull90     fun logDeviceProvisionedState(deviceProvisioned: Boolean) {
91         logBuffer.log(
92             TAG,
93             DEBUG,
94             { bool1 = deviceProvisioned },
95             { "DEVICE_PROVISIONED state = $bool1" }
96         )
97     }
98 
logExceptionnull99     fun logException(ex: Exception, @CompileTimeConstant logMsg: String) {
100         logBuffer.log(TAG, ERROR, {}, { logMsg }, exception = ex)
101     }
102 
logFaceAuthErrornull103     fun logFaceAuthError(msgId: Int, originalErrMsg: String) {
104         logBuffer.log(
105             TAG,
106             DEBUG,
107             {
108                 str1 = originalErrMsg
109                 int1 = msgId
110             },
111             { "Face error received: $str1 msgId= $int1" }
112         )
113     }
114 
logFaceAuthForWrongUsernull115     fun logFaceAuthForWrongUser(authUserId: Int) {
116         logBuffer.log(
117             TAG,
118             DEBUG,
119             { int1 = authUserId },
120             { "Face authenticated for wrong user: $int1" }
121         )
122     }
123 
logFaceAuthSuccessnull124     fun logFaceAuthSuccess(userId: Int) {
125         logBuffer.log(TAG, DEBUG, { int1 = userId }, { "Face auth succeeded for user $int1" })
126     }
127 
logFingerprintAuthForWrongUsernull128     fun logFingerprintAuthForWrongUser(authUserId: Int) {
129         logBuffer.log(
130             FP_LOG_TAG,
131             DEBUG,
132             { int1 = authUserId },
133             { "Fingerprint authenticated for wrong user: $int1" }
134         )
135     }
136 
logFingerprintDisabledForUsernull137     fun logFingerprintDisabledForUser(userId: Int) {
138         logBuffer.log(
139             FP_LOG_TAG,
140             DEBUG,
141             { int1 = userId },
142             { "Fingerprint disabled by DPM for userId: $int1" }
143         )
144     }
145 
logFingerprintLockoutResetnull146     fun logFingerprintLockoutReset(@LockoutMode mode: Int) {
147         logBuffer.log(
148             FP_LOG_TAG,
149             DEBUG,
150             { int1 = mode },
151             { "handleFingerprintLockoutReset: $int1" }
152         )
153     }
154 
logFingerprintRunningStatenull155     fun logFingerprintRunningState(fingerprintRunningState: Int) {
156         logBuffer.log(
157             FP_LOG_TAG,
158             DEBUG,
159             { int1 = fingerprintRunningState },
160             { "fingerprintRunningState: $int1" }
161         )
162     }
163 
logFingerprintSuccessnull164     fun logFingerprintSuccess(userId: Int, isStrongBiometric: Boolean) {
165         logBuffer.log(
166             FP_LOG_TAG,
167             DEBUG,
168             {
169                 int1 = userId
170                 bool1 = isStrongBiometric
171             },
172             { "Fingerprint auth successful: userId: $int1, isStrongBiometric: $bool1" }
173         )
174     }
175 
logFaceDetectednull176     fun logFaceDetected(userId: Int, isStrongBiometric: Boolean) {
177         logBuffer.log(
178             TAG,
179             DEBUG,
180             {
181                 int1 = userId
182                 bool1 = isStrongBiometric
183             },
184             { "Face detected: userId: $int1, isStrongBiometric: $bool1" }
185         )
186     }
187 
logFingerprintDetectednull188     fun logFingerprintDetected(userId: Int, isStrongBiometric: Boolean) {
189         logBuffer.log(
190             FP_LOG_TAG,
191             DEBUG,
192             {
193                 int1 = userId
194                 bool1 = isStrongBiometric
195             },
196             { "Fingerprint detected: userId: $int1, isStrongBiometric: $bool1" }
197         )
198     }
199 
logFingerprintErrornull200     fun logFingerprintError(msgId: Int, originalErrMsg: String) {
201         logBuffer.log(
202             FP_LOG_TAG,
203             DEBUG,
204             {
205                 str1 = originalErrMsg
206                 int1 = msgId
207             },
208             { "Fingerprint error received: $str1 msgId= $int1" }
209         )
210     }
211 
logInvalidSubIdnull212     fun logInvalidSubId(subId: Int) {
213         logBuffer.log(
214             TAG,
215             INFO,
216             { int1 = subId },
217             { "Previously active sub id $int1 is now invalid, will remove" }
218         )
219     }
220 
logPrimaryKeyguardBouncerChangednull221     fun logPrimaryKeyguardBouncerChanged(
222         primaryBouncerIsOrWillBeShowing: Boolean,
223         primaryBouncerFullyShown: Boolean
224     ) {
225         logBuffer.log(
226             TAG,
227             DEBUG,
228             {
229                 bool1 = primaryBouncerIsOrWillBeShowing
230                 bool2 = primaryBouncerFullyShown
231             },
232             {
233                 "handlePrimaryBouncerChanged " +
234                     "primaryBouncerIsOrWillBeShowing=$bool1 primaryBouncerFullyShown=$bool2"
235             }
236         )
237     }
238 
logKeyguardListenerModelnull239     fun logKeyguardListenerModel(model: KeyguardListenModel) {
240         logBuffer.log(TAG, VERBOSE, { str1 = "$model" }, { str1!! })
241     }
242 
logKeyguardShowingChangednull243     fun logKeyguardShowingChanged(showing: Boolean, occluded: Boolean, visible: Boolean) {
244         logBuffer.log(
245             TAG,
246             DEBUG,
247             {
248                 bool1 = showing
249                 bool2 = occluded
250                 bool3 = visible
251             },
252             { "keyguardShowingChanged(showing=$bool1 occluded=$bool2 visible=$bool3)" }
253         )
254     }
255 
logMissingSupervisorAppErrornull256     fun logMissingSupervisorAppError(userId: Int) {
257         logBuffer.log(
258             TAG,
259             ERROR,
260             { int1 = userId },
261             { "No Profile Owner or Device Owner supervision app found for User $int1" }
262         )
263     }
264 
logPhoneStateChangednull265     fun logPhoneStateChanged(newState: String?) {
266         logBuffer.log(TAG, DEBUG, { str1 = newState }, { "handlePhoneStateChanged($str1)" })
267     }
268 
logRegisterCallbacknull269     fun logRegisterCallback(callback: KeyguardUpdateMonitorCallback?) {
270         logBuffer.log(TAG, VERBOSE, { str1 = "$callback" }, { "*** register callback for $str1" })
271     }
272 
logRetryAfterFpErrorWithDelaynull273     fun logRetryAfterFpErrorWithDelay(msgId: Int, errString: String?, delay: Int) {
274         logBuffer.log(
275             TAG,
276             DEBUG,
277             {
278                 int1 = msgId
279                 int2 = delay
280                 str1 = "$errString"
281             },
282             { "Fingerprint scheduling retry auth after $int2 ms due to($int1) -> $str1" }
283         )
284     }
285 
logRetryAfterFpHwUnavailablenull286     fun logRetryAfterFpHwUnavailable(retryCount: Int) {
287         logBuffer.log(
288             TAG,
289             WARNING,
290             { int1 = retryCount },
291             { "Retrying fingerprint attempt: $int1" }
292         )
293     }
294 
logSendPrimaryBouncerChangednull295     fun logSendPrimaryBouncerChanged(
296         primaryBouncerIsOrWillBeShowing: Boolean,
297         primaryBouncerFullyShown: Boolean,
298     ) {
299         logBuffer.log(
300             TAG,
301             DEBUG,
302             {
303                 bool1 = primaryBouncerIsOrWillBeShowing
304                 bool2 = primaryBouncerFullyShown
305             },
306             {
307                 "sendPrimaryBouncerChanged primaryBouncerIsOrWillBeShowing=$bool1 " +
308                     "primaryBouncerFullyShown=$bool2"
309             }
310         )
311     }
312 
logServiceStateChangenull313     fun logServiceStateChange(subId: Int, serviceState: ServiceState?) {
314         logBuffer.log(
315             TAG,
316             DEBUG,
317             {
318                 int1 = subId
319                 str1 = "$serviceState"
320             },
321             { "handleServiceStateChange(subId=$int1, serviceState=$str1)" }
322         )
323     }
324 
logServiceStateIntentnull325     fun logServiceStateIntent(action: String?, serviceState: ServiceState?, subId: Int) {
326         logBuffer.log(
327             TAG,
328             VERBOSE,
329             {
330                 str1 = action
331                 str2 = "$serviceState"
332                 int1 = subId
333             },
334             { "action $str1 serviceState=$str2 subId=$int1" }
335         )
336     }
337 
logServiceProvidersUpdatednull338     fun logServiceProvidersUpdated(intent: Intent) {
339         logBuffer.log(
340             TAG,
341             VERBOSE,
342             {
343                 int1 = intent.getIntExtra(EXTRA_SUBSCRIPTION_INDEX, INVALID_SUBSCRIPTION_ID)
344                 str1 = intent.getStringExtra(TelephonyManager.EXTRA_SPN)
345                 str2 = intent.getStringExtra(TelephonyManager.EXTRA_PLMN)
346             },
347             { "action SERVICE_PROVIDERS_UPDATED subId=$int1 spn=$str1 plmn=$str2" }
348         )
349     }
350 
logSimStatenull351     fun logSimState(subId: Int, slotId: Int, state: Int) {
352         logBuffer.log(
353             TAG,
354             DEBUG,
355             {
356                 int1 = subId
357                 int2 = slotId
358                 long1 = state.toLong()
359             },
360             { "handleSimStateChange(subId=$int1, slotId=$int2, state=$long1)" }
361         )
362     }
363 
logSimStateFromIntentnull364     fun logSimStateFromIntent(action: String?, extraSimState: String?, slotId: Int, subId: Int) {
365         logBuffer.log(
366             TAG,
367             VERBOSE,
368             {
369                 str1 = action
370                 str2 = extraSimState
371                 int1 = slotId
372                 int2 = subId
373             },
374             { "action $str1 state: $str2 slotId: $int1 subid: $int2" }
375         )
376     }
377 
logSimUnlockednull378     fun logSimUnlocked(subId: Int) {
379         logBuffer.log(TAG, VERBOSE, { int1 = subId }, { "reportSimUnlocked(subId=$int1)" })
380     }
381 
logSubInfonull382     fun logSubInfo(subInfo: SubscriptionInfo?) {
383         logBuffer.log(TAG, DEBUG, { str1 = "$subInfo" }, { "SubInfo:$str1" })
384     }
385 
logTimeFormatChangednull386     fun logTimeFormatChanged(newTimeFormat: String?) {
387         logBuffer.log(
388             TAG,
389             DEBUG,
390             { str1 = newTimeFormat },
391             { "handleTimeFormatUpdate timeFormat=$str1" }
392         )
393     }
logUdfpsPointerDownnull394     fun logUdfpsPointerDown(sensorId: Int) {
395         logBuffer.log(TAG, DEBUG, { int1 = sensorId }, { "onUdfpsPointerDown, sensorId: $int1" })
396     }
397 
logUdfpsPointerUpnull398     fun logUdfpsPointerUp(sensorId: Int) {
399         logBuffer.log(TAG, DEBUG, { int1 = sensorId }, { "onUdfpsPointerUp, sensorId: $int1" })
400     }
401 
logUnexpectedFpCancellationSignalStatenull402     fun logUnexpectedFpCancellationSignalState(
403         fingerprintRunningState: Int,
404         unlockPossible: Boolean
405     ) {
406         logBuffer.log(
407             TAG,
408             ERROR,
409             {
410                 int1 = fingerprintRunningState
411                 bool1 = unlockPossible
412             },
413             {
414                 "Cancellation signal is not null, high chance of bug in " +
415                     "fp auth lifecycle management. FP state: $int1, unlockPossible: $bool1"
416             }
417         )
418     }
419 
logUnregisterCallbacknull420     fun logUnregisterCallback(callback: KeyguardUpdateMonitorCallback?) {
421         logBuffer.log(TAG, VERBOSE, { str1 = "$callback" }, { "*** unregister callback for $str1" })
422     }
423 
logUserRequestedUnlocknull424     fun logUserRequestedUnlock(
425         requestOrigin: ActiveUnlockConfig.ActiveUnlockRequestOrigin,
426         reason: String?,
427         dismissKeyguard: Boolean
428     ) {
429         logBuffer.log(
430             "ActiveUnlock",
431             DEBUG,
432             {
433                 str1 = requestOrigin?.name
434                 str2 = reason
435                 bool1 = dismissKeyguard
436             },
437             { "reportUserRequestedUnlock origin=$str1 reason=$str2 dismissKeyguard=$bool1" }
438         )
439     }
440 
logTrustGrantedWithFlagsnull441     fun logTrustGrantedWithFlags(
442         flags: Int,
443         newlyUnlocked: Boolean,
444         userId: Int,
445         message: String?
446     ) {
447         logBuffer.log(
448             TAG,
449             DEBUG,
450             {
451                 int1 = flags
452                 bool1 = newlyUnlocked
453                 int2 = userId
454                 str1 = message
455             },
456             {
457                 "trustGrantedWithFlags[user=$int2] newlyUnlocked=$bool1 " +
458                     "flags=${TrustGrantFlags(int1)} message=$str1"
459             }
460         )
461     }
462 
logTrustChangednull463     fun logTrustChanged(wasTrusted: Boolean, isNowTrusted: Boolean, userId: Int) {
464         logBuffer.log(
465             TAG,
466             DEBUG,
467             {
468                 bool1 = wasTrusted
469                 bool2 = isNowTrusted
470                 int1 = userId
471             },
472             { "onTrustChanged[user=$int1] wasTrusted=$bool1 isNowTrusted=$bool2" }
473         )
474     }
475 
logKeyguardStateUpdatenull476     fun logKeyguardStateUpdate(
477         secure: Boolean,
478         canDismissLockScreen: Boolean,
479         trusted: Boolean,
480         trustManaged: Boolean
481     ) {
482         logBuffer.log(
483             "KeyguardState",
484             DEBUG,
485             {
486                 bool1 = secure
487                 bool2 = canDismissLockScreen
488                 bool3 = trusted
489                 bool4 = trustManaged
490             },
491             {
492                 "#update secure=$bool1 canDismissKeyguard=$bool2" +
493                     " trusted=$bool3 trustManaged=$bool4"
494             }
495         )
496     }
497 
logTaskStackChangedForAssistantnull498     fun logTaskStackChangedForAssistant(assistantVisible: Boolean) {
499         logBuffer.log(
500             TAG,
501             VERBOSE,
502             { bool1 = assistantVisible },
503             { "TaskStackChanged for ACTIVITY_TYPE_ASSISTANT, assistant visible: $bool1" }
504         )
505     }
506 
allowFingerprintOnCurrentOccludingActivityChangednull507     fun allowFingerprintOnCurrentOccludingActivityChanged(allow: Boolean) {
508         logBuffer.log(
509             TAG,
510             VERBOSE,
511             { bool1 = allow },
512             { "allowFingerprintOnCurrentOccludingActivityChanged: $bool1" }
513         )
514     }
515 
logAssistantVisiblenull516     fun logAssistantVisible(assistantVisible: Boolean) {
517         logBuffer.log(
518             TAG,
519             VERBOSE,
520             { bool1 = assistantVisible },
521             { "Updating mAssistantVisible to new value: $bool1" }
522         )
523     }
524 
logReportSuccessfulBiometricUnlocknull525     fun logReportSuccessfulBiometricUnlock(isStrongBiometric: Boolean, userId: Int) {
526         logBuffer.log(
527             TAG,
528             DEBUG,
529             {
530                 bool1 = isStrongBiometric
531                 int1 = userId
532             },
533             { "reporting successful biometric unlock: isStrongBiometric: $bool1, userId: $int1" }
534         )
535     }
536 
logHandlerHasAuthContinueMsgsnull537     fun logHandlerHasAuthContinueMsgs(action: Int) {
538         logBuffer.log(
539             TAG,
540             DEBUG,
541             { int1 = action },
542             {
543                 "MSG_BIOMETRIC_AUTHENTICATION_CONTINUE already queued up, " +
544                     "ignoring updating FP listening state to $int1"
545             }
546         )
547     }
548 
logTrustUsuallyManagedUpdatednull549     fun logTrustUsuallyManagedUpdated(
550         userId: Int,
551         oldValue: Boolean,
552         newValue: Boolean,
553         context: String
554     ) {
555         logBuffer.log(
556             TAG,
557             DEBUG,
558             {
559                 int1 = userId
560                 bool1 = oldValue
561                 bool2 = newValue
562                 str1 = context
563             },
564             {
565                 "trustUsuallyManaged changed for " +
566                     "userId: $int1 " +
567                     "old: $bool1, " +
568                     "new: $bool2 " +
569                     "context: $str1"
570             }
571         )
572     }
573 
logHandleBatteryUpdatenull574     fun logHandleBatteryUpdate(batteryStatus: BatteryStatus?) {
575         logBuffer.log(
576             TAG,
577             DEBUG,
578             {
579                 bool1 = batteryStatus != null
580                 int1 = batteryStatus?.status ?: -1
581                 int2 = batteryStatus?.chargingStatus ?: -1
582                 long1 = (batteryStatus?.level ?: -1).toLong()
583                 long2 = (batteryStatus?.maxChargingWattage ?: -1).toLong()
584                 str1 = "${batteryStatus?.plugged ?: -1}"
585             },
586             {
587                 "handleBatteryUpdate: isNotNull: $bool1 " +
588                     "BatteryStatus{status= $int1, " +
589                     "level=$long1, " +
590                     "plugged=$str1, " +
591                     "chargingStatus=$int2, " +
592                     "maxChargingWattage= $long2}"
593             }
594         )
595     }
596 
scheduleWatchdognull597     fun scheduleWatchdog(@CompileTimeConstant watchdogType: String) {
598         logBuffer.log(TAG, DEBUG, "Scheduling biometric watchdog for $watchdogType")
599     }
600 
notifyAboutEnrollmentsChangednull601     fun notifyAboutEnrollmentsChanged(biometricSourceType: BiometricSourceType) {
602         logBuffer.log(
603             TAG,
604             DEBUG,
605             { str1 = "$biometricSourceType" },
606             { "notifying about enrollments changed: $str1" }
607         )
608     }
609 
logUserSwitchingnull610     fun logUserSwitching(userId: Int, context: String) {
611         logBuffer.log(
612             TAG,
613             DEBUG,
614             {
615                 int1 = userId
616                 str1 = context
617             },
618             { "userCurrentlySwitching: $str1, userId: $int1" }
619         )
620     }
621 
logUserSwitchCompletenull622     fun logUserSwitchComplete(userId: Int, context: String) {
623         logBuffer.log(
624             TAG,
625             DEBUG,
626             {
627                 int1 = userId
628                 str1 = context
629             },
630             { "userSwitchComplete: $str1, userId: $int1" }
631         )
632     }
633 
logFingerprintAcquirednull634     fun logFingerprintAcquired(acquireInfo: Int) {
635         logBuffer.log(
636             FP_LOG_TAG,
637             DEBUG,
638             { int1 = acquireInfo },
639             { "fingerprint acquire message: $int1" }
640         )
641     }
logForceIsDismissibleKeyguardnull642     fun logForceIsDismissibleKeyguard(keepUnlocked: Boolean) {
643         logBuffer.log(
644                 TAG,
645                 DEBUG,
646                 { bool1 = keepUnlocked },
647                 { "keepUnlockedOnFold changed to: $bool1" }
648         )
649     }
650 }
651