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.filterNotNull 31 32 @SysUISingleton 33 class FakeDeviceEntryFaceAuthRepository @Inject constructor() : DeviceEntryFaceAuthRepository { 34 override val isAuthenticated = MutableStateFlow(false) 35 override val canRunFaceAuth = MutableStateFlow(false) 36 private val _authenticationStatus = MutableStateFlow<FaceAuthenticationStatus?>(null) 37 override val authenticationStatus: Flow<FaceAuthenticationStatus> = 38 _authenticationStatus.filterNotNull() 39 setAuthenticationStatusnull40 fun setAuthenticationStatus(status: FaceAuthenticationStatus) { 41 _authenticationStatus.value = status 42 } 43 44 private val _detectionStatus = MutableStateFlow<FaceDetectionStatus?>(null) 45 override val detectionStatus: Flow<FaceDetectionStatus> 46 get() = _detectionStatus.filterNotNull() 47 setDetectionStatusnull48 fun setDetectionStatus(status: FaceDetectionStatus) { 49 _detectionStatus.value = status 50 } 51 52 private val _isLockedOut = MutableStateFlow(false) 53 override val isLockedOut = _isLockedOut 54 val runningAuthRequest: MutableStateFlow<Pair<FaceAuthUiEvent, Boolean>?> = 55 MutableStateFlow(null) 56 57 private val _isAuthRunning = MutableStateFlow(false) 58 override val isAuthRunning: StateFlow<Boolean> = _isAuthRunning 59 60 override val isBypassEnabled = MutableStateFlow(false) 61 setLockedOutnull62 override fun setLockedOut(isLockedOut: Boolean) { 63 _isLockedOut.value = isLockedOut 64 } 65 requestAuthenticatenull66 override fun requestAuthenticate(uiEvent: FaceAuthUiEvent, fallbackToDetection: Boolean) { 67 runningAuthRequest.value = uiEvent to fallbackToDetection 68 _isAuthRunning.value = true 69 } 70 cancelnull71 override fun cancel() { 72 _isAuthRunning.value = false 73 runningAuthRequest.value = null 74 } 75 } 76 77 @Module 78 interface FakeDeviceEntryFaceAuthRepositoryModule { bindFakenull79 @Binds fun bindFake(fake: FakeDeviceEntryFaceAuthRepository): DeviceEntryFaceAuthRepository 80 } 81