1 /*
2  * Copyright (C) 2022 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.keyguard.TrustGrantFlags
21 import com.android.systemui.dagger.SysUISingleton
22 import com.android.systemui.keyguard.shared.model.TrustModel
23 import dagger.Binds
24 import dagger.Module
25 import javax.inject.Inject
26 import kotlinx.coroutines.flow.Flow
27 import kotlinx.coroutines.flow.MutableStateFlow
28 import kotlinx.coroutines.flow.StateFlow
29 import kotlinx.coroutines.flow.asStateFlow
30 
31 @SysUISingleton
32 class FakeTrustRepository @Inject constructor() : TrustRepository {
33     private val _isTrustUsuallyManaged = MutableStateFlow(false)
34     override val isCurrentUserTrustUsuallyManaged: StateFlow<Boolean>
35         get() = _isTrustUsuallyManaged
36     private val _isCurrentUserTrusted = MutableStateFlow(false)
37     override val isCurrentUserTrusted: Flow<Boolean>
38         get() = _isCurrentUserTrusted
39 
40     private val _isCurrentUserActiveUnlockAvailable = MutableStateFlow(false)
41     override val isCurrentUserActiveUnlockRunning: StateFlow<Boolean> =
42         _isCurrentUserActiveUnlockAvailable.asStateFlow()
43 
44     private val _isCurrentUserTrustManaged = MutableStateFlow(false)
45     override val isCurrentUserTrustManaged: StateFlow<Boolean>
46         get() = _isCurrentUserTrustManaged
47 
48     private val _requestDismissKeyguard = MutableStateFlow(TrustModel(false, 0, TrustGrantFlags(0)))
49     override val trustAgentRequestingToDismissKeyguard: Flow<TrustModel> = _requestDismissKeyguard
50 
setCurrentUserTrustednull51     fun setCurrentUserTrusted(trust: Boolean) {
52         _isCurrentUserTrusted.value = trust
53     }
54 
setCurrentUserTrustManagednull55     fun setCurrentUserTrustManaged(value: Boolean) {
56         _isCurrentUserTrustManaged.value = value
57     }
58 
setCurrentUserActiveUnlockAvailablenull59     fun setCurrentUserActiveUnlockAvailable(available: Boolean) {
60         _isCurrentUserActiveUnlockAvailable.value = available
61     }
62 
setRequestDismissKeyguardnull63     fun setRequestDismissKeyguard(trustModel: TrustModel) {
64         _requestDismissKeyguard.value = trustModel
65     }
66 
setTrustUsuallyManagednull67     fun setTrustUsuallyManaged(value: Boolean) {
68         _isTrustUsuallyManaged.value = value
69     }
70 }
71 
72 @Module
73 interface FakeTrustRepositoryModule {
bindFakenull74     @Binds fun bindFake(fake: FakeTrustRepository): TrustRepository
75 }
76