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.DismissAction 26 import com.android.systemui.keyguard.shared.model.DozeTransitionModel 27 import com.android.systemui.keyguard.shared.model.KeyguardDone 28 import com.android.systemui.keyguard.shared.model.StatusBarState 29 import dagger.Binds 30 import dagger.Module 31 import javax.inject.Inject 32 import kotlinx.coroutines.flow.Flow 33 import kotlinx.coroutines.flow.MutableSharedFlow 34 import kotlinx.coroutines.flow.MutableStateFlow 35 import kotlinx.coroutines.flow.StateFlow 36 import kotlinx.coroutines.flow.asStateFlow 37 38 /** Fake implementation of [KeyguardRepository] */ 39 @SysUISingleton 40 class FakeKeyguardRepository @Inject constructor() : KeyguardRepository { 41 private val _deferKeyguardDone: MutableSharedFlow<KeyguardDone> = MutableSharedFlow() 42 override val keyguardDone: Flow<KeyguardDone> = _deferKeyguardDone 43 44 private val _keyguardDoneAnimationsFinished: MutableSharedFlow<Unit> = 45 MutableSharedFlow(extraBufferCapacity = 1) 46 override val keyguardDoneAnimationsFinished: Flow<Unit> = _keyguardDoneAnimationsFinished 47 48 private val _clockShouldBeCentered = MutableStateFlow<Boolean>(true) 49 override val clockShouldBeCentered: Flow<Boolean> = _clockShouldBeCentered 50 51 private val _dismissAction = MutableStateFlow<DismissAction>(DismissAction.None) 52 override val dismissAction: StateFlow<DismissAction> = _dismissAction 53 54 private val _animateBottomAreaDozingTransitions = MutableStateFlow(false) 55 override val animateBottomAreaDozingTransitions: StateFlow<Boolean> = 56 _animateBottomAreaDozingTransitions 57 58 private val _bottomAreaAlpha = MutableStateFlow(1f) 59 override val bottomAreaAlpha: StateFlow<Float> = _bottomAreaAlpha 60 61 private val _isKeyguardShowing = MutableStateFlow(false) 62 override val isKeyguardShowing: Flow<Boolean> = _isKeyguardShowing 63 64 private val _isKeyguardUnlocked = MutableStateFlow(false) 65 override val isKeyguardDismissible: StateFlow<Boolean> = _isKeyguardUnlocked.asStateFlow() 66 67 private val _isKeyguardOccluded = MutableStateFlow(false) 68 override val isKeyguardOccluded: Flow<Boolean> = _isKeyguardOccluded 69 70 private val _isDozing = MutableStateFlow(false) 71 override val isDozing: StateFlow<Boolean> = _isDozing 72 73 private val _dozeTimeTick = MutableStateFlow<Long>(0L) 74 override val dozeTimeTick = _dozeTimeTick 75 76 private val _lastDozeTapToWakePosition = MutableStateFlow<Point?>(null) 77 override val lastDozeTapToWakePosition = _lastDozeTapToWakePosition.asStateFlow() 78 79 private val _isAodAvailable = MutableStateFlow(false) 80 override val isAodAvailable: StateFlow<Boolean> = _isAodAvailable 81 82 private val _isDreaming = MutableStateFlow(false) 83 override val isDreaming: MutableStateFlow<Boolean> = _isDreaming 84 85 private val _isDreamingWithOverlay = MutableStateFlow(false) 86 override val isDreamingWithOverlay: Flow<Boolean> = _isDreamingWithOverlay 87 88 private val _isActiveDreamLockscreenHosted = MutableStateFlow(false) 89 override val isActiveDreamLockscreenHosted: StateFlow<Boolean> = _isActiveDreamLockscreenHosted 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 private val _isKeyguardGoingAway = MutableStateFlow(false) 103 override val isKeyguardGoingAway: Flow<Boolean> = _isKeyguardGoingAway 104 105 private val _biometricUnlockState = 106 MutableStateFlow(BiometricUnlockModel(BiometricUnlockMode.NONE, null)) 107 override val biometricUnlockState: StateFlow<BiometricUnlockModel> = 108 _biometricUnlockState.asStateFlow() 109 110 private val _fingerprintSensorLocation = MutableStateFlow<Point?>(null) 111 override val fingerprintSensorLocation: Flow<Point?> = _fingerprintSensorLocation 112 113 private val _faceSensorLocation = MutableStateFlow<Point?>(null) 114 override val faceSensorLocation: Flow<Point?> = _faceSensorLocation 115 116 private val _isQuickSettingsVisible = MutableStateFlow(false) 117 override val isQuickSettingsVisible: Flow<Boolean> = _isQuickSettingsVisible.asStateFlow() 118 119 private val _keyguardAlpha = MutableStateFlow(1f) 120 override val keyguardAlpha: StateFlow<Float> = _keyguardAlpha 121 122 override val lastRootViewTapPosition: MutableStateFlow<Point?> = MutableStateFlow(null) 123 124 override val ambientIndicationVisible: MutableStateFlow<Boolean> = MutableStateFlow(false) 125 126 private val _isEncryptedOrLockdown = MutableStateFlow(true) 127 override val isEncryptedOrLockdown: Flow<Boolean> = _isEncryptedOrLockdown 128 129 private val _isKeyguardEnabled = MutableStateFlow(true) 130 override val isKeyguardEnabled: StateFlow<Boolean> = _isKeyguardEnabled.asStateFlow() 131 132 override val topClippingBounds = MutableStateFlow<Int?>(null) 133 setQuickSettingsVisiblenull134 override fun setQuickSettingsVisible(isVisible: Boolean) { 135 _isQuickSettingsVisible.value = isVisible 136 } 137 isKeyguardShowingnull138 override fun isKeyguardShowing(): Boolean { 139 return _isKeyguardShowing.value 140 } 141 setAnimateDozingTransitionsnull142 override fun setAnimateDozingTransitions(animate: Boolean) { 143 _animateBottomAreaDozingTransitions.tryEmit(animate) 144 } 145 146 @Deprecated("Deprecated as part of b/278057014") setBottomAreaAlphanull147 override fun setBottomAreaAlpha(alpha: Float) { 148 _bottomAreaAlpha.value = alpha 149 } 150 setKeyguardShowingnull151 fun setKeyguardShowing(isShowing: Boolean) { 152 _isKeyguardShowing.value = isShowing 153 } 154 setKeyguardGoingAwaynull155 fun setKeyguardGoingAway(isGoingAway: Boolean) { 156 _isKeyguardGoingAway.value = isGoingAway 157 } 158 setKeyguardOccludednull159 fun setKeyguardOccluded(isOccluded: Boolean) { 160 _isKeyguardOccluded.value = isOccluded 161 } 162 setKeyguardDismissiblenull163 fun setKeyguardDismissible(isUnlocked: Boolean) { 164 _isKeyguardUnlocked.value = isUnlocked 165 } 166 setIsDozingnull167 override fun setIsDozing(isDozing: Boolean) { 168 _isDozing.value = isDozing 169 } 170 dozeTimeTicknull171 override fun dozeTimeTick() { 172 _dozeTimeTick.value = _dozeTimeTick.value + 1 173 } 174 setDismissActionnull175 override fun setDismissAction(dismissAction: DismissAction) { 176 _dismissAction.value = dismissAction 177 } 178 setKeyguardDonenull179 override suspend fun setKeyguardDone(timing: KeyguardDone) { 180 _deferKeyguardDone.emit(timing) 181 } 182 keyguardDoneAnimationsFinishednull183 override fun keyguardDoneAnimationsFinished() { 184 _keyguardDoneAnimationsFinished.tryEmit(Unit) 185 } 186 setClockShouldBeCenterednull187 override fun setClockShouldBeCentered(shouldBeCentered: Boolean) { 188 _clockShouldBeCentered.value = shouldBeCentered 189 } 190 setKeyguardEnablednull191 override fun setKeyguardEnabled(enabled: Boolean) { 192 _isKeyguardEnabled.value = enabled 193 } 194 dozeTimeTicknull195 fun dozeTimeTick(millis: Long) { 196 _dozeTimeTick.value = millis 197 } 198 setLastDozeTapToWakePositionnull199 override fun setLastDozeTapToWakePosition(position: Point) { 200 _lastDozeTapToWakePosition.value = position 201 } 202 setAodAvailablenull203 override fun setAodAvailable(value: Boolean) { 204 _isAodAvailable.value = value 205 } 206 setDreamingnull207 override fun setDreaming(isDreaming: Boolean) { 208 _isDreaming.value = isDreaming 209 } 210 setDreamingWithOverlaynull211 fun setDreamingWithOverlay(isDreaming: Boolean) { 212 _isDreamingWithOverlay.value = isDreaming 213 } 214 setIsActiveDreamLockscreenHostednull215 override fun setIsActiveDreamLockscreenHosted(isLockscreenHosted: Boolean) { 216 _isActiveDreamLockscreenHosted.value = isLockscreenHosted 217 } 218 setDozeAmountnull219 fun setDozeAmount(dozeAmount: Float) { 220 _dozeAmount.value = dozeAmount 221 } 222 setBiometricUnlockStatenull223 override fun setBiometricUnlockState( 224 mode: BiometricUnlockMode, 225 source: BiometricUnlockSource? 226 ) { 227 _biometricUnlockState.tryEmit(BiometricUnlockModel(mode, source)) 228 } 229 setBiometricUnlockStatenull230 fun setBiometricUnlockState(mode: BiometricUnlockMode) { 231 setBiometricUnlockState(mode, BiometricUnlockSource.FINGERPRINT_SENSOR) 232 } 233 setBiometricUnlockSourcenull234 fun setBiometricUnlockSource(source: BiometricUnlockSource?) { 235 setBiometricUnlockState(BiometricUnlockMode.NONE, source) 236 } 237 setFaceSensorLocationnull238 fun setFaceSensorLocation(location: Point?) { 239 _faceSensorLocation.tryEmit(location) 240 } 241 setFingerprintSensorLocationnull242 fun setFingerprintSensorLocation(location: Point?) { 243 _fingerprintSensorLocation.tryEmit(location) 244 } 245 setDozeTransitionModelnull246 fun setDozeTransitionModel(model: DozeTransitionModel) { 247 _dozeTransitionModel.value = model 248 } 249 setStatusBarStatenull250 fun setStatusBarState(state: StatusBarState) { 251 _statusBarState.value = state 252 } 253 isUdfpsSupportednull254 override fun isUdfpsSupported(): Boolean { 255 return _isUdfpsSupported.value 256 } 257 setKeyguardAlphanull258 override fun setKeyguardAlpha(alpha: Float) { 259 _keyguardAlpha.value = alpha 260 } 261 setIsEncryptedOrLockdownnull262 fun setIsEncryptedOrLockdown(value: Boolean) { 263 _isEncryptedOrLockdown.value = value 264 } 265 } 266 267 @Module 268 interface FakeKeyguardRepositoryModule { bindFakenull269 @Binds fun bindFake(fake: FakeKeyguardRepository): KeyguardRepository 270 } 271