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.biometrics.ui.viewmodel 18 19 import com.android.systemui.biometrics.shared.model.BiometricModality 20 21 /** 22 * The authenticated state with the [authenticatedModality] (when [isAuthenticated]) with an 23 * optional [delay] to keep the UI showing before dismissing when [needsUserConfirmation] is not 24 * required. 25 */ 26 data class PromptAuthState( 27 val isAuthenticated: Boolean, 28 val authenticatedModality: BiometricModality = BiometricModality.None, 29 val needsUserConfirmation: Boolean = false, 30 val delay: Long = 0, 31 ) { 32 private var wasConfirmed = false 33 34 /** If authentication was successful and the user has confirmed (or does not need to). */ 35 val isAuthenticatedAndConfirmed: Boolean 36 get() = isAuthenticated && !needsUserConfirmation 37 38 /** Same as [isAuthenticatedAndConfirmed] but only true if the user clicked a confirm button. */ 39 val isAuthenticatedAndExplicitlyConfirmed: Boolean 40 get() = isAuthenticated && wasConfirmed 41 42 /** If a successful authentication has not occurred. */ 43 val isNotAuthenticated: Boolean 44 get() = !isAuthenticated 45 46 /** If a authentication has succeeded and it was done by face (may need confirmation). */ 47 val isAuthenticatedByFace: Boolean 48 get() = isAuthenticated && authenticatedModality == BiometricModality.Face 49 50 /** If a authentication has succeeded and it was done by fingerprint (may need confirmation). */ 51 val isAuthenticatedByFingerprint: Boolean 52 get() = isAuthenticated && authenticatedModality == BiometricModality.Fingerprint 53 54 /** 55 * Copies this state, but toggles [needsUserConfirmation] to false and ensures that 56 * [isAuthenticatedAndExplicitlyConfirmed] is true. 57 */ asExplicitlyConfirmednull58 fun asExplicitlyConfirmed(): PromptAuthState = 59 PromptAuthState( 60 isAuthenticated = isAuthenticated, 61 authenticatedModality = authenticatedModality, 62 needsUserConfirmation = false, 63 delay = delay, 64 ) 65 .apply { wasConfirmed = true } 66 } 67