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     private val _primaryBouncerDisappearAnimation = MutableStateFlow<Runnable?>(null)
27     override val primaryBouncerStartingDisappearAnimation =
28         _primaryBouncerDisappearAnimation.asStateFlow()
29     private val _primaryBouncerScrimmed = MutableStateFlow(false)
30     override val primaryBouncerScrimmed = _primaryBouncerScrimmed.asStateFlow()
31     private val _panelExpansionAmount = MutableStateFlow(KeyguardBouncerConstants.EXPANSION_HIDDEN)
32     override val panelExpansionAmount = _panelExpansionAmount.asStateFlow()
33     private val _keyguardPosition = MutableStateFlow<Float?>(null)
34     override val keyguardPosition = _keyguardPosition.asStateFlow()
35     private val _isBackButtonEnabled = MutableStateFlow<Boolean?>(null)
36     override val isBackButtonEnabled = _isBackButtonEnabled.asStateFlow()
37     private val _keyguardAuthenticated = MutableStateFlow<Boolean?>(null)
38     override val keyguardAuthenticatedBiometrics = _keyguardAuthenticated.asStateFlow()
39     private val _keyguardAuthenticatedPrimaryAuth = MutableSharedFlow<Int>()
40     override val keyguardAuthenticatedPrimaryAuth: Flow<Int> =
41         _keyguardAuthenticatedPrimaryAuth.asSharedFlow()
42     private val _userRequestedBouncerWhenAlreadyAuthenticated = MutableSharedFlow<Int>()
43     override val userRequestedBouncerWhenAlreadyAuthenticated: Flow<Int> =
44         _userRequestedBouncerWhenAlreadyAuthenticated.asSharedFlow()
45     private val _showMessage = MutableStateFlow<BouncerShowMessageModel?>(null)
46     override val showMessage = _showMessage.asStateFlow()
47     private val _resourceUpdateRequests = MutableStateFlow(false)
48     override val resourceUpdateRequests = _resourceUpdateRequests.asStateFlow()
49     private val _isAlternateBouncerVisible = MutableStateFlow(false)
50     override val alternateBouncerVisible = _isAlternateBouncerVisible.asStateFlow()
51     override var lastAlternateBouncerVisibleTime: Long = 0L
52     private val _isAlternateBouncerUIAvailable = MutableStateFlow<Boolean>(false)
53     override val alternateBouncerUIAvailable = _isAlternateBouncerUIAvailable.asStateFlow()
54     override val lastShownSecurityMode: MutableStateFlow<KeyguardSecurityModel.SecurityMode> =
55         MutableStateFlow(KeyguardSecurityModel.SecurityMode.Invalid)
56     override var bouncerDismissActionModel: BouncerDismissActionModel? = null
57 
setPrimaryScrimmednull58     override fun setPrimaryScrimmed(isScrimmed: Boolean) {
59         _primaryBouncerScrimmed.value = isScrimmed
60     }
61 
setAlternateVisiblenull62     override fun setAlternateVisible(isVisible: Boolean) {
63         _isAlternateBouncerVisible.value = isVisible
64     }
65 
setAlternateBouncerUIAvailablenull66     override fun setAlternateBouncerUIAvailable(isAvailable: Boolean) {
67         _isAlternateBouncerUIAvailable.value = isAvailable
68     }
69 
setPrimaryShownull70     override fun setPrimaryShow(isShowing: Boolean) {
71         _primaryBouncerShow.value = isShowing
72     }
73 
setPrimaryShowingSoonnull74     override fun setPrimaryShowingSoon(showingSoon: Boolean) {
75         _primaryBouncerShowingSoon.value = showingSoon
76     }
77 
setPrimaryStartingToHidenull78     override fun setPrimaryStartingToHide(startingToHide: Boolean) {
79         _primaryBouncerStartingToHide.value = startingToHide
80     }
81 
setPrimaryStartDisappearAnimationnull82     override fun setPrimaryStartDisappearAnimation(runnable: Runnable?) {
83         _primaryBouncerDisappearAnimation.value = runnable
84     }
85 
setPanelExpansionnull86     override fun setPanelExpansion(panelExpansion: Float) {
87         _panelExpansionAmount.value = panelExpansion
88     }
89 
setKeyguardPositionnull90     override fun setKeyguardPosition(keyguardPosition: Float) {
91         _keyguardPosition.value = keyguardPosition
92     }
93 
setResourceUpdateRequestsnull94     override fun setResourceUpdateRequests(willUpdateResources: Boolean) {
95         _resourceUpdateRequests.value = willUpdateResources
96     }
97 
setShowMessagenull98     override fun setShowMessage(bouncerShowMessageModel: BouncerShowMessageModel?) {
99         _showMessage.value = bouncerShowMessageModel
100     }
101 
setKeyguardAuthenticatedBiometricsnull102     override fun setKeyguardAuthenticatedBiometrics(keyguardAuthenticated: Boolean?) {
103         _keyguardAuthenticated.value = keyguardAuthenticated
104     }
105 
setKeyguardAuthenticatedPrimaryAuthnull106     override suspend fun setKeyguardAuthenticatedPrimaryAuth(userId: Int) {
107         _keyguardAuthenticatedPrimaryAuth.emit(userId)
108     }
109 
setUserRequestedBouncerWhenAlreadyAuthenticatednull110     override suspend fun setUserRequestedBouncerWhenAlreadyAuthenticated(userId: Int) {
111         _userRequestedBouncerWhenAlreadyAuthenticated.emit(userId)
112     }
113 
setIsBackButtonEnablednull114     override fun setIsBackButtonEnabled(isBackButtonEnabled: Boolean) {
115         _isBackButtonEnabled.value = isBackButtonEnabled
116     }
117 
setLastShownSecurityModenull118     override fun setLastShownSecurityMode(securityMode: KeyguardSecurityModel.SecurityMode) {
119         lastShownSecurityMode.value = securityMode
120     }
121 }
122 
123 @Module
124 interface FakeKeyguardBouncerRepositoryModule {
bindFakenull125     @Binds fun bindFake(fake: FakeKeyguardBouncerRepository): KeyguardBouncerRepository
126 }
127