1 package com.android.systemui.bouncer.data.repository 2 3 import com.android.keyguard.KeyguardSecurityModel 4 import com.android.systemui.bouncer.shared.constants.KeyguardBouncerConstants 5 import com.android.systemui.bouncer.shared.model.BouncerDismissActionModel 6 import com.android.systemui.bouncer.shared.model.BouncerShowMessageModel 7 import com.android.systemui.dagger.SysUISingleton 8 import dagger.Binds 9 import dagger.Module 10 import javax.inject.Inject 11 import kotlinx.coroutines.flow.Flow 12 import kotlinx.coroutines.flow.MutableSharedFlow 13 import kotlinx.coroutines.flow.MutableStateFlow 14 import kotlinx.coroutines.flow.asSharedFlow 15 import kotlinx.coroutines.flow.asStateFlow 16 17 /** Fake implementation of [KeyguardBouncerRepository] */ 18 @SysUISingleton 19 class FakeKeyguardBouncerRepository @Inject constructor() : KeyguardBouncerRepository { 20 private val _primaryBouncerShow = MutableStateFlow(false) 21 override val primaryBouncerShow = _primaryBouncerShow.asStateFlow() 22 private val _primaryBouncerShowingSoon = MutableStateFlow(false) 23 override val primaryBouncerShowingSoon = _primaryBouncerShowingSoon.asStateFlow() 24 private val _primaryBouncerStartingToHide = MutableStateFlow(false) 25 override val primaryBouncerStartingToHide = _primaryBouncerStartingToHide.asStateFlow() 26 override val primaryBouncerStartingDisappearAnimation = 27 MutableSharedFlow<Runnable?>(extraBufferCapacity = 2, replay = 1) 28 isPrimaryBouncerStartingDisappearAnimationnull29 override fun isPrimaryBouncerStartingDisappearAnimation(): Boolean { 30 val replayCache = primaryBouncerStartingDisappearAnimation.replayCache 31 return if (!replayCache.isEmpty()) { 32 replayCache.last() != null 33 } else { 34 false 35 } 36 } 37 38 private val _primaryBouncerScrimmed = MutableStateFlow(false) 39 override val primaryBouncerScrimmed = _primaryBouncerScrimmed.asStateFlow() 40 private val _panelExpansionAmount = MutableStateFlow(KeyguardBouncerConstants.EXPANSION_HIDDEN) 41 override val panelExpansionAmount = _panelExpansionAmount.asStateFlow() 42 private val _keyguardPosition = MutableStateFlow<Float?>(null) 43 override val keyguardPosition = _keyguardPosition.asStateFlow() 44 private val _isBackButtonEnabled = MutableStateFlow<Boolean?>(null) 45 override val isBackButtonEnabled = _isBackButtonEnabled.asStateFlow() 46 private val _keyguardAuthenticated = MutableStateFlow<Boolean?>(null) 47 override val keyguardAuthenticatedBiometrics = _keyguardAuthenticated.asStateFlow() 48 private val _keyguardAuthenticatedPrimaryAuth = MutableSharedFlow<Int>() 49 override val keyguardAuthenticatedPrimaryAuth: Flow<Int> = 50 _keyguardAuthenticatedPrimaryAuth.asSharedFlow() 51 private val _userRequestedBouncerWhenAlreadyAuthenticated = MutableSharedFlow<Int>() 52 override val userRequestedBouncerWhenAlreadyAuthenticated: Flow<Int> = 53 _userRequestedBouncerWhenAlreadyAuthenticated.asSharedFlow() 54 private val _showMessage = MutableStateFlow<BouncerShowMessageModel?>(null) 55 override val showMessage = _showMessage.asStateFlow() 56 private val _resourceUpdateRequests = MutableStateFlow(false) 57 override val resourceUpdateRequests = _resourceUpdateRequests.asStateFlow() 58 private val _isAlternateBouncerVisible = MutableStateFlow(false) 59 override val alternateBouncerVisible = _isAlternateBouncerVisible.asStateFlow() 60 override var lastAlternateBouncerVisibleTime: Long = 0L 61 override val lastShownSecurityMode: MutableStateFlow<KeyguardSecurityModel.SecurityMode> = 62 MutableStateFlow(KeyguardSecurityModel.SecurityMode.Invalid) 63 override var bouncerDismissActionModel: BouncerDismissActionModel? = null 64 isDebuggablenull65 override fun isDebuggable() = true 66 67 override fun setPrimaryScrimmed(isScrimmed: Boolean) { 68 _primaryBouncerScrimmed.value = isScrimmed 69 } 70 setAlternateVisiblenull71 override fun setAlternateVisible(isVisible: Boolean) { 72 _isAlternateBouncerVisible.value = isVisible 73 } 74 setPrimaryShownull75 override fun setPrimaryShow(isShowing: Boolean) { 76 _primaryBouncerShow.value = isShowing 77 } 78 setPrimaryShowingSoonnull79 override fun setPrimaryShowingSoon(showingSoon: Boolean) { 80 _primaryBouncerShowingSoon.value = showingSoon 81 } 82 setPrimaryStartingToHidenull83 override fun setPrimaryStartingToHide(startingToHide: Boolean) { 84 _primaryBouncerStartingToHide.value = startingToHide 85 } 86 setPrimaryStartDisappearAnimationnull87 override fun setPrimaryStartDisappearAnimation(runnable: Runnable?) { 88 primaryBouncerStartingDisappearAnimation.tryEmit(runnable) 89 } 90 setPanelExpansionnull91 override fun setPanelExpansion(panelExpansion: Float) { 92 _panelExpansionAmount.value = panelExpansion 93 } 94 setKeyguardPositionnull95 override fun setKeyguardPosition(keyguardPosition: Float) { 96 _keyguardPosition.value = keyguardPosition 97 } 98 setResourceUpdateRequestsnull99 override fun setResourceUpdateRequests(willUpdateResources: Boolean) { 100 _resourceUpdateRequests.value = willUpdateResources 101 } 102 setShowMessagenull103 override fun setShowMessage(bouncerShowMessageModel: BouncerShowMessageModel?) { 104 _showMessage.value = bouncerShowMessageModel 105 } 106 setKeyguardAuthenticatedBiometricsnull107 override fun setKeyguardAuthenticatedBiometrics(keyguardAuthenticated: Boolean?) { 108 _keyguardAuthenticated.value = keyguardAuthenticated 109 } 110 setKeyguardAuthenticatedPrimaryAuthnull111 override suspend fun setKeyguardAuthenticatedPrimaryAuth(userId: Int) { 112 _keyguardAuthenticatedPrimaryAuth.emit(userId) 113 } 114 setUserRequestedBouncerWhenAlreadyAuthenticatednull115 override suspend fun setUserRequestedBouncerWhenAlreadyAuthenticated(userId: Int) { 116 _userRequestedBouncerWhenAlreadyAuthenticated.emit(userId) 117 } 118 setIsBackButtonEnablednull119 override fun setIsBackButtonEnabled(isBackButtonEnabled: Boolean) { 120 _isBackButtonEnabled.value = isBackButtonEnabled 121 } 122 setLastShownSecurityModenull123 override fun setLastShownSecurityMode(securityMode: KeyguardSecurityModel.SecurityMode) { 124 lastShownSecurityMode.value = securityMode 125 } 126 } 127 128 @Module 129 interface FakeKeyguardBouncerRepositoryModule { bindFakenull130 @Binds fun bindFake(fake: FakeKeyguardBouncerRepository): KeyguardBouncerRepository 131 } 132