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.hardware.biometrics.BiometricSourceType 20 import com.android.systemui.dagger.SysUISingleton 21 import com.android.systemui.log.LogBuffer 22 import com.android.systemui.log.core.LogLevel 23 import com.android.systemui.log.core.LogLevel.DEBUG 24 import com.android.systemui.log.core.LogLevel.INFO 25 import com.android.systemui.log.dagger.BiometricLog 26 import com.android.systemui.statusbar.phone.BiometricUnlockController.MODE_DISMISS_BOUNCER 27 import com.android.systemui.statusbar.phone.BiometricUnlockController.MODE_NONE 28 import com.android.systemui.statusbar.phone.BiometricUnlockController.MODE_ONLY_WAKE 29 import com.android.systemui.statusbar.phone.BiometricUnlockController.MODE_SHOW_BOUNCER 30 import com.android.systemui.statusbar.phone.BiometricUnlockController.MODE_UNLOCK_COLLAPSING 31 import com.android.systemui.statusbar.phone.BiometricUnlockController.MODE_WAKE_AND_UNLOCK 32 import com.android.systemui.statusbar.phone.BiometricUnlockController.MODE_WAKE_AND_UNLOCK_FROM_DREAM 33 import com.android.systemui.statusbar.phone.BiometricUnlockController.MODE_WAKE_AND_UNLOCK_PULSING 34 import com.google.errorprone.annotations.CompileTimeConstant 35 import javax.inject.Inject 36 37 private const val TAG = "BiometricUnlockLogger" 38 39 /** Helper class for logging for [com.android.systemui.statusbar.phone.BiometricUnlockController] */ 40 @SysUISingleton 41 class BiometricUnlockLogger @Inject constructor(@BiometricLog private val logBuffer: LogBuffer) { 42 fun i(@CompileTimeConstant msg: String) = log(msg, INFO) 43 fun d(@CompileTimeConstant msg: String) = log(msg, DEBUG) 44 fun log(@CompileTimeConstant msg: String, level: LogLevel) = logBuffer.log(TAG, level, msg) 45 46 fun logStartWakeAndUnlock(mode: Int) { 47 logBuffer.log( 48 TAG, 49 DEBUG, 50 { int1 = mode }, 51 { "startWakeAndUnlock(${wakeAndUnlockModeToString(int1)})" } 52 ) 53 } 54 55 fun logUdfpsAttemptThresholdMet(consecutiveFailedAttempts: Int) { 56 logBuffer.log( 57 TAG, 58 DEBUG, 59 { int1 = consecutiveFailedAttempts }, 60 { "udfpsAttemptThresholdMet consecutiveFailedAttempts=$int1" } 61 ) 62 } 63 64 fun logCalculateModeForFingerprintUnlockingAllowed( 65 deviceInteractive: Boolean, 66 keyguardShowing: Boolean, 67 deviceDreaming: Boolean 68 ) { 69 logBuffer.log( 70 TAG, 71 DEBUG, 72 { 73 bool1 = deviceInteractive 74 bool2 = keyguardShowing 75 bool3 = deviceDreaming 76 }, 77 { 78 "calculateModeForFingerprint unlockingAllowed=true" + 79 " deviceInteractive=$bool1 isKeyguardShowing=$bool2" + 80 " deviceDreaming=$bool3" 81 } 82 ) 83 } 84 85 fun logCalculateModeForFingerprintUnlockingNotAllowed( 86 strongBiometric: Boolean, 87 strongAuthFlags: Int, 88 nonStrongBiometricAllowed: Boolean, 89 deviceInteractive: Boolean, 90 keyguardShowing: Boolean 91 ) { 92 logBuffer.log( 93 TAG, 94 DEBUG, 95 { 96 int1 = strongAuthFlags 97 bool1 = strongBiometric 98 bool2 = nonStrongBiometricAllowed 99 bool3 = deviceInteractive 100 bool4 = keyguardShowing 101 }, 102 { 103 "calculateModeForFingerprint unlockingAllowed=false" + 104 " strongBiometric=$bool1 strongAuthFlags=$int1" + 105 " nonStrongBiometricAllowed=$bool2" + 106 " deviceInteractive=$bool3 isKeyguardShowing=$bool4" 107 } 108 ) 109 } 110 111 fun logCalculateModeForPassiveAuthUnlockingAllowed( 112 deviceInteractive: Boolean, 113 keyguardShowing: Boolean, 114 deviceDreaming: Boolean, 115 bypass: Boolean 116 ) { 117 logBuffer.log( 118 TAG, 119 DEBUG, 120 { 121 bool1 = deviceInteractive 122 bool2 = keyguardShowing 123 bool3 = deviceDreaming 124 bool4 = bypass 125 }, 126 { 127 "calculateModeForPassiveAuth unlockingAllowed=true" + 128 " deviceInteractive=$bool1 isKeyguardShowing=$bool2" + 129 " deviceDreaming=$bool3 bypass=$bool4" 130 } 131 ) 132 } 133 134 fun logCalculateModeForPassiveAuthUnlockingNotAllowed( 135 strongBiometric: Boolean, 136 strongAuthFlags: Int, 137 nonStrongBiometricAllowed: Boolean, 138 deviceInteractive: Boolean, 139 keyguardShowing: Boolean, 140 bypass: Boolean 141 ) { 142 logBuffer.log( 143 TAG, 144 DEBUG, 145 { 146 int1 = if (strongBiometric) 1 else 0 147 int2 = strongAuthFlags 148 bool1 = nonStrongBiometricAllowed 149 bool2 = deviceInteractive 150 bool3 = keyguardShowing 151 bool4 = bypass 152 }, 153 { 154 "calculateModeForPassiveAuth unlockingAllowed=false" + 155 " strongBiometric=${int1 == 1}" + 156 " strongAuthFlags=$int2 nonStrongBiometricAllowed=$bool1" + 157 " deviceInteractive=$bool2 isKeyguardShowing=$bool3 bypass=$bool4" 158 } 159 ) 160 } 161 162 fun deferringAuthenticationDueToSleep( 163 userId: Int, 164 biometricSourceType: BiometricSourceType, 165 alreadyPendingAuth: Boolean 166 ) { 167 logBuffer.log( 168 TAG, 169 DEBUG, 170 { 171 int1 = userId 172 str1 = biometricSourceType.name 173 bool2 = alreadyPendingAuth 174 }, 175 { 176 "onBiometricAuthenticated, deferring auth: userId: $int1, " + 177 "biometricSourceType: $str1, " + 178 "goingToSleep: true, " + 179 "mPendingAuthentication != null: $bool2" 180 } 181 ) 182 } 183 184 fun finishedGoingToSleepWithPendingAuth() { 185 logBuffer.log( 186 TAG, 187 LogLevel.DEBUG, 188 "onFinishedGoingToSleep with pendingAuthenticated != null" 189 ) 190 } 191 } 192 193 private fun wakeAndUnlockModeToString(mode: Int): String { 194 return when (mode) { 195 MODE_NONE -> "MODE_NONE" 196 MODE_WAKE_AND_UNLOCK -> "MODE_WAKE_AND_UNLOCK" 197 MODE_WAKE_AND_UNLOCK_PULSING -> "MODE_WAKE_AND_UNLOCK_PULSING" 198 MODE_SHOW_BOUNCER -> "MODE_SHOW_BOUNCER" 199 MODE_ONLY_WAKE -> "MODE_ONLY_WAKE" 200 MODE_UNLOCK_COLLAPSING -> "MODE_UNLOCK_COLLAPSING" 201 MODE_WAKE_AND_UNLOCK_FROM_DREAM -> "MODE_WAKE_AND_UNLOCK_FROM_DREAM" 202 MODE_DISMISS_BOUNCER -> "MODE_DISMISS_BOUNCER" 203 else -> "UNKNOWN{$mode}" 204 } 205 } 206