1 /* 2 * Copyright (C) 2023 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.keyguard.util 18 19 import android.hardware.biometrics.BiometricFaceConstants 20 import android.hardware.biometrics.BiometricFingerprintConstants 21 import android.hardware.biometrics.BiometricSourceType 22 import com.android.keyguard.KeyguardUpdateMonitor 23 import com.android.systemui.dagger.SysUISingleton 24 import javax.inject.Inject 25 26 @SysUISingleton 27 class IndicationHelper 28 @Inject 29 constructor( 30 val keyguardUpdateMonitor: KeyguardUpdateMonitor, 31 ) { shouldSuppressErrorMsgnull32 fun shouldSuppressErrorMsg(biometricSource: BiometricSourceType, msgId: Int): Boolean { 33 return when (biometricSource) { 34 BiometricSourceType.FINGERPRINT -> 35 (isPrimaryAuthRequired() && !isFingerprintLockoutErrorMsg(msgId)) || 36 msgId == BiometricFingerprintConstants.FINGERPRINT_ERROR_CANCELED || 37 msgId == BiometricFingerprintConstants.FINGERPRINT_ERROR_USER_CANCELED || 38 msgId == BiometricFingerprintConstants.BIOMETRIC_ERROR_POWER_PRESSED 39 BiometricSourceType.FACE -> 40 (isPrimaryAuthRequired() && !isFaceLockoutErrorMsg(msgId)) || 41 msgId == BiometricFaceConstants.FACE_ERROR_CANCELED || 42 msgId == BiometricFaceConstants.FACE_ERROR_UNABLE_TO_PROCESS 43 else -> false 44 } 45 } 46 isFingerprintLockoutErrorMsgnull47 private fun isFingerprintLockoutErrorMsg(msgId: Int): Boolean { 48 return msgId == BiometricFingerprintConstants.FINGERPRINT_ERROR_LOCKOUT || 49 msgId == BiometricFingerprintConstants.FINGERPRINT_ERROR_LOCKOUT_PERMANENT 50 } 51 isFaceLockoutErrorMsgnull52 fun isFaceLockoutErrorMsg(msgId: Int): Boolean { 53 return msgId == BiometricFaceConstants.FACE_ERROR_LOCKOUT || 54 msgId == BiometricFaceConstants.FACE_ERROR_LOCKOUT_PERMANENT 55 } 56 isPrimaryAuthRequirednull57 private fun isPrimaryAuthRequired(): Boolean { 58 // Only checking if unlocking with Biometric is allowed (no matter strong or non-strong 59 // as long as primary auth, i.e. PIN/pattern/password, is required), so it's ok to 60 // pass true for isStrongBiometric to isUnlockingWithBiometricAllowed() to bypass the 61 // check of whether non-strong biometric is allowed since strong biometrics can still be 62 // used. 63 return !keyguardUpdateMonitor.isUnlockingWithBiometricAllowed(true /* isStrongBiometric */) 64 } 65 } 66