• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.deviceentry.shared.model
18 
19 import android.hardware.biometrics.BiometricFaceConstants.FACE_ERROR_CANCELED
20 import android.hardware.biometrics.BiometricFaceConstants.FACE_ERROR_HW_UNAVAILABLE
21 import android.hardware.biometrics.BiometricFaceConstants.FACE_ERROR_LOCKOUT
22 import android.hardware.biometrics.BiometricFaceConstants.FACE_ERROR_LOCKOUT_PERMANENT
23 import android.hardware.biometrics.BiometricFaceConstants.FACE_ERROR_TIMEOUT
24 import android.hardware.biometrics.BiometricFaceConstants.FACE_ERROR_UNABLE_TO_PROCESS
25 import android.hardware.face.FaceManager
26 import android.os.SystemClock.elapsedRealtime
27 
28 /**
29  * Authentication status provided by
30  * [com.android.systemui.deviceentry.data.repository.DeviceEntryFaceAuthRepository]
31  */
32 sealed class FaceAuthenticationStatus
33 
34 /** Success authentication status. */
35 data class SuccessFaceAuthenticationStatus(
36     val successResult: FaceManager.AuthenticationResult,
37     // present to break equality check if the same error occurs repeatedly.
38     @JvmField val createdAt: Long = elapsedRealtime()
39 ) : FaceAuthenticationStatus()
40 
41 /** Face authentication help message. */
42 data class HelpFaceAuthenticationStatus(
43     val msgId: Int,
44     val msg: String?, // present to break equality check if the same error occurs repeatedly.
45     @JvmField val createdAt: Long = elapsedRealtime()
46 ) : FaceAuthenticationStatus()
47 
48 /** Face acquired message. */
49 data class AcquiredFaceAuthenticationStatus(
50     val acquiredInfo: Int, // present to break equality check if the same error occurs repeatedly.
51     @JvmField val createdAt: Long = elapsedRealtime()
52 ) : FaceAuthenticationStatus()
53 
54 /** Face authentication failed message. */
55 data class FailedFaceAuthenticationStatus(
56     // present to break equality check if the same error occurs repeatedly.
57     @JvmField val createdAt: Long = elapsedRealtime()
58 ) : FaceAuthenticationStatus()
59 
60 /** Face authentication error message */
61 data class ErrorFaceAuthenticationStatus(
62     val msgId: Int,
63     val msg: String? = null,
64     // present to break equality check if the same error occurs repeatedly.
65     @JvmField val createdAt: Long = elapsedRealtime()
66 ) : FaceAuthenticationStatus() {
67     /**
68      * Method that checks if [msgId] is a lockout error. A lockout error means that face
69      * authentication is locked out.
70      */
isLockoutErrornull71     fun isLockoutError() = msgId == FACE_ERROR_LOCKOUT_PERMANENT || msgId == FACE_ERROR_LOCKOUT
72 
73     /**
74      * Method that checks if [msgId] is a cancellation error. This means that face authentication
75      * was cancelled before it completed.
76      */
77     fun isCancellationError() = msgId == FACE_ERROR_CANCELED
78 
79     fun isUnableToProcessError() = msgId == FACE_ERROR_UNABLE_TO_PROCESS
80 
81     /** Method that checks if [msgId] is a hardware error. */
82     fun isHardwareError() =
83         msgId == FACE_ERROR_HW_UNAVAILABLE || msgId == FACE_ERROR_UNABLE_TO_PROCESS
84 
85     /** Method that checks if [msgId] is a timeout error. */
86     fun isTimeoutError() = msgId == FACE_ERROR_TIMEOUT
87 
88     companion object {
89         /**
90          * Error message that is created when cancel confirmation is not received from FaceManager
91          * after we request for a cancellation of face auth.
92          */
93         fun cancelNotReceivedError() = ErrorFaceAuthenticationStatus(-1, "")
94     }
95 }
96 
97 /** Face detection success message. */
98 data class FaceDetectionStatus(
99     val sensorId: Int,
100     val userId: Int,
101     val isStrongBiometric: Boolean,
102     // present to break equality check if the same error occurs repeatedly.
103     @JvmField val createdAt: Long = elapsedRealtime()
104 )
105