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.domain.interactor
18 
19 import com.android.systemui.keyguard.shared.model.FaceAuthenticationStatus
20 import com.android.systemui.keyguard.shared.model.FaceDetectionStatus
21 import kotlinx.coroutines.flow.Flow
22 
23 /**
24  * Interactor that exposes API to get the face authentication status and handle any events that can
25  * cause face authentication to run.
26  */
27 interface KeyguardFaceAuthInteractor {
28 
29     /** Current authentication status */
30     val authenticationStatus: Flow<FaceAuthenticationStatus>
31 
32     /** Current detection status */
33     val detectionStatus: Flow<FaceDetectionStatus>
34 
35     /** Can face auth be run right now */
36     fun canFaceAuthRun(): Boolean
37 
38     /** Whether face auth is currently running or not. */
39     fun isRunning(): Boolean
40 
41     /** Whether face auth is in lock out state. */
42     fun isLockedOut(): Boolean
43 
44     /**
45      * Register listener for use from code that cannot use [authenticationStatus] or
46      * [detectionStatus]
47      */
48     fun registerListener(listener: FaceAuthenticationListener)
49 
50     /** Unregister previously registered listener */
51     fun unregisterListener(listener: FaceAuthenticationListener)
52 
53     /** Whether the face auth interactor is enabled or not. */
54     fun isEnabled(): Boolean
55 
56     fun onUdfpsSensorTouched()
57     fun onAssistantTriggeredOnLockScreen()
58     fun onDeviceLifted()
59     fun onQsExpansionStared()
60     fun onNotificationPanelClicked()
61     fun onSwipeUpOnBouncer()
62     fun onPrimaryBouncerUserInput()
63     fun onAccessibilityAction()
64 }
65 
66 /**
67  * Listener that can be registered with the [KeyguardFaceAuthInteractor] to receive updates about
68  * face authentication & detection updates.
69  *
70  * This is present to make it easier for use the new face auth API for code that cannot use
71  * [KeyguardFaceAuthInteractor.authenticationStatus] or [KeyguardFaceAuthInteractor.detectionStatus]
72  * flows.
73  */
74 interface FaceAuthenticationListener {
75     /** Receive face authentication status updates */
76     fun onAuthenticationStatusChanged(status: FaceAuthenticationStatus)
77 
78     /** Receive status updates whenever face detection runs */
79     fun onDetectionStatusChanged(status: FaceDetectionStatus)
80 }
81