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.ConfigurationInteractorImpl 23 import com.android.systemui.flags.FakeFeatureFlags 24 import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository 25 import com.android.systemui.keyguard.shared.model.KeyguardState 26 import com.android.systemui.keyguard.shared.model.TransitionStep 27 import com.android.systemui.scene.domain.interactor.SceneInteractor 28 import com.android.systemui.shade.data.repository.FakeShadeRepository 29 import com.android.systemui.util.mockito.mock 30 import com.android.systemui.util.mockito.whenever 31 import com.android.systemui.wallpapers.data.repository.FakeWallpaperFocalAreaRepository 32 import com.android.systemui.wallpapers.data.repository.WallpaperFocalAreaRepository 33 import kotlinx.coroutines.CoroutineScope 34 import kotlinx.coroutines.flow.MutableSharedFlow 35 import kotlinx.coroutines.flow.MutableStateFlow 36 import kotlinx.coroutines.test.TestScope 37 import org.mockito.kotlin.any 38 39 /** 40 * Simply put, I got tired of adding a constructor argument and then having to tweak dozens of 41 * files. This should alleviate some of the burden by providing defaults for testing. 42 */ 43 object KeyguardInteractorFactory { 44 45 @JvmOverloads 46 @JvmStatic createnull47 fun create( 48 featureFlags: FakeFeatureFlags = FakeFeatureFlags(), 49 repository: FakeKeyguardRepository = FakeKeyguardRepository(), 50 bouncerRepository: FakeKeyguardBouncerRepository = FakeKeyguardBouncerRepository(), 51 configurationRepository: FakeConfigurationRepository = FakeConfigurationRepository(), 52 shadeRepository: FakeShadeRepository = FakeShadeRepository(), 53 wallpaperFocalAreaRepository: WallpaperFocalAreaRepository = 54 FakeWallpaperFocalAreaRepository(), 55 sceneInteractor: SceneInteractor = mock(), 56 fromGoneTransitionInteractor: FromGoneTransitionInteractor = mock(), 57 fromLockscreenTransitionInteractor: FromLockscreenTransitionInteractor = mock(), 58 fromOccludedTransitionInteractor: FromOccludedTransitionInteractor = mock(), 59 fromAlternateBouncerTransitionInteractor: FromAlternateBouncerTransitionInteractor = mock(), 60 testScope: CoroutineScope = TestScope(), 61 ): WithDependencies { 62 // Mock these until they are replaced by kosmos 63 val currentKeyguardStateFlow = MutableSharedFlow<KeyguardState>() 64 val transitionStateFlow = MutableStateFlow(TransitionStep()) 65 val keyguardTransitionInteractor = 66 mock<KeyguardTransitionInteractor>().also { 67 whenever(it.currentKeyguardState).thenReturn(currentKeyguardStateFlow) 68 whenever(it.transitionState).thenReturn(transitionStateFlow) 69 whenever(it.isFinishedIn(any(), any())).thenReturn(MutableStateFlow(false)) 70 } 71 return WithDependencies( 72 repository = repository, 73 featureFlags = featureFlags, 74 bouncerRepository = bouncerRepository, 75 configurationRepository = configurationRepository, 76 shadeRepository = shadeRepository, 77 KeyguardInteractor( 78 repository = repository, 79 bouncerRepository = bouncerRepository, 80 configurationInteractor = ConfigurationInteractorImpl(configurationRepository), 81 shadeRepository = shadeRepository, 82 keyguardTransitionInteractor = keyguardTransitionInteractor, 83 sceneInteractorProvider = { sceneInteractor }, 84 fromGoneTransitionInteractor = { fromGoneTransitionInteractor }, 85 fromLockscreenTransitionInteractor = { fromLockscreenTransitionInteractor }, 86 fromOccludedTransitionInteractor = { fromOccludedTransitionInteractor }, 87 fromAlternateBouncerTransitionInteractor = { 88 fromAlternateBouncerTransitionInteractor 89 }, 90 applicationScope = testScope, 91 wallpaperFocalAreaRepository = wallpaperFocalAreaRepository, 92 ), 93 ) 94 } 95 96 data class WithDependencies( 97 val repository: FakeKeyguardRepository, 98 val featureFlags: FakeFeatureFlags, 99 val bouncerRepository: FakeKeyguardBouncerRepository, 100 val configurationRepository: FakeConfigurationRepository, 101 val shadeRepository: FakeShadeRepository, 102 val keyguardInteractor: KeyguardInteractor, 103 ) 104 } 105