• 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.SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX
24 import android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID
25 import android.telephony.TelephonyManager
26 import com.android.keyguard.ActiveUnlockConfig
27 import com.android.keyguard.KeyguardListenModel
28 import com.android.keyguard.KeyguardUpdateMonitorCallback
29 import com.android.keyguard.TrustGrantFlags
30 import com.android.settingslib.fuelgauge.BatteryStatus
31 import com.android.systemui.log.LogBuffer
32 import com.android.systemui.log.core.LogLevel
33 import com.android.systemui.log.core.LogLevel.DEBUG
34 import com.android.systemui.log.core.LogLevel.ERROR
35 import com.android.systemui.log.core.LogLevel.VERBOSE
36 import com.android.systemui.log.core.LogLevel.WARNING
37 import com.android.systemui.log.dagger.KeyguardUpdateMonitorLog
38 import com.google.errorprone.annotations.CompileTimeConstant
39 import javax.inject.Inject
40 
41 private const val TAG = "KeyguardUpdateMonitorLog"
42 private const val FP_LOG_TAG = "KeyguardFingerprintLog"
43 
44 /** Helper class for logging for [com.android.keyguard.KeyguardUpdateMonitor] */
45 class KeyguardUpdateMonitorLogger
46 @Inject
47 constructor(@KeyguardUpdateMonitorLog private val logBuffer: LogBuffer) {
dnull48     fun d(@CompileTimeConstant msg: String) = log(msg, DEBUG)
49 
50     fun e(@CompileTimeConstant msg: String) = log(msg, ERROR)
51 
52     fun v(@CompileTimeConstant msg: String) = log(msg, VERBOSE)
53 
54     fun w(@CompileTimeConstant msg: String) = log(msg, WARNING)
55 
56     fun log(@CompileTimeConstant msg: String, level: LogLevel) = logBuffer.log(TAG, level, msg)
57 
58     fun logActiveUnlockTriggered(reason: String?) {
59         logBuffer.log(
60             "ActiveUnlock",
61             DEBUG,
62             { str1 = reason },
63             { "initiate active unlock triggerReason=$str1" },
64         )
65     }
66 
logActiveUnlockRequestSkippedForWakeReasonDueToFaceConfignull67     fun logActiveUnlockRequestSkippedForWakeReasonDueToFaceConfig(wakeReason: Int) {
68         logBuffer.log(
69             "ActiveUnlock",
70             DEBUG,
71             { int1 = wakeReason },
72             {
73                 "Skip requesting active unlock from wake reason that doesn't trigger face auth" +
74                     " reason=${PowerManager.wakeReasonToString(int1)}"
75             },
76         )
77     }
78 
logAuthInterruptDetectednull79     fun logAuthInterruptDetected(active: Boolean) {
80         logBuffer.log(TAG, DEBUG, { bool1 = active }, { "onAuthInterruptDetected($bool1)" })
81     }
82 
logBroadcastReceivednull83     fun logBroadcastReceived(action: String?) {
84         logBuffer.log(TAG, DEBUG, { str1 = action }, { "received broadcast $str1" })
85     }
86 
logDeviceProvisionedStatenull87     fun logDeviceProvisionedState(deviceProvisioned: Boolean) {
88         logBuffer.log(
89             TAG,
90             DEBUG,
91             { bool1 = deviceProvisioned },
92             { "DEVICE_PROVISIONED state = $bool1" },
93         )
94     }
95 
logExceptionnull96     fun logException(ex: Exception, @CompileTimeConstant logMsg: String) {
97         logBuffer.log(TAG, ERROR, {}, { logMsg }, exception = ex)
98     }
99 
logFaceAuthErrornull100     fun logFaceAuthError(msgId: Int, originalErrMsg: String) {
101         logBuffer.log(
102             TAG,
103             DEBUG,
104             {
105                 str1 = originalErrMsg
106                 int1 = msgId
107             },
108             { "Face error received: $str1 msgId= $int1" },
109         )
110     }
111 
logFaceAuthForWrongUsernull112     fun logFaceAuthForWrongUser(authUserId: Int) {
113         logBuffer.log(
114             TAG,
115             DEBUG,
116             { int1 = authUserId },
117             { "Face authenticated for wrong user: $int1" },
118         )
119     }
120 
logFaceAuthSuccessnull121     fun logFaceAuthSuccess(userId: Int) {
122         logBuffer.log(TAG, DEBUG, { int1 = userId }, { "Face auth succeeded for user $int1" })
123     }
124 
logFingerprintAuthForWrongUsernull125     fun logFingerprintAuthForWrongUser(authUserId: Int) {
126         logBuffer.log(
127             FP_LOG_TAG,
128             DEBUG,
129             { int1 = authUserId },
130             { "Fingerprint authenticated for wrong user: $int1" },
131         )
132     }
133 
logFingerprintDisabledForUsernull134     fun logFingerprintDisabledForUser(userId: Int) {
135         logBuffer.log(
136             FP_LOG_TAG,
137             DEBUG,
138             { int1 = userId },
139             { "Fingerprint disabled by DPM for userId: $int1" },
140         )
141     }
142 
logFingerprintLockoutResetnull143     fun logFingerprintLockoutReset(@LockoutMode mode: Int) {
144         logBuffer.log(
145             FP_LOG_TAG,
146             DEBUG,
147             { int1 = mode },
148             { "handleFingerprintLockoutReset: $int1" },
149         )
150     }
151 
logFingerprintRunningStatenull152     fun logFingerprintRunningState(fingerprintRunningState: Int) {
153         logBuffer.log(
154             FP_LOG_TAG,
155             DEBUG,
156             { int1 = fingerprintRunningState },
157             { "fingerprintRunningState: $int1" },
158         )
159     }
160 
logFingerprintSuccessnull161     fun logFingerprintSuccess(userId: Int, isStrongBiometric: Boolean) {
162         logBuffer.log(
163             FP_LOG_TAG,
164             DEBUG,
165             {
166                 int1 = userId
167                 bool1 = isStrongBiometric
168             },
169             { "Fingerprint auth successful: userId: $int1, isStrongBiometric: $bool1" },
170         )
171     }
172 
logFaceDetectednull173     fun logFaceDetected(userId: Int, isStrongBiometric: Boolean) {
174         logBuffer.log(
175             TAG,
176             DEBUG,
177             {
178                 int1 = userId
179                 bool1 = isStrongBiometric
180             },
181             { "Face detected: userId: $int1, isStrongBiometric: $bool1" },
182         )
183     }
184 
logFingerprintDetectednull185     fun logFingerprintDetected(userId: Int, isStrongBiometric: Boolean) {
186         logBuffer.log(
187             FP_LOG_TAG,
188             DEBUG,
189             {
190                 int1 = userId
191                 bool1 = isStrongBiometric
192             },
193             { "Fingerprint detected: userId: $int1, isStrongBiometric: $bool1" },
194         )
195     }
196 
logFingerprintErrornull197     fun logFingerprintError(msgId: Int, originalErrMsg: String) {
198         logBuffer.log(
199             FP_LOG_TAG,
200             DEBUG,
201             {
202                 str1 = originalErrMsg
203                 int1 = msgId
204             },
205             { "Fingerprint error received: $str1 msgId= $int1" },
206         )
207     }
208 
logPrimaryKeyguardBouncerChangednull209     fun logPrimaryKeyguardBouncerChanged(
210         primaryBouncerIsOrWillBeShowing: Boolean,
211         primaryBouncerFullyShown: Boolean,
212     ) {
213         logBuffer.log(
214             TAG,
215             DEBUG,
216             {
217                 bool1 = primaryBouncerIsOrWillBeShowing
218                 bool2 = primaryBouncerFullyShown
219             },
220             {
221                 "handlePrimaryBouncerChanged " +
222                     "primaryBouncerIsOrWillBeShowing=$bool1 primaryBouncerFullyShown=$bool2"
223             },
224         )
225     }
226 
logKeyguardListenerModelnull227     fun logKeyguardListenerModel(model: KeyguardListenModel) {
228         logBuffer.log(TAG, VERBOSE, { str1 = "$model" }, { str1!! })
229     }
230 
logKeyguardShowingChangednull231     fun logKeyguardShowingChanged(showing: Boolean, occluded: Boolean, visible: Boolean) {
232         logBuffer.log(
233             TAG,
234             DEBUG,
235             {
236                 bool1 = showing
237                 bool2 = occluded
238                 bool3 = visible
239             },
240             { "keyguardShowingChanged(showing=$bool1 occluded=$bool2 visible=$bool3)" },
241         )
242     }
243 
logMissingSupervisorAppErrornull244     fun logMissingSupervisorAppError(userId: Int) {
245         logBuffer.log(
246             TAG,
247             ERROR,
248             { int1 = userId },
249             { "No Profile Owner or Device Owner supervision app found for User $int1" },
250         )
251     }
252 
logPhoneStateChangednull253     fun logPhoneStateChanged(newState: String?) {
254         logBuffer.log(TAG, DEBUG, { str1 = newState }, { "handlePhoneStateChanged($str1)" })
255     }
256 
logRegisterCallbacknull257     fun logRegisterCallback(callback: KeyguardUpdateMonitorCallback?) {
258         logBuffer.log(TAG, VERBOSE, { str1 = "$callback" }, { "*** register callback for $str1" })
259     }
260 
logRetryAfterFpErrorWithDelaynull261     fun logRetryAfterFpErrorWithDelay(msgId: Int, errString: String?, delay: Int) {
262         logBuffer.log(
263             TAG,
264             DEBUG,
265             {
266                 int1 = msgId
267                 int2 = delay
268                 str1 = "$errString"
269             },
270             { "Fingerprint scheduling retry auth after $int2 ms due to($int1) -> $str1" },
271         )
272     }
273 
logRetryAfterFpHwUnavailablenull274     fun logRetryAfterFpHwUnavailable(retryCount: Int) {
275         logBuffer.log(
276             TAG,
277             WARNING,
278             { int1 = retryCount },
279             { "Retrying fingerprint attempt: $int1" },
280         )
281     }
282 
logSendPrimaryBouncerChangednull283     fun logSendPrimaryBouncerChanged(
284         primaryBouncerIsOrWillBeShowing: Boolean,
285         primaryBouncerFullyShown: Boolean,
286     ) {
287         logBuffer.log(
288             TAG,
289             DEBUG,
290             {
291                 bool1 = primaryBouncerIsOrWillBeShowing
292                 bool2 = primaryBouncerFullyShown
293             },
294             {
295                 "sendPrimaryBouncerChanged primaryBouncerIsOrWillBeShowing=$bool1 " +
296                     "primaryBouncerFullyShown=$bool2"
297             },
298         )
299     }
300 
logServiceProvidersUpdatednull301     fun logServiceProvidersUpdated(intent: Intent) {
302         logBuffer.log(
303             TAG,
304             VERBOSE,
305             {
306                 int1 = intent.getIntExtra(EXTRA_SUBSCRIPTION_INDEX, INVALID_SUBSCRIPTION_ID)
307                 str1 = intent.getStringExtra(TelephonyManager.EXTRA_SPN)
308                 str2 = intent.getStringExtra(TelephonyManager.EXTRA_PLMN)
309             },
310             { "action SERVICE_PROVIDERS_UPDATED subId=$int1 spn=$str1 plmn=$str2" },
311         )
312     }
313 
logTimeFormatChangednull314     fun logTimeFormatChanged(newTimeFormat: String?) {
315         logBuffer.log(
316             TAG,
317             DEBUG,
318             { str1 = newTimeFormat },
319             { "handleTimeFormatUpdate timeFormat=$str1" },
320         )
321     }
322 
logUdfpsPointerDownnull323     fun logUdfpsPointerDown(sensorId: Int) {
324         logBuffer.log(TAG, DEBUG, { int1 = sensorId }, { "onUdfpsPointerDown, sensorId: $int1" })
325     }
326 
logUdfpsPointerUpnull327     fun logUdfpsPointerUp(sensorId: Int) {
328         logBuffer.log(TAG, DEBUG, { int1 = sensorId }, { "onUdfpsPointerUp, sensorId: $int1" })
329     }
330 
logUnexpectedFpCancellationSignalStatenull331     fun logUnexpectedFpCancellationSignalState(
332         fingerprintRunningState: Int,
333         unlockPossible: Boolean,
334     ) {
335         logBuffer.log(
336             TAG,
337             ERROR,
338             {
339                 int1 = fingerprintRunningState
340                 bool1 = unlockPossible
341             },
342             {
343                 "Cancellation signal is not null, high chance of bug in " +
344                     "fp auth lifecycle management. FP state: $int1, unlockPossible: $bool1"
345             },
346         )
347     }
348 
logUnregisterCallbacknull349     fun logUnregisterCallback(callback: KeyguardUpdateMonitorCallback?) {
350         logBuffer.log(TAG, VERBOSE, { str1 = "$callback" }, { "*** unregister callback for $str1" })
351     }
352 
logUserRequestedUnlocknull353     fun logUserRequestedUnlock(
354         requestOrigin: ActiveUnlockConfig.ActiveUnlockRequestOrigin,
355         reason: String?,
356         dismissKeyguard: Boolean,
357     ) {
358         logBuffer.log(
359             "ActiveUnlock",
360             DEBUG,
361             {
362                 str1 = requestOrigin?.name
363                 str2 = reason
364                 bool1 = dismissKeyguard
365             },
366             { "reportUserRequestedUnlock origin=$str1 reason=$str2 dismissKeyguard=$bool1" },
367         )
368     }
369 
logTrustGrantedWithFlagsnull370     fun logTrustGrantedWithFlags(
371         flags: Int,
372         newlyUnlocked: Boolean,
373         userId: Int,
374         message: String?,
375     ) {
376         logBuffer.log(
377             TAG,
378             DEBUG,
379             {
380                 int1 = flags
381                 bool1 = newlyUnlocked
382                 int2 = userId
383                 str1 = message
384             },
385             {
386                 "trustGrantedWithFlags[user=$int2] newlyUnlocked=$bool1 " +
387                     "flags=${TrustGrantFlags(int1)} message=$str1"
388             },
389         )
390     }
391 
logTrustChangednull392     fun logTrustChanged(wasTrusted: Boolean, isNowTrusted: Boolean, userId: Int) {
393         logBuffer.log(
394             TAG,
395             DEBUG,
396             {
397                 bool1 = wasTrusted
398                 bool2 = isNowTrusted
399                 int1 = userId
400             },
401             { "onTrustChanged[user=$int1] wasTrusted=$bool1 isNowTrusted=$bool2" },
402         )
403     }
404 
logKeyguardStateUpdatenull405     fun logKeyguardStateUpdate(
406         secure: Boolean,
407         canDismissLockScreen: Boolean,
408         trusted: Boolean,
409         trustManaged: Boolean,
410     ) {
411         logBuffer.log(
412             "KeyguardState",
413             DEBUG,
414             {
415                 bool1 = secure
416                 bool2 = canDismissLockScreen
417                 bool3 = trusted
418                 bool4 = trustManaged
419             },
420             {
421                 "#update secure=$bool1 canDismissKeyguard=$bool2" +
422                     " trusted=$bool3 trustManaged=$bool4"
423             },
424         )
425     }
426 
logTaskStackChangedForAssistantnull427     fun logTaskStackChangedForAssistant(assistantVisible: Boolean) {
428         logBuffer.log(
429             TAG,
430             VERBOSE,
431             { bool1 = assistantVisible },
432             { "TaskStackChanged for ACTIVITY_TYPE_ASSISTANT, assistant visible: $bool1" },
433         )
434     }
435 
allowFingerprintOnCurrentOccludingActivityChangednull436     fun allowFingerprintOnCurrentOccludingActivityChanged(allow: Boolean) {
437         logBuffer.log(
438             TAG,
439             VERBOSE,
440             { bool1 = allow },
441             { "allowFingerprintOnCurrentOccludingActivityChanged: $bool1" },
442         )
443     }
444 
logAssistantVisiblenull445     fun logAssistantVisible(assistantVisible: Boolean) {
446         logBuffer.log(
447             TAG,
448             VERBOSE,
449             { bool1 = assistantVisible },
450             { "Updating mAssistantVisible to new value: $bool1" },
451         )
452     }
453 
logReportSuccessfulBiometricUnlocknull454     fun logReportSuccessfulBiometricUnlock(isStrongBiometric: Boolean, userId: Int) {
455         logBuffer.log(
456             TAG,
457             DEBUG,
458             {
459                 bool1 = isStrongBiometric
460                 int1 = userId
461             },
462             { "reporting successful biometric unlock: isStrongBiometric: $bool1, userId: $int1" },
463         )
464     }
465 
logHandlerHasAuthContinueMsgsnull466     fun logHandlerHasAuthContinueMsgs(action: Int) {
467         logBuffer.log(
468             TAG,
469             DEBUG,
470             { int1 = action },
471             {
472                 "MSG_BIOMETRIC_AUTHENTICATION_CONTINUE already queued up, " +
473                     "ignoring updating FP listening state to $int1"
474             },
475         )
476     }
477 
logTrustUsuallyManagedUpdatednull478     fun logTrustUsuallyManagedUpdated(
479         userId: Int,
480         oldValue: Boolean,
481         newValue: Boolean,
482         context: String,
483     ) {
484         logBuffer.log(
485             TAG,
486             DEBUG,
487             {
488                 int1 = userId
489                 bool1 = oldValue
490                 bool2 = newValue
491                 str1 = context
492             },
493             {
494                 "trustUsuallyManaged changed for " +
495                     "userId: $int1 " +
496                     "old: $bool1, " +
497                     "new: $bool2 " +
498                     "context: $str1"
499             },
500         )
501     }
502 
logHandleBatteryUpdatenull503     fun logHandleBatteryUpdate(batteryStatus: BatteryStatus?) {
504         logBuffer.log(
505             TAG,
506             DEBUG,
507             {
508                 bool1 = batteryStatus != null
509                 int1 = batteryStatus?.status ?: -1
510                 int2 = batteryStatus?.chargingStatus ?: -1
511                 long1 = (batteryStatus?.level ?: -1).toLong()
512                 long2 = (batteryStatus?.maxChargingWattage ?: -1).toLong()
513                 str1 = "${batteryStatus?.plugged ?: -1}"
514             },
515             {
516                 "handleBatteryUpdate: isNotNull: $bool1 " +
517                     "BatteryStatus{status= $int1, " +
518                     "level=$long1, " +
519                     "plugged=$str1, " +
520                     "chargingStatus=$int2, " +
521                     "maxChargingWattage= $long2}"
522             },
523         )
524     }
525 
scheduleWatchdognull526     fun scheduleWatchdog(@CompileTimeConstant watchdogType: String) {
527         logBuffer.log(TAG, DEBUG, "Scheduling biometric watchdog for $watchdogType")
528     }
529 
notifyAboutEnrollmentsChangednull530     fun notifyAboutEnrollmentsChanged(biometricSourceType: BiometricSourceType) {
531         logBuffer.log(
532             TAG,
533             DEBUG,
534             { str1 = "$biometricSourceType" },
535             { "notifying about enrollments changed: $str1" },
536         )
537     }
538 
logUserSwitchingnull539     fun logUserSwitching(userId: Int, context: String) {
540         logBuffer.log(
541             TAG,
542             DEBUG,
543             {
544                 int1 = userId
545                 str1 = context
546             },
547             { "userCurrentlySwitching: $str1, userId: $int1" },
548         )
549     }
550 
logUserSwitchCompletenull551     fun logUserSwitchComplete(userId: Int, context: String) {
552         logBuffer.log(
553             TAG,
554             DEBUG,
555             {
556                 int1 = userId
557                 str1 = context
558             },
559             { "userSwitchComplete: $str1, userId: $int1" },
560         )
561     }
562 
logFingerprintAcquirednull563     fun logFingerprintAcquired(acquireInfo: Int) {
564         logBuffer.log(
565             FP_LOG_TAG,
566             DEBUG,
567             { int1 = acquireInfo },
568             { "fingerprint acquire message: $int1" },
569         )
570     }
571 
logForceIsDismissibleKeyguardnull572     fun logForceIsDismissibleKeyguard(keepUnlocked: Boolean) {
573         logBuffer.log(
574             TAG,
575             DEBUG,
576             { bool1 = keepUnlocked },
577             { "keepUnlockedOnFold changed to: $bool1" },
578         )
579     }
580 
logUserUnlockednull581     fun logUserUnlocked(userId: Int) {
582         logBuffer.log(TAG, DEBUG, { int1 = userId }, { "userUnlocked userId: $int1" })
583     }
584 
logUserStoppednull585     fun logUserStopped(userId: Int, isUnlocked: Boolean) {
586         logBuffer.log(
587             TAG,
588             DEBUG,
589             {
590                 int1 = userId
591                 bool1 = isUnlocked
592             },
593             { "userStopped userId: $int1 isUnlocked: $bool1" },
594         )
595     }
596 
logUserRemovednull597     fun logUserRemoved(userId: Int) {
598         logBuffer.log(TAG, DEBUG, { int1 = userId }, { "userRemoved userId: $int1" })
599     }
600 
logUserUnlockedInitialStatenull601     fun logUserUnlockedInitialState(userId: Int, isUnlocked: Boolean) {
602         logBuffer.log(
603             TAG,
604             DEBUG,
605             {
606                 int1 = userId
607                 bool1 = isUnlocked
608             },
609             { "userUnlockedInitialState userId: $int1 isUnlocked: $bool1" },
610         )
611     }
612 }
613