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 
18 package com.android.systemui.keyguard.data.repository
19 
20 import com.android.systemui.dagger.SysUISingleton
21 import com.android.systemui.keyguard.shared.model.FingerprintAuthenticationStatus
22 import dagger.Binds
23 import dagger.Module
24 import javax.inject.Inject
25 import kotlinx.coroutines.flow.Flow
26 import kotlinx.coroutines.flow.MutableStateFlow
27 import kotlinx.coroutines.flow.StateFlow
28 import kotlinx.coroutines.flow.asStateFlow
29 import kotlinx.coroutines.flow.filterNotNull
30 
31 @SysUISingleton
32 class FakeDeviceEntryFingerprintAuthRepository @Inject constructor() :
33     DeviceEntryFingerprintAuthRepository {
34     private val _isLockedOut = MutableStateFlow(false)
35     override val isLockedOut: StateFlow<Boolean> = _isLockedOut.asStateFlow()
setLockedOutnull36     fun setLockedOut(lockedOut: Boolean) {
37         _isLockedOut.value = lockedOut
38     }
39 
40     private val _isRunning = MutableStateFlow(false)
41     override val isRunning: Flow<Boolean>
42         get() = _isRunning
43 
44     override val isEngaged: MutableStateFlow<Boolean> = MutableStateFlow(false)
45 
setIsRunningnull46     fun setIsRunning(value: Boolean) {
47         _isRunning.value = value
48     }
49 
50     private var fpSensorType = MutableStateFlow<BiometricType?>(null)
51     override val availableFpSensorType: Flow<BiometricType?>
52         get() = fpSensorType
setAvailableFpSensorTypenull53     fun setAvailableFpSensorType(value: BiometricType?) {
54         fpSensorType.value = value
55     }
56 
57     private var _authenticationStatus = MutableStateFlow<FingerprintAuthenticationStatus?>(null)
58     override val authenticationStatus: Flow<FingerprintAuthenticationStatus>
59         get() = _authenticationStatus.filterNotNull()
60 
61     private var _shouldUpdateIndicatorVisibility = MutableStateFlow(false)
62     override val shouldUpdateIndicatorVisibility: Flow<Boolean>
63         get() = _shouldUpdateIndicatorVisibility
64 
setAuthenticationStatusnull65     fun setAuthenticationStatus(status: FingerprintAuthenticationStatus) {
66         _authenticationStatus.value = status
67     }
68 
setShouldUpdateIndicatorVisibilitynull69     fun setShouldUpdateIndicatorVisibility(shouldUpdateIndicatorVisibility: Boolean) {
70         _shouldUpdateIndicatorVisibility.value = shouldUpdateIndicatorVisibility
71     }
72 }
73 
74 @Module
75 interface FakeDeviceEntryFingerprintAuthRepositoryModule {
76     @Binds
bindFakenull77     fun bindFake(
78         fake: FakeDeviceEntryFingerprintAuthRepository
79     ): DeviceEntryFingerprintAuthRepository
80 }
81