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.fingerprint.FingerprintManager
20 import android.os.SystemClock.elapsedRealtime
21 
22 /**
23  * Fingerprint authentication status provided by
24  * [com.android.systemui.keyguard.data.repository.DeviceEntryFingerprintAuthRepository]
25  */
26 sealed class FingerprintAuthenticationStatus
27 
28 /** Fingerprint authentication success status. */
29 data class SuccessFingerprintAuthenticationStatus(
30     val userId: Int,
31     val isStrongBiometric: Boolean,
32 ) : FingerprintAuthenticationStatus()
33 
34 /** Fingerprint authentication help message. */
35 data class HelpFingerprintAuthenticationStatus(
36     val msgId: Int,
37     val msg: String?,
38 ) : FingerprintAuthenticationStatus()
39 
40 /** Fingerprint acquired message. */
41 data class AcquiredFingerprintAuthenticationStatus(val acquiredInfo: Int) :
42     FingerprintAuthenticationStatus()
43 
44 /** Fingerprint authentication failed message. */
45 object FailFingerprintAuthenticationStatus : FingerprintAuthenticationStatus()
46 
47 /** Fingerprint authentication error message */
48 data class ErrorFingerprintAuthenticationStatus(
49     val msgId: Int,
50     val msg: String? = null,
51     // present to break equality check if the same error occurs repeatedly.
52     val createdAt: Long = elapsedRealtime(),
53 ) : FingerprintAuthenticationStatus() {
54     fun isLockoutMessage(): Boolean {
55         return msgId == FingerprintManager.FINGERPRINT_ERROR_LOCKOUT ||
56             msgId == FingerprintManager.FINGERPRINT_ERROR_LOCKOUT_PERMANENT
57     }
58 }
59