1 /* 2 * Copyright (C) 2024 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.domain.interactor 18 19 import com.android.systemui.CoreStartable 20 import com.android.systemui.deviceentry.shared.model.FaceAuthenticationStatus 21 import com.android.systemui.deviceentry.shared.model.FaceDetectionStatus 22 import com.android.systemui.log.table.TableLogBuffer 23 import kotlinx.coroutines.flow.Flow 24 import kotlinx.coroutines.flow.StateFlow 25 26 /** 27 * Interactor that exposes API to get the face authentication status and handle any events that can 28 * cause face authentication to run for device entry. 29 */ 30 interface DeviceEntryFaceAuthInteractor : CoreStartable { 31 32 /** Current authentication status */ 33 val authenticationStatus: Flow<FaceAuthenticationStatus> 34 35 /** Current detection status */ 36 val detectionStatus: Flow<FaceDetectionStatus> 37 38 val isLockedOut: StateFlow<Boolean> 39 40 val isAuthenticated: StateFlow<Boolean> 41 42 /** Whether bypass is enabled. If enabled, face unlock dismisses the lock screen. */ 43 val isBypassEnabled: Flow<Boolean> 44 45 /** Can face auth be run right now */ canFaceAuthRunnull46 fun canFaceAuthRun(): Boolean 47 48 /** Whether face auth is currently running or not. */ 49 fun isRunning(): Boolean 50 51 /** Whether face auth is enrolled and enabled for the current user */ 52 fun isFaceAuthEnabledAndEnrolled(): Boolean 53 54 /** 55 * Register listener for use from code that cannot use [authenticationStatus] or 56 * [detectionStatus] 57 */ 58 fun registerListener(listener: FaceAuthenticationListener) 59 60 /** Unregister previously registered listener */ 61 fun unregisterListener(listener: FaceAuthenticationListener) 62 63 fun onUdfpsSensorTouched() 64 65 fun onAssistantTriggeredOnLockScreen() 66 67 fun onDeviceLifted() 68 69 fun onShadeExpansionStarted() 70 71 fun onNotificationPanelClicked() 72 73 fun onSwipeUpOnBouncer() 74 75 fun onPrimaryBouncerUserInput() 76 77 fun onAccessibilityAction() 78 79 fun onWalletLaunched() 80 81 fun onDeviceUnfolded() 82 83 /** Whether face auth is considered class 3 */ 84 fun isFaceAuthStrong(): Boolean 85 86 suspend fun hydrateTableLogBuffer(tableLogBuffer: TableLogBuffer) 87 } 88 89 /** 90 * Listener that can be registered with the [DeviceEntryFaceAuthInteractor] to receive updates about 91 * face authentication & detection updates. 92 * 93 * This is present to make it easier for use the new face auth API for code that cannot use 94 * [DeviceEntryFaceAuthInteractor.authenticationStatus] or 95 * [DeviceEntryFaceAuthInteractor.detectionStatus] flows. 96 */ 97 interface FaceAuthenticationListener { 98 /** Receive face isAuthenticated updates */ 99 fun onAuthenticatedChanged(isAuthenticated: Boolean) = Unit 100 101 /** Receive face authentication status updates */ 102 fun onAuthenticationStatusChanged(status: FaceAuthenticationStatus) = Unit 103 104 /** Receive status updates whenever face detection runs */ 105 fun onDetectionStatusChanged(status: FaceDetectionStatus) = Unit 106 107 fun onLockoutStateChanged(isLockedOut: Boolean) = Unit 108 109 fun onRunningStateChanged(isRunning: Boolean) = Unit 110 111 fun onAuthEnrollmentStateChanged(enrolled: Boolean) = Unit 112 } 113