• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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.domain.interactor
19 
20 import com.android.systemui.bouncer.data.repository.FakeKeyguardBouncerRepository
21 import com.android.systemui.common.ui.data.repository.FakeConfigurationRepository
22 import com.android.systemui.common.ui.domain.interactor.ConfigurationInteractor
23 import com.android.systemui.flags.FakeFeatureFlags
24 import com.android.systemui.keyguard.data.repository.FakeCommandQueue
25 import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository
26 import com.android.systemui.keyguard.shared.model.KeyguardState
27 import com.android.systemui.keyguard.shared.model.TransitionStep
28 import com.android.systemui.power.domain.interactor.PowerInteractor
29 import com.android.systemui.power.domain.interactor.PowerInteractorFactory
30 import com.android.systemui.scene.domain.interactor.SceneInteractor
31 import com.android.systemui.shade.data.repository.FakeShadeRepository
32 import com.android.systemui.statusbar.notification.stack.domain.interactor.SharedNotificationContainerInteractor
33 import com.android.systemui.statusbar.notification.stack.domain.interactor.SharedNotificationContainerInteractor.ConfigurationBasedDimensions
34 import com.android.systemui.util.mockito.mock
35 import com.android.systemui.util.mockito.whenever
36 import kotlinx.coroutines.CoroutineScope
37 import kotlinx.coroutines.flow.MutableSharedFlow
38 import kotlinx.coroutines.flow.MutableStateFlow
39 import kotlinx.coroutines.test.TestScope
40 
41 /**
42  * Simply put, I got tired of adding a constructor argument and then having to tweak dozens of
43  * files. This should alleviate some of the burden by providing defaults for testing.
44  */
45 object KeyguardInteractorFactory {
46 
47     @JvmOverloads
48     @JvmStatic
createnull49     fun create(
50         featureFlags: FakeFeatureFlags = FakeFeatureFlags(),
51         repository: FakeKeyguardRepository = FakeKeyguardRepository(),
52         commandQueue: FakeCommandQueue = FakeCommandQueue(),
53         bouncerRepository: FakeKeyguardBouncerRepository = FakeKeyguardBouncerRepository(),
54         configurationRepository: FakeConfigurationRepository = FakeConfigurationRepository(),
55         shadeRepository: FakeShadeRepository = FakeShadeRepository(),
56         sceneInteractor: SceneInteractor = mock(),
57         fromGoneTransitionInteractor: FromGoneTransitionInteractor = mock(),
58         fromLockscreenTransitionInteractor: FromLockscreenTransitionInteractor = mock(),
59         sharedNotificationContainerInteractor: SharedNotificationContainerInteractor? = null,
60         powerInteractor: PowerInteractor = PowerInteractorFactory.create().powerInteractor,
61         testScope: CoroutineScope = TestScope(),
62     ): WithDependencies {
63         // Mock these until they are replaced by kosmos
64         val currentKeyguardStateFlow = MutableSharedFlow<KeyguardState>()
65         val transitionStateFlow = MutableStateFlow(TransitionStep())
66         val keyguardTransitionInteractor =
67             mock<KeyguardTransitionInteractor>().also {
68                 whenever(it.currentKeyguardState).thenReturn(currentKeyguardStateFlow)
69                 whenever(it.transitionState).thenReturn(transitionStateFlow)
70             }
71         val configurationDimensionFlow = MutableSharedFlow<ConfigurationBasedDimensions>()
72         configurationDimensionFlow.tryEmit(
73             ConfigurationBasedDimensions(
74                 useSplitShade = false,
75                 useLargeScreenHeader = false,
76                 marginHorizontal = 0,
77                 marginBottom = 0,
78                 marginTop = 0,
79                 marginTopLargeScreen = 0,
80                 keyguardSplitShadeTopMargin = 0,
81             )
82         )
83         val sncInteractor =
84             sharedNotificationContainerInteractor
85                 ?: mock<SharedNotificationContainerInteractor>().also {
86                     whenever(it.configurationBasedDimensions).thenReturn(configurationDimensionFlow)
87                 }
88         return WithDependencies(
89             repository = repository,
90             commandQueue = commandQueue,
91             featureFlags = featureFlags,
92             bouncerRepository = bouncerRepository,
93             configurationRepository = configurationRepository,
94             shadeRepository = shadeRepository,
95             powerInteractor = powerInteractor,
96             KeyguardInteractor(
97                 repository = repository,
98                 commandQueue = commandQueue,
99                 powerInteractor = powerInteractor,
100                 bouncerRepository = bouncerRepository,
101                 configurationInteractor = ConfigurationInteractor(configurationRepository),
102                 shadeRepository = shadeRepository,
103                 keyguardTransitionInteractor = keyguardTransitionInteractor,
104                 sceneInteractorProvider = { sceneInteractor },
105                 fromGoneTransitionInteractor = { fromGoneTransitionInteractor },
106                 fromLockscreenTransitionInteractor = { fromLockscreenTransitionInteractor },
107                 sharedNotificationContainerInteractor = { sncInteractor },
108                 applicationScope = testScope,
109             ),
110         )
111     }
112 
113     data class WithDependencies(
114         val repository: FakeKeyguardRepository,
115         val commandQueue: FakeCommandQueue,
116         val featureFlags: FakeFeatureFlags,
117         val bouncerRepository: FakeKeyguardBouncerRepository,
118         val configurationRepository: FakeConfigurationRepository,
119         val shadeRepository: FakeShadeRepository,
120         val powerInteractor: PowerInteractor,
121         val keyguardInteractor: KeyguardInteractor,
122     )
123 }
124