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 android.graphics.Point
21 import com.android.systemui.common.shared.model.Position
22 import com.android.systemui.keyguard.shared.model.BiometricUnlockModel
23 import com.android.systemui.keyguard.shared.model.BiometricUnlockSource
24 import com.android.systemui.keyguard.shared.model.DozeTransitionModel
25 import com.android.systemui.keyguard.shared.model.KeyguardRootViewVisibilityState
26 import com.android.systemui.keyguard.shared.model.ScreenModel
27 import com.android.systemui.keyguard.shared.model.ScreenState
28 import com.android.systemui.keyguard.shared.model.StatusBarState
29 import com.android.systemui.keyguard.shared.model.WakeSleepReason
30 import com.android.systemui.keyguard.shared.model.WakefulnessModel
31 import com.android.systemui.keyguard.shared.model.WakefulnessState
32 import kotlinx.coroutines.flow.Flow
33 import kotlinx.coroutines.flow.MutableStateFlow
34 import kotlinx.coroutines.flow.StateFlow
35 import kotlinx.coroutines.flow.asStateFlow
36 
37 /** Fake implementation of [KeyguardRepository] */
38 class FakeKeyguardRepository : KeyguardRepository {
39 
40     private val _animateBottomAreaDozingTransitions = MutableStateFlow(false)
41     override val animateBottomAreaDozingTransitions: StateFlow<Boolean> =
42         _animateBottomAreaDozingTransitions
43 
44     private val _bottomAreaAlpha = MutableStateFlow(1f)
45     override val bottomAreaAlpha: StateFlow<Float> = _bottomAreaAlpha
46 
47     private val _clockPosition = MutableStateFlow(Position(0, 0))
48     override val clockPosition: StateFlow<Position> = _clockPosition
49 
50     private val _isKeyguardShowing = MutableStateFlow(false)
51     override val isKeyguardShowing: Flow<Boolean> = _isKeyguardShowing
52 
53     private val _isKeyguardUnlocked = MutableStateFlow(false)
54     override val isKeyguardUnlocked: StateFlow<Boolean> = _isKeyguardUnlocked.asStateFlow()
55 
56     private val _isKeyguardOccluded = MutableStateFlow(false)
57     override val isKeyguardOccluded: Flow<Boolean> = _isKeyguardOccluded
58 
59     private val _isDozing = MutableStateFlow(false)
60     override val isDozing: StateFlow<Boolean> = _isDozing
61 
62     private val _dozeTimeTick = MutableStateFlow<Long>(0L)
63     override val dozeTimeTick = _dozeTimeTick
64 
65     private val _lastDozeTapToWakePosition = MutableStateFlow<Point?>(null)
66     override val lastDozeTapToWakePosition = _lastDozeTapToWakePosition.asStateFlow()
67 
68     private val _isAodAvailable = MutableStateFlow(false)
69     override val isAodAvailable: Flow<Boolean> = _isAodAvailable
70 
71     private val _isDreaming = MutableStateFlow(false)
72     override val isDreaming: Flow<Boolean> = _isDreaming
73 
74     private val _isDreamingWithOverlay = MutableStateFlow(false)
75     override val isDreamingWithOverlay: Flow<Boolean> = _isDreamingWithOverlay
76 
77     private val _isActiveDreamLockscreenHosted = MutableStateFlow(false)
78     override val isActiveDreamLockscreenHosted: StateFlow<Boolean> = _isActiveDreamLockscreenHosted
79 
80     private val _dozeAmount = MutableStateFlow(0f)
81     override val linearDozeAmount: Flow<Float> = _dozeAmount
82 
83     private val _statusBarState = MutableStateFlow(StatusBarState.SHADE)
84     override val statusBarState: Flow<StatusBarState> = _statusBarState
85 
86     private val _dozeTransitionModel = MutableStateFlow(DozeTransitionModel())
87     override val dozeTransitionModel: Flow<DozeTransitionModel> = _dozeTransitionModel
88 
89     private val _wakefulnessModel =
90         MutableStateFlow(
91             WakefulnessModel(WakefulnessState.ASLEEP, WakeSleepReason.OTHER, WakeSleepReason.OTHER)
92         )
93     override val wakefulness = _wakefulnessModel
94 
95     private val _screenModel = MutableStateFlow(ScreenModel(ScreenState.SCREEN_OFF))
96     override val screenModel = _screenModel
97 
98     private val _isUdfpsSupported = MutableStateFlow(false)
99 
100     private val _isKeyguardGoingAway = MutableStateFlow(false)
101     override val isKeyguardGoingAway: Flow<Boolean> = _isKeyguardGoingAway
102 
103     private val _biometricUnlockState = MutableStateFlow(BiometricUnlockModel.NONE)
104     override val biometricUnlockState: Flow<BiometricUnlockModel> = _biometricUnlockState
105 
106     private val _fingerprintSensorLocation = MutableStateFlow<Point?>(null)
107     override val fingerprintSensorLocation: Flow<Point?> = _fingerprintSensorLocation
108 
109     private val _faceSensorLocation = MutableStateFlow<Point?>(null)
110     override val faceSensorLocation: Flow<Point?> = _faceSensorLocation
111 
112     private val _biometricUnlockSource = MutableStateFlow<BiometricUnlockSource?>(null)
113     override val biometricUnlockSource: Flow<BiometricUnlockSource?> = _biometricUnlockSource
114 
115     private val _isQuickSettingsVisible = MutableStateFlow(false)
116     override val isQuickSettingsVisible: Flow<Boolean> = _isQuickSettingsVisible.asStateFlow()
117 
118     private val _keyguardAlpha = MutableStateFlow(1f)
119     override val keyguardAlpha: StateFlow<Float> = _keyguardAlpha
120 
121     private val _keyguardRootViewVisibility =
122         MutableStateFlow(
123             KeyguardRootViewVisibilityState(
124                 0,
125                 goingToFullShade = false,
126                 occlusionTransitionRunning = false
127             )
128         )
129     override val keyguardRootViewVisibility: Flow<KeyguardRootViewVisibilityState> =
130         _keyguardRootViewVisibility.asStateFlow()
131 
132     override fun setQuickSettingsVisible(isVisible: Boolean) {
133         _isQuickSettingsVisible.value = isVisible
134     }
135 
136     override fun isKeyguardShowing(): Boolean {
137         return _isKeyguardShowing.value
138     }
139 
140     private var _isBypassEnabled = false
141     override fun isBypassEnabled(): Boolean {
142         return _isBypassEnabled
143     }
144 
145     override fun setAnimateDozingTransitions(animate: Boolean) {
146         _animateBottomAreaDozingTransitions.tryEmit(animate)
147     }
148 
149     @Deprecated("Deprecated as part of b/278057014")
150     override fun setBottomAreaAlpha(alpha: Float) {
151         _bottomAreaAlpha.value = alpha
152     }
153 
154     override fun setClockPosition(x: Int, y: Int) {
155         _clockPosition.value = Position(x, y)
156     }
157 
158     fun setKeyguardShowing(isShowing: Boolean) {
159         _isKeyguardShowing.value = isShowing
160     }
161 
162     fun setKeyguardGoingAway(isGoingAway: Boolean) {
163         _isKeyguardGoingAway.value = isGoingAway
164     }
165 
166     fun setKeyguardOccluded(isOccluded: Boolean) {
167         _isKeyguardOccluded.value = isOccluded
168     }
169 
170     override fun setIsDozing(isDozing: Boolean) {
171         _isDozing.value = isDozing
172     }
173 
174     override fun dozeTimeTick() {
175         _dozeTimeTick.value = _dozeTimeTick.value + 1
176     }
177 
178     fun dozeTimeTick(millis: Long) {
179         _dozeTimeTick.value = millis
180     }
181 
182     override fun setLastDozeTapToWakePosition(position: Point) {
183         _lastDozeTapToWakePosition.value = position
184     }
185 
186     fun setAodAvailable(isAodAvailable: Boolean) {
187         _isAodAvailable.value = isAodAvailable
188     }
189 
190     fun setDreaming(isDreaming: Boolean) {
191         _isDreaming.value = isDreaming
192     }
193 
194     fun setDreamingWithOverlay(isDreaming: Boolean) {
195         _isDreamingWithOverlay.value = isDreaming
196     }
197 
198     override fun setIsActiveDreamLockscreenHosted(isLockscreenHosted: Boolean) {
199         _isActiveDreamLockscreenHosted.value = isLockscreenHosted
200     }
201 
202     fun setDozeAmount(dozeAmount: Float) {
203         _dozeAmount.value = dozeAmount
204     }
205 
206     fun setWakefulnessModel(model: WakefulnessModel) {
207         _wakefulnessModel.value = model
208     }
209 
210     fun setBiometricUnlockState(state: BiometricUnlockModel) {
211         _biometricUnlockState.tryEmit(state)
212     }
213 
214     fun setBiometricUnlockSource(source: BiometricUnlockSource?) {
215         _biometricUnlockSource.tryEmit(source)
216     }
217 
218     fun setFaceSensorLocation(location: Point?) {
219         _faceSensorLocation.tryEmit(location)
220     }
221 
222     fun setFingerprintSensorLocation(location: Point?) {
223         _fingerprintSensorLocation.tryEmit(location)
224     }
225 
226     fun setDozeTransitionModel(model: DozeTransitionModel) {
227         _dozeTransitionModel.value = model
228     }
229 
230     fun setStatusBarState(state: StatusBarState) {
231         _statusBarState.value = state
232     }
233 
234     fun setKeyguardUnlocked(isUnlocked: Boolean) {
235         _isKeyguardUnlocked.value = isUnlocked
236     }
237 
238     fun setBypassEnabled(isEnabled: Boolean) {
239         _isBypassEnabled = isEnabled
240     }
241 
242     fun setScreenModel(screenModel: ScreenModel) {
243         _screenModel.value = screenModel
244     }
245 
246     override fun isUdfpsSupported(): Boolean {
247         return _isUdfpsSupported.value
248     }
249 
250     override fun setKeyguardAlpha(alpha: Float) {
251         _keyguardAlpha.value = alpha
252     }
253 
254     override fun setKeyguardVisibility(
255         statusBarState: Int,
256         goingToFullShade: Boolean,
257         occlusionTransitionRunning: Boolean
258     ) {
259         _keyguardRootViewVisibility.value =
260             KeyguardRootViewVisibilityState(
261                 statusBarState,
262                 goingToFullShade,
263                 occlusionTransitionRunning
264             )
265     }
266 }
267