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.systemui.biometrics
18 
19 import android.content.Context
20 import android.hardware.biometrics.BiometricAuthenticator.Modality
21 import android.hardware.biometrics.BiometricAuthenticator.TYPE_FACE
22 import android.hardware.biometrics.BiometricConstants
23 import android.hardware.face.FaceManager
24 import android.util.AttributeSet
25 import com.android.systemui.R
26 
27 /** Face/Fingerprint combined view for BiometricPrompt. */
28 class AuthBiometricFingerprintAndFaceView(
29     context: Context,
30     attrs: AttributeSet?
31 ) : AuthBiometricFingerprintView(context, attrs) {
32     var isFaceClass3 = false
33 
34     constructor (context: Context) : this(context, null)
35 
36     override fun getConfirmationPrompt() = R.string.biometric_dialog_tap_confirm_with_face
37 
38     override fun forceRequireConfirmation(@Modality modality: Int) = modality == TYPE_FACE
39 
40     override fun ignoreUnsuccessfulEventsFrom(@Modality modality: Int, unsuccessfulReason: String) =
41         modality == TYPE_FACE && !(isFaceClass3 && isLockoutErrorString(unsuccessfulReason))
42 
43     override fun createIconController(): AuthIconController =
44         AuthBiometricFingerprintAndFaceIconController(mContext, mIconView, mIconViewOverlay)
45 
46     override fun isCoex() = true
47 
48     private fun isLockoutErrorString(unsuccessfulReason: String) =
49         unsuccessfulReason == FaceManager.getErrorString(
50             mContext,
51             BiometricConstants.BIOMETRIC_ERROR_LOCKOUT,
52             0 /*vendorCode */
53         ) || unsuccessfulReason == FaceManager.getErrorString(
54             mContext,
55             BiometricConstants.BIOMETRIC_ERROR_LOCKOUT_PERMANENT,
56             0 /*vendorCode */
57         )
58 }
59