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