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.keyguard.FaceAuthUiEvent 20 import com.android.systemui.keyguard.shared.model.FaceAuthenticationStatus 21 import com.android.systemui.keyguard.shared.model.FaceDetectionStatus 22 import kotlinx.coroutines.flow.Flow 23 import kotlinx.coroutines.flow.MutableStateFlow 24 import kotlinx.coroutines.flow.StateFlow 25 import kotlinx.coroutines.flow.asStateFlow 26 import kotlinx.coroutines.flow.filterNotNull 27 28 class FakeDeviceEntryFaceAuthRepository : DeviceEntryFaceAuthRepository { 29 30 private var _wasDisabled: Boolean = false 31 32 val wasDisabled: Boolean 33 get() = _wasDisabled 34 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() 40 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() 46 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) 60 override fun lockoutFaceAuth() { 61 _wasDisabled = true 62 } 63 64 private val faceAuthPaused = MutableStateFlow(false) 65 override fun pauseFaceAuth() { 66 faceAuthPaused.value = true 67 } 68 69 override fun resumeFaceAuth() { 70 faceAuthPaused.value = false 71 } 72 73 fun isFaceAuthPaused(): Boolean { 74 return faceAuthPaused.value 75 } 76 77 override suspend fun authenticate(uiEvent: FaceAuthUiEvent, fallbackToDetection: Boolean) { 78 _runningAuthRequest.value = uiEvent to fallbackToDetection 79 _isAuthRunning.value = true 80 } 81 82 fun setLockedOut(value: Boolean) { 83 _isLockedOut.value = value 84 } 85 86 override fun cancel() { 87 _isAuthRunning.value = false 88 _runningAuthRequest.value = null 89 } 90 } 91