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.data.repository
18 
19 import com.android.systemui.dagger.SysUISingleton
20 import com.android.systemui.deviceentry.data.repository.DeviceEntryFaceAuthRepository
21 import com.android.systemui.deviceentry.shared.FaceAuthUiEvent
22 import com.android.systemui.deviceentry.shared.model.FaceAuthenticationStatus
23 import com.android.systemui.deviceentry.shared.model.FaceDetectionStatus
24 import dagger.Binds
25 import dagger.Module
26 import javax.inject.Inject
27 import kotlinx.coroutines.flow.Flow
28 import kotlinx.coroutines.flow.MutableStateFlow
29 import kotlinx.coroutines.flow.StateFlow
30 import kotlinx.coroutines.flow.asStateFlow
31 import kotlinx.coroutines.flow.filterNotNull
32 
33 @SysUISingleton
34 class FakeDeviceEntryFaceAuthRepository @Inject constructor() : DeviceEntryFaceAuthRepository {
35     override val isAuthenticated = MutableStateFlow(false)
36     override val canRunFaceAuth = MutableStateFlow(false)
37     private val _authenticationStatus = MutableStateFlow<FaceAuthenticationStatus?>(null)
38     override val authenticationStatus: Flow<FaceAuthenticationStatus> =
39         _authenticationStatus.filterNotNull()
setAuthenticationStatusnull40     fun setAuthenticationStatus(status: FaceAuthenticationStatus) {
41         _authenticationStatus.value = status
42     }
43     private val _detectionStatus = MutableStateFlow<FaceDetectionStatus?>(null)
44     override val detectionStatus: Flow<FaceDetectionStatus>
45         get() = _detectionStatus.filterNotNull()
setDetectionStatusnull46     fun setDetectionStatus(status: FaceDetectionStatus) {
47         _detectionStatus.value = status
48     }
49 
50     private val _isLockedOut = MutableStateFlow(false)
51     override val isLockedOut = _isLockedOut
52     private val _runningAuthRequest = MutableStateFlow<Pair<FaceAuthUiEvent, Boolean>?>(null)
53     val runningAuthRequest: StateFlow<Pair<FaceAuthUiEvent, Boolean>?> =
54         _runningAuthRequest.asStateFlow()
55 
56     private val _isAuthRunning = MutableStateFlow(false)
57     override val isAuthRunning: StateFlow<Boolean> = _isAuthRunning
58 
59     override val isBypassEnabled = MutableStateFlow(false)
setLockedOutnull60     override fun setLockedOut(isLockedOut: Boolean) {
61         _isLockedOut.value = isLockedOut
62     }
63 
requestAuthenticatenull64     override fun requestAuthenticate(uiEvent: FaceAuthUiEvent, fallbackToDetection: Boolean) {
65         _runningAuthRequest.value = uiEvent to fallbackToDetection
66         _isAuthRunning.value = true
67     }
68 
cancelnull69     override fun cancel() {
70         _isAuthRunning.value = false
71         _runningAuthRequest.value = null
72     }
73 }
74 
75 @Module
76 interface FakeDeviceEntryFaceAuthRepositoryModule {
bindFakenull77     @Binds fun bindFake(fake: FakeDeviceEntryFaceAuthRepository): DeviceEntryFaceAuthRepository
78 }
79