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.dagger.SysUISingleton 22 import com.android.systemui.keyguard.shared.model.BiometricUnlockMode 23 import com.android.systemui.keyguard.shared.model.BiometricUnlockModel 24 import com.android.systemui.keyguard.shared.model.BiometricUnlockSource 25 import com.android.systemui.keyguard.shared.model.CameraLaunchSourceModel 26 import com.android.systemui.keyguard.shared.model.DismissAction 27 import com.android.systemui.keyguard.shared.model.DozeTransitionModel 28 import com.android.systemui.keyguard.shared.model.KeyguardDone 29 import com.android.systemui.keyguard.shared.model.StatusBarState 30 import dagger.Binds 31 import dagger.Module 32 import javax.inject.Inject 33 import kotlinx.coroutines.flow.Flow 34 import kotlinx.coroutines.flow.MutableSharedFlow 35 import kotlinx.coroutines.flow.MutableStateFlow 36 import kotlinx.coroutines.flow.StateFlow 37 import kotlinx.coroutines.flow.asStateFlow 38 39 /** Fake implementation of [KeyguardRepository] */ 40 @SysUISingleton 41 class FakeKeyguardRepository @Inject constructor() : KeyguardRepository { 42 private val _deferKeyguardDone: MutableSharedFlow<KeyguardDone> = MutableSharedFlow() 43 override val keyguardDone: Flow<KeyguardDone> = _deferKeyguardDone 44 45 private val _keyguardDoneAnimationsFinished: MutableSharedFlow<Unit> = 46 MutableSharedFlow(extraBufferCapacity = 1) 47 override val keyguardDoneAnimationsFinished: Flow<Unit> = _keyguardDoneAnimationsFinished 48 49 private val _clockShouldBeCentered = MutableStateFlow<Boolean>(true) 50 override val clockShouldBeCentered: Flow<Boolean> = _clockShouldBeCentered 51 52 private val _dismissAction = MutableStateFlow<DismissAction>(DismissAction.None) 53 override val dismissAction: StateFlow<DismissAction> = _dismissAction 54 55 private val _animateBottomAreaDozingTransitions = MutableStateFlow(false) 56 override val animateBottomAreaDozingTransitions: StateFlow<Boolean> = 57 _animateBottomAreaDozingTransitions 58 59 private val _bottomAreaAlpha = MutableStateFlow(1f) 60 override val bottomAreaAlpha: StateFlow<Float> = _bottomAreaAlpha 61 62 private val _isKeyguardShowing = MutableStateFlow(false) 63 override val isKeyguardShowing: StateFlow<Boolean> = _isKeyguardShowing 64 65 private val _isKeyguardUnlocked = MutableStateFlow(false) 66 override val isKeyguardDismissible: StateFlow<Boolean> = _isKeyguardUnlocked.asStateFlow() 67 68 private val _isKeyguardOccluded = MutableStateFlow(false) 69 override val isKeyguardOccluded: StateFlow<Boolean> = _isKeyguardOccluded 70 71 private val _isDozing = MutableStateFlow(false) 72 override val isDozing: StateFlow<Boolean> = _isDozing 73 74 private val _dozeTimeTick = MutableStateFlow<Long>(0L) 75 override val dozeTimeTick = _dozeTimeTick 76 77 override val showDismissibleKeyguard = MutableStateFlow<Long>(0L) 78 79 private val _lastDozeTapToWakePosition = MutableStateFlow<Point?>(null) 80 override val lastDozeTapToWakePosition = _lastDozeTapToWakePosition.asStateFlow() 81 82 private val _isAodAvailable = MutableStateFlow(false) 83 override val isAodAvailable: StateFlow<Boolean> = _isAodAvailable 84 85 private val _isDreaming = MutableStateFlow(false) 86 override val isDreaming: MutableStateFlow<Boolean> = _isDreaming 87 88 private val _isDreamingWithOverlay = MutableStateFlow(false) 89 override val isDreamingWithOverlay: Flow<Boolean> = _isDreamingWithOverlay 90 91 private val _dozeAmount = MutableStateFlow(0f) 92 override val linearDozeAmount: Flow<Float> = _dozeAmount 93 94 private val _statusBarState = MutableStateFlow(StatusBarState.SHADE) 95 override val statusBarState: StateFlow<StatusBarState> = _statusBarState 96 97 private val _dozeTransitionModel = MutableStateFlow(DozeTransitionModel()) 98 override val dozeTransitionModel: Flow<DozeTransitionModel> = _dozeTransitionModel 99 100 private val _isUdfpsSupported = MutableStateFlow(false) 101 102 override val isKeyguardGoingAway = MutableStateFlow(false) 103 104 private val _biometricUnlockState = 105 MutableStateFlow(BiometricUnlockModel(BiometricUnlockMode.NONE, null)) 106 override val biometricUnlockState: StateFlow<BiometricUnlockModel> = 107 _biometricUnlockState.asStateFlow() 108 109 private val _fingerprintSensorLocation = MutableStateFlow<Point?>(null) 110 override val fingerprintSensorLocation: Flow<Point?> = _fingerprintSensorLocation 111 112 private val _faceSensorLocation = MutableStateFlow<Point?>(null) 113 override val faceSensorLocation: Flow<Point?> = _faceSensorLocation 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 override val panelAlpha: MutableStateFlow<Float> = MutableStateFlow(1f) 122 123 override val lastRootViewTapPosition: MutableStateFlow<Point?> = MutableStateFlow(null) 124 125 override val ambientIndicationVisible: MutableStateFlow<Boolean> = MutableStateFlow(false) 126 127 private val _isEncryptedOrLockdown = MutableStateFlow(true) 128 override val isEncryptedOrLockdown: Flow<Boolean> = _isEncryptedOrLockdown 129 130 private val _shortcutAbsoluteTop = MutableStateFlow(0F) 131 override val shortcutAbsoluteTop: StateFlow<Float> 132 get() = _shortcutAbsoluteTop.asStateFlow() 133 134 private val _notificationStackAbsoluteBottom = MutableStateFlow(0F) 135 override val notificationStackAbsoluteBottom: StateFlow<Float> 136 get() = _notificationStackAbsoluteBottom.asStateFlow() 137 138 private val _isKeyguardEnabled = MutableStateFlow(true) 139 override val isKeyguardEnabled: StateFlow<Boolean> = _isKeyguardEnabled.asStateFlow() 140 141 override val topClippingBounds = MutableStateFlow<Int?>(null) 142 143 private var isShowKeyguardWhenReenabled: Boolean = false 144 145 private val _canIgnoreAuthAndReturnToGone = MutableStateFlow(false) 146 override val canIgnoreAuthAndReturnToGone = _canIgnoreAuthAndReturnToGone.asStateFlow() 147 148 override val onCameraLaunchDetected = MutableStateFlow(CameraLaunchSourceModel()) 149 setQuickSettingsVisiblenull150 override fun setQuickSettingsVisible(isVisible: Boolean) { 151 _isQuickSettingsVisible.value = isVisible 152 } 153 isKeyguardShowingnull154 override fun isKeyguardShowing(): Boolean { 155 return _isKeyguardShowing.value 156 } 157 setAnimateDozingTransitionsnull158 override fun setAnimateDozingTransitions(animate: Boolean) { 159 _animateBottomAreaDozingTransitions.tryEmit(animate) 160 } 161 162 @Deprecated("Deprecated as part of b/278057014") setBottomAreaAlphanull163 override fun setBottomAreaAlpha(alpha: Float) { 164 _bottomAreaAlpha.value = alpha 165 } 166 setKeyguardShowingnull167 fun setKeyguardShowing(isShowing: Boolean) { 168 _isKeyguardShowing.value = isShowing 169 } 170 setKeyguardGoingAwaynull171 fun setKeyguardGoingAway(isGoingAway: Boolean) { 172 isKeyguardGoingAway.value = isGoingAway 173 } 174 setKeyguardOccludednull175 fun setKeyguardOccluded(isOccluded: Boolean) { 176 _isKeyguardOccluded.value = isOccluded 177 } 178 setKeyguardDismissiblenull179 fun setKeyguardDismissible(isUnlocked: Boolean) { 180 _isKeyguardUnlocked.value = isUnlocked 181 } 182 setIsDozingnull183 override fun setIsDozing(isDozing: Boolean) { 184 _isDozing.value = isDozing 185 } 186 dozeTimeTicknull187 override fun dozeTimeTick() { 188 _dozeTimeTick.value = _dozeTimeTick.value + 1 189 } 190 setDismissActionnull191 override fun setDismissAction(dismissAction: DismissAction) { 192 _dismissAction.value = dismissAction 193 } 194 setKeyguardDonenull195 override suspend fun setKeyguardDone(timing: KeyguardDone) { 196 _deferKeyguardDone.emit(timing) 197 } 198 keyguardDoneAnimationsFinishednull199 override fun keyguardDoneAnimationsFinished() { 200 _keyguardDoneAnimationsFinished.tryEmit(Unit) 201 } 202 setClockShouldBeCenterednull203 override fun setClockShouldBeCentered(shouldBeCentered: Boolean) { 204 _clockShouldBeCentered.value = shouldBeCentered 205 } 206 setKeyguardEnablednull207 override fun setKeyguardEnabled(enabled: Boolean) { 208 _isKeyguardEnabled.value = enabled 209 } 210 dozeTimeTicknull211 fun dozeTimeTick(millis: Long) { 212 _dozeTimeTick.value = millis 213 } 214 showDismissibleKeyguardnull215 override fun showDismissibleKeyguard() { 216 showDismissibleKeyguard.value = showDismissibleKeyguard.value + 1 217 } 218 setLastDozeTapToWakePositionnull219 override fun setLastDozeTapToWakePosition(position: Point) { 220 _lastDozeTapToWakePosition.value = position 221 } 222 setAodAvailablenull223 override fun setAodAvailable(value: Boolean) { 224 _isAodAvailable.value = value 225 } 226 setDreamingnull227 override fun setDreaming(isDreaming: Boolean) { 228 _isDreaming.value = isDreaming 229 // Intentionally set both for testing, to avoid races with merge() in the interactor that 230 // would make testing difficult 231 _isDreamingWithOverlay.value = isDreaming 232 } 233 setDreamingWithOverlaynull234 fun setDreamingWithOverlay(isDreaming: Boolean) { 235 _isDreamingWithOverlay.value = isDreaming 236 } 237 setDozeAmountnull238 fun setDozeAmount(dozeAmount: Float) { 239 _dozeAmount.value = dozeAmount 240 } 241 setBiometricUnlockStatenull242 override fun setBiometricUnlockState( 243 mode: BiometricUnlockMode, 244 source: BiometricUnlockSource?, 245 ) { 246 _biometricUnlockState.tryEmit(BiometricUnlockModel(mode, source)) 247 } 248 setBiometricUnlockStatenull249 fun setBiometricUnlockState(mode: BiometricUnlockMode) { 250 setBiometricUnlockState(mode, BiometricUnlockSource.FINGERPRINT_SENSOR) 251 } 252 setBiometricUnlockSourcenull253 fun setBiometricUnlockSource(source: BiometricUnlockSource?) { 254 setBiometricUnlockState(BiometricUnlockMode.NONE, source) 255 } 256 setFaceSensorLocationnull257 fun setFaceSensorLocation(location: Point?) { 258 _faceSensorLocation.tryEmit(location) 259 } 260 setFingerprintSensorLocationnull261 fun setFingerprintSensorLocation(location: Point?) { 262 _fingerprintSensorLocation.tryEmit(location) 263 } 264 setDozeTransitionModelnull265 fun setDozeTransitionModel(model: DozeTransitionModel) { 266 _dozeTransitionModel.value = model 267 } 268 setStatusBarStatenull269 fun setStatusBarState(state: StatusBarState) { 270 _statusBarState.value = state 271 } 272 isUdfpsSupportednull273 override fun isUdfpsSupported(): Boolean { 274 return _isUdfpsSupported.value 275 } 276 setKeyguardAlphanull277 override fun setKeyguardAlpha(alpha: Float) { 278 _keyguardAlpha.value = alpha 279 } 280 setPanelAlphanull281 override fun setPanelAlpha(alpha: Float) { 282 panelAlpha.value = alpha 283 } 284 setIsEncryptedOrLockdownnull285 fun setIsEncryptedOrLockdown(value: Boolean) { 286 _isEncryptedOrLockdown.value = value 287 } 288 setShowKeyguardWhenReenablednull289 override fun setShowKeyguardWhenReenabled(isShowKeyguardWhenReenabled: Boolean) { 290 this.isShowKeyguardWhenReenabled = isShowKeyguardWhenReenabled 291 } 292 isShowKeyguardWhenReenablednull293 override fun isShowKeyguardWhenReenabled(): Boolean { 294 return isShowKeyguardWhenReenabled 295 } 296 setShortcutAbsoluteTopnull297 override fun setShortcutAbsoluteTop(top: Float) { 298 _shortcutAbsoluteTop.value = top 299 } 300 setNotificationStackAbsoluteBottomnull301 override fun setNotificationStackAbsoluteBottom(bottom: Float) { 302 _notificationStackAbsoluteBottom.value = bottom 303 } 304 setCanIgnoreAuthAndReturnToGonenull305 override fun setCanIgnoreAuthAndReturnToGone(canWake: Boolean) { 306 _canIgnoreAuthAndReturnToGone.value = canWake 307 } 308 } 309 310 @Module 311 interface FakeKeyguardRepositoryModule { bindFakenull312 @Binds fun bindFake(fake: FakeKeyguardRepository): KeyguardRepository 313 } 314