From 286094a8e33ed85780ada2060c2281d3f47a2dc9 Mon Sep 17 00:00:00 2001 From: Alejandro Nijamkin Date: Fri, 12 Aug 2022 10:16:10 -0700 Subject: [PATCH] Unifies use-cases into interactors. To reduce memory use and garbage collection pressure, moving from having multiple one-method use-case classes without a dagger scope to having a handful of multi-method interactor classes with a singleton dagger scope. Fix: 241788615 Test: Unit tests. Manually verified bottom area view quick affordances behave as before. Change-Id: I441c31d5643dd7dc19d681261f8ef415ec533e0b --- .../systemui/common/coroutine/ChannelExt.kt | 2 +- .../systemui/common/domain/model/Position.kt | 34 -- .../common/{data => shared}/model/Position.kt | 2 +- .../keyguard/dagger/KeyguardModule.java | 2 - .../data/repository/KeyguardRepository.kt | 2 +- .../KeyguardBottomAreaInteractor.kt | 51 +++ .../KeyguardInteractor.kt} | 26 +- .../KeyguardQuickAffordanceInteractor.kt | 136 ++++++++ .../model/KeyguardQuickAffordanceModel.kt | 17 - .../KeyguardQuickAffordanceModule.kt | 2 +- .../KeyguardQuickAffordanceRegistry.kt | 8 +- .../domain/usecase/KeyguardUseCaseModule.kt | 34 -- .../LaunchKeyguardQuickAffordanceUseCase.kt | 76 ----- ...erveAnimateBottomAreaTransitionsUseCase.kt | 32 -- .../usecase/ObserveBottomAreaAlphaUseCase.kt | 32 -- .../usecase/ObserveClockPositionUseCase.kt | 35 --- .../usecase/ObserveDozeAmountUseCase.kt | 32 -- .../domain/usecase/ObserveIsDozingUseCase.kt | 32 -- .../ObserveKeyguardQuickAffordanceUseCase.kt | 75 ----- ...OnKeyguardQuickAffordanceClickedUseCase.kt | 49 --- .../domain/usecase/SetClockPositionUseCase.kt | 31 -- .../SetKeyguardBottomAreaAlphaUseCase.kt | 31 -- ...ttomAreaAnimateDozingTransitionsUseCase.kt | 33 -- .../viewmodel/KeyguardBottomAreaViewModel.kt | 35 +-- .../KeyguardQuickAffordanceViewModel.kt | 5 +- .../NotificationPanelViewController.java | 28 +- .../data/repository/FakeKeyguardRepository.kt | 24 +- .../repository/KeyguardRepositoryImplTest.kt | 2 +- .../FakeKeyguardQuickAffordanceRegistry.kt | 10 +- ...akeLaunchKeyguardQuickAffordanceUseCase.kt | 47 --- ...keObserveKeyguardQuickAffordanceUseCase.kt | 46 --- ...ckAffordanceInteractorParameterizedTest.kt | 294 ++++++++++++++++++ ... KeyguardQuickAffordanceInteractorTest.kt} | 54 ++-- ...hKeyguardQuickAffordanceUseCaseImplTest.kt | 178 ----------- .../KeyguardBottomAreaViewModelTest.kt | 111 +++---- .../NotificationPanelViewControllerTest.java | 13 +- 36 files changed, 614 insertions(+), 1007 deletions(-) delete mode 100644 packages/SystemUI/src/com/android/systemui/common/domain/model/Position.kt rename packages/SystemUI/src/com/android/systemui/common/{data => shared}/model/Position.kt (93%) create mode 100644 packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardBottomAreaInteractor.kt rename packages/SystemUI/src/com/android/systemui/keyguard/domain/{usecase/ObserveIsKeyguardShowingUseCase.kt => interactor/KeyguardInteractor.kt} (53%) create mode 100644 packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardQuickAffordanceInteractor.kt delete mode 100644 packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/KeyguardUseCaseModule.kt delete mode 100644 packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/LaunchKeyguardQuickAffordanceUseCase.kt delete mode 100644 packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveAnimateBottomAreaTransitionsUseCase.kt delete mode 100644 packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveBottomAreaAlphaUseCase.kt delete mode 100644 packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveClockPositionUseCase.kt delete mode 100644 packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveDozeAmountUseCase.kt delete mode 100644 packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveIsDozingUseCase.kt delete mode 100644 packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveKeyguardQuickAffordanceUseCase.kt delete mode 100644 packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/OnKeyguardQuickAffordanceClickedUseCase.kt delete mode 100644 packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/SetClockPositionUseCase.kt delete mode 100644 packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/SetKeyguardBottomAreaAlphaUseCase.kt delete mode 100644 packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/SetKeyguardBottomAreaAnimateDozingTransitionsUseCase.kt delete mode 100644 packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/usecase/FakeLaunchKeyguardQuickAffordanceUseCase.kt delete mode 100644 packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/usecase/FakeObserveKeyguardQuickAffordanceUseCase.kt create mode 100644 packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/usecase/KeyguardQuickAffordanceInteractorParameterizedTest.kt rename packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/usecase/{ObserveKeyguardQuickAffordanceUseCaseImplTest.kt => KeyguardQuickAffordanceInteractorTest.kt} (74%) delete mode 100644 packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/usecase/LaunchKeyguardQuickAffordanceUseCaseImplTest.kt diff --git a/packages/SystemUI/src/com/android/systemui/common/coroutine/ChannelExt.kt b/packages/SystemUI/src/com/android/systemui/common/coroutine/ChannelExt.kt index 6f3beac2ac85b..a0b19dc5c96e7 100644 --- a/packages/SystemUI/src/com/android/systemui/common/coroutine/ChannelExt.kt +++ b/packages/SystemUI/src/com/android/systemui/common/coroutine/ChannelExt.kt @@ -35,7 +35,7 @@ object ChannelExt { * " - downstream canceled or failed.", * it, * ) - *} + * } * ``` */ fun SendChannel.trySendWithFailureLogging( diff --git a/packages/SystemUI/src/com/android/systemui/common/domain/model/Position.kt b/packages/SystemUI/src/com/android/systemui/common/domain/model/Position.kt deleted file mode 100644 index f697c0ab3b226..0000000000000 --- a/packages/SystemUI/src/com/android/systemui/common/domain/model/Position.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.systemui.common.domain.model - -import com.android.systemui.common.data.model.Position as DataLayerPosition - -/** Models a two-dimensional position */ -data class Position( - val x: Int, - val y: Int, -) { - companion object { - fun DataLayerPosition.toDomainLayer(): Position { - return Position( - x = x, - y = y, - ) - } - } -} diff --git a/packages/SystemUI/src/com/android/systemui/common/data/model/Position.kt b/packages/SystemUI/src/com/android/systemui/common/shared/model/Position.kt similarity index 93% rename from packages/SystemUI/src/com/android/systemui/common/data/model/Position.kt rename to packages/SystemUI/src/com/android/systemui/common/shared/model/Position.kt index 7c9df102ef1dc..52f6167ba7aef 100644 --- a/packages/SystemUI/src/com/android/systemui/common/data/model/Position.kt +++ b/packages/SystemUI/src/com/android/systemui/common/shared/model/Position.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.systemui.common.data.model +package com.android.systemui.common.shared.model /** Models a two-dimensional position */ data class Position( diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java b/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java index 430b59cd4027c..56f1ac46a8758 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java @@ -44,7 +44,6 @@ import com.android.systemui.keyguard.KeyguardUnlockAnimationController; import com.android.systemui.keyguard.KeyguardViewMediator; import com.android.systemui.keyguard.data.repository.KeyguardRepositoryModule; import com.android.systemui.keyguard.domain.quickaffordance.KeyguardQuickAffordanceModule; -import com.android.systemui.keyguard.domain.usecase.KeyguardUseCaseModule; import com.android.systemui.navigationbar.NavigationModeController; import com.android.systemui.statusbar.NotificationShadeDepthController; import com.android.systemui.statusbar.NotificationShadeWindowController; @@ -73,7 +72,6 @@ import dagger.Provides; FalsingModule.class, KeyguardQuickAffordanceModule.class, KeyguardRepositoryModule.class, - KeyguardUseCaseModule.class, }) public class KeyguardModule { /** diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardRepository.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardRepository.kt index 62cf1a624d9b8..e52d9ee7b9d45 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardRepository.kt @@ -18,7 +18,7 @@ package com.android.systemui.keyguard.data.repository import com.android.systemui.common.coroutine.ChannelExt.trySendWithFailureLogging import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow -import com.android.systemui.common.data.model.Position +import com.android.systemui.common.shared.model.Position import com.android.systemui.dagger.SysUISingleton import com.android.systemui.plugins.statusbar.StatusBarStateController import com.android.systemui.statusbar.policy.KeyguardStateController diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardBottomAreaInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardBottomAreaInteractor.kt new file mode 100644 index 0000000000000..ede50b068de35 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardBottomAreaInteractor.kt @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.android.systemui.keyguard.domain.interactor + +import com.android.systemui.common.shared.model.Position +import com.android.systemui.dagger.SysUISingleton +import com.android.systemui.keyguard.data.repository.KeyguardRepository +import javax.inject.Inject +import kotlinx.coroutines.flow.Flow + +/** Encapsulates business-logic specifically related to the keyguard bottom area. */ +@SysUISingleton +class KeyguardBottomAreaInteractor +@Inject +constructor( + private val repository: KeyguardRepository, +) { + /** Whether to animate the next doze mode transition. */ + val animateDozingTransitions: Flow = repository.animateBottomAreaDozingTransitions + /** The amount of alpha for the UI components of the bottom area. */ + val alpha: Flow = repository.bottomAreaAlpha + /** The position of the keyguard clock. */ + val clockPosition: Flow = repository.clockPosition + + fun setClockPosition(x: Int, y: Int) { + repository.setClockPosition(x, y) + } + + fun setAlpha(alpha: Float) { + repository.setBottomAreaAlpha(alpha) + } + + fun setAnimateDozingTransitions(animate: Boolean) { + repository.setAnimateDozingTransitions(animate) + } +} diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveIsKeyguardShowingUseCase.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractor.kt similarity index 53% rename from packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveIsKeyguardShowingUseCase.kt rename to packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractor.kt index 11af123c1650e..dccc94178ed5c 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveIsKeyguardShowingUseCase.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractor.kt @@ -15,25 +15,29 @@ * */ -package com.android.systemui.keyguard.domain.usecase +package com.android.systemui.keyguard.domain.interactor +import com.android.systemui.dagger.SysUISingleton import com.android.systemui.keyguard.data.repository.KeyguardRepository import javax.inject.Inject import kotlinx.coroutines.flow.Flow /** - * Use-case for observing whether the keyguard is currently being shown. - * - * Note: this is also `true` when the lock-screen is occluded with an `Activity` "above" it in the - * z-order (which is not really above the system UI window, but rather - the lock-screen becomes - * invisible to reveal the "occluding activity"). + * Encapsulates business-logic related to the keyguard but not to a more specific part within it. */ -class ObserveIsKeyguardShowingUseCase +@SysUISingleton +class KeyguardInteractor @Inject constructor( - private val repository: KeyguardRepository, + repository: KeyguardRepository, ) { - operator fun invoke(): Flow { - return repository.isKeyguardShowing - } + /** + * The amount of doze the system is in, where `1.0` is fully dozing and `0.0` is not dozing at + * all. + */ + val dozeAmount: Flow = repository.dozeAmount + /** Whether the system is in doze mode. */ + val isDozing: Flow = repository.isDozing + /** Whether the keyguard is showing ot not. */ + val isKeyguardShowing: Flow = repository.isKeyguardShowing } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardQuickAffordanceInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardQuickAffordanceInteractor.kt new file mode 100644 index 0000000000000..9a69e26488d97 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardQuickAffordanceInteractor.kt @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.android.systemui.keyguard.domain.interactor + +import android.content.Intent +import com.android.internal.widget.LockPatternUtils +import com.android.systemui.animation.ActivityLaunchAnimator +import com.android.systemui.dagger.SysUISingleton +import com.android.systemui.keyguard.domain.model.KeyguardQuickAffordanceModel +import com.android.systemui.keyguard.domain.model.KeyguardQuickAffordancePosition +import com.android.systemui.keyguard.domain.quickaffordance.KeyguardQuickAffordanceConfig +import com.android.systemui.keyguard.domain.quickaffordance.KeyguardQuickAffordanceRegistry +import com.android.systemui.plugins.ActivityStarter +import com.android.systemui.settings.UserTracker +import com.android.systemui.statusbar.policy.KeyguardStateController +import javax.inject.Inject +import kotlin.reflect.KClass +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.combine + +@SysUISingleton +class KeyguardQuickAffordanceInteractor +@Inject +constructor( + private val keyguardInteractor: KeyguardInteractor, + private val registry: KeyguardQuickAffordanceRegistry, + private val lockPatternUtils: LockPatternUtils, + private val keyguardStateController: KeyguardStateController, + private val userTracker: UserTracker, + private val activityStarter: ActivityStarter, +) { + /** Returns an observable for the quick affordance at the given position. */ + fun quickAffordance( + position: KeyguardQuickAffordancePosition + ): Flow { + return combine( + quickAffordanceInternal(position), + keyguardInteractor.isDozing, + keyguardInteractor.isKeyguardShowing, + ) { affordance, isDozing, isKeyguardShowing -> + if (!isDozing && isKeyguardShowing) { + affordance + } else { + KeyguardQuickAffordanceModel.Hidden + } + } + } + + /** + * Notifies that a quick affordance has been clicked by the user. + * + * @param configKey The configuration key corresponding to the [KeyguardQuickAffordanceModel] of + * the affordance that was clicked + * @param animationController An optional controller for the activity-launch animation + */ + fun onQuickAffordanceClicked( + configKey: KClass, + animationController: ActivityLaunchAnimator.Controller?, + ) { + @Suppress("UNCHECKED_CAST") val config = registry.get(configKey as KClass) + when (val result = config.onQuickAffordanceClicked(animationController)) { + is KeyguardQuickAffordanceConfig.OnClickedResult.StartActivity -> + launchQuickAffordance( + intent = result.intent, + canShowWhileLocked = result.canShowWhileLocked, + animationController = animationController + ) + is KeyguardQuickAffordanceConfig.OnClickedResult.Handled -> Unit + } + } + + private fun quickAffordanceInternal( + position: KeyguardQuickAffordancePosition + ): Flow { + val configs = registry.getAll(position) + return combine(configs.map { config -> config.state }) { states -> + val index = states.indexOfFirst { it is KeyguardQuickAffordanceConfig.State.Visible } + if (index != -1) { + val visibleState = states[index] as KeyguardQuickAffordanceConfig.State.Visible + KeyguardQuickAffordanceModel.Visible( + configKey = configs[index]::class, + icon = visibleState.icon, + contentDescriptionResourceId = visibleState.contentDescriptionResourceId, + ) + } else { + KeyguardQuickAffordanceModel.Hidden + } + } + } + + private fun launchQuickAffordance( + intent: Intent, + canShowWhileLocked: Boolean, + animationController: ActivityLaunchAnimator.Controller?, + ) { + @LockPatternUtils.StrongAuthTracker.StrongAuthFlags + val strongAuthFlags = + lockPatternUtils.getStrongAuthForUser(userTracker.userHandle.identifier) + val needsToUnlockFirst = + when { + strongAuthFlags == + LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT -> true + !canShowWhileLocked && !keyguardStateController.isUnlocked -> true + else -> false + } + if (needsToUnlockFirst) { + activityStarter.postStartActivityDismissingKeyguard( + intent, + 0 /* delay */, + animationController + ) + } else { + activityStarter.startActivity( + intent, + true /* dismissShade */, + animationController, + true /* showOverLockscreenWhenLocked */, + ) + } + } +} diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/model/KeyguardQuickAffordanceModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/model/KeyguardQuickAffordanceModel.kt index 411a2ca5ffe2a..eff146984176e 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/model/KeyguardQuickAffordanceModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/model/KeyguardQuickAffordanceModel.kt @@ -42,21 +42,4 @@ sealed class KeyguardQuickAffordanceModel { */ @StringRes val contentDescriptionResourceId: Int, ) : KeyguardQuickAffordanceModel() - - companion object { - fun from( - state: KeyguardQuickAffordanceConfig.State?, - configKey: KClass, - ): KeyguardQuickAffordanceModel { - return when (state) { - is KeyguardQuickAffordanceConfig.State.Visible -> - Visible( - configKey = configKey, - icon = state.icon, - contentDescriptionResourceId = state.contentDescriptionResourceId, - ) - else -> Hidden - } - } - } } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/quickaffordance/KeyguardQuickAffordanceModule.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/quickaffordance/KeyguardQuickAffordanceModule.kt index a7b38282d0aab..94024d4a0ace7 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/quickaffordance/KeyguardQuickAffordanceModule.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/quickaffordance/KeyguardQuickAffordanceModule.kt @@ -25,5 +25,5 @@ interface KeyguardQuickAffordanceModule { @Binds fun keyguardQuickAffordanceRegistry( impl: KeyguardQuickAffordanceRegistryImpl - ): KeyguardQuickAffordanceRegistry + ): KeyguardQuickAffordanceRegistry } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/quickaffordance/KeyguardQuickAffordanceRegistry.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/quickaffordance/KeyguardQuickAffordanceRegistry.kt index 2c37f93de4355..ad40ee7a01830 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/quickaffordance/KeyguardQuickAffordanceRegistry.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/quickaffordance/KeyguardQuickAffordanceRegistry.kt @@ -22,9 +22,9 @@ import javax.inject.Inject import kotlin.reflect.KClass /** Central registry of all known quick affordance configs. */ -interface KeyguardQuickAffordanceRegistry { - fun getAll(position: KeyguardQuickAffordancePosition): List - fun get(configClass: KClass): KeyguardQuickAffordanceConfig +interface KeyguardQuickAffordanceRegistry { + fun getAll(position: KeyguardQuickAffordancePosition): List + fun get(configClass: KClass): T } class KeyguardQuickAffordanceRegistryImpl @@ -33,7 +33,7 @@ constructor( homeControls: HomeControlsKeyguardQuickAffordanceConfig, quickAccessWallet: QuickAccessWalletKeyguardQuickAffordanceConfig, qrCodeScanner: QrCodeScannerKeyguardQuickAffordanceConfig, -) : KeyguardQuickAffordanceRegistry { +) : KeyguardQuickAffordanceRegistry { private val configsByPosition = mapOf( KeyguardQuickAffordancePosition.BOTTOM_START to diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/KeyguardUseCaseModule.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/KeyguardUseCaseModule.kt deleted file mode 100644 index 403d34352c7bc..0000000000000 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/KeyguardUseCaseModule.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.systemui.keyguard.domain.usecase - -import dagger.Binds -import dagger.Module - -@Module -interface KeyguardUseCaseModule { - - @Binds - fun launchQuickAffordance( - impl: LaunchKeyguardQuickAffordanceUseCaseImpl - ): LaunchKeyguardQuickAffordanceUseCase - - @Binds - fun observeKeyguardQuickAffordance( - impl: ObserveKeyguardQuickAffordanceUseCaseImpl - ): ObserveKeyguardQuickAffordanceUseCase -} diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/LaunchKeyguardQuickAffordanceUseCase.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/LaunchKeyguardQuickAffordanceUseCase.kt deleted file mode 100644 index 3d60399cf5227..0000000000000 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/LaunchKeyguardQuickAffordanceUseCase.kt +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.systemui.keyguard.domain.usecase - -import android.content.Intent -import com.android.internal.widget.LockPatternUtils -import com.android.internal.widget.LockPatternUtils.StrongAuthTracker.StrongAuthFlags -import com.android.systemui.animation.ActivityLaunchAnimator -import com.android.systemui.plugins.ActivityStarter -import com.android.systemui.settings.UserTracker -import com.android.systemui.statusbar.policy.KeyguardStateController -import javax.inject.Inject - -/** Defines interface for classes that can launch a quick affordance. */ -interface LaunchKeyguardQuickAffordanceUseCase { - operator fun invoke( - intent: Intent, - canShowWhileLocked: Boolean, - animationController: ActivityLaunchAnimator.Controller?, - ) -} - -/** Real implementation of [LaunchKeyguardQuickAffordanceUseCase] */ -class LaunchKeyguardQuickAffordanceUseCaseImpl -@Inject -constructor( - private val lockPatternUtils: LockPatternUtils, - private val keyguardStateController: KeyguardStateController, - private val userTracker: UserTracker, - private val activityStarter: ActivityStarter, -) : LaunchKeyguardQuickAffordanceUseCase { - override operator fun invoke( - intent: Intent, - canShowWhileLocked: Boolean, - animationController: ActivityLaunchAnimator.Controller?, - ) { - @StrongAuthFlags - val strongAuthFlags = - lockPatternUtils.getStrongAuthForUser(userTracker.userHandle.identifier) - val needsToUnlockFirst = - when { - strongAuthFlags == - LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT -> true - !canShowWhileLocked && !keyguardStateController.isUnlocked -> true - else -> false - } - if (needsToUnlockFirst) { - activityStarter.postStartActivityDismissingKeyguard( - intent, - 0 /* delay */, - animationController - ) - } else { - activityStarter.startActivity( - intent, - true /* dismissShade */, - animationController, - true /* showOverLockscreenWhenLocked */, - ) - } - } -} diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveAnimateBottomAreaTransitionsUseCase.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveAnimateBottomAreaTransitionsUseCase.kt deleted file mode 100644 index ca37727072f02..0000000000000 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveAnimateBottomAreaTransitionsUseCase.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.systemui.keyguard.domain.usecase - -import com.android.systemui.keyguard.data.repository.KeyguardRepository -import javax.inject.Inject -import kotlinx.coroutines.flow.Flow - -/** Use-case for observing whether doze state transitions should animate the bottom area */ -class ObserveAnimateBottomAreaTransitionsUseCase -@Inject -constructor( - private val repository: KeyguardRepository, -) { - operator fun invoke(): Flow { - return repository.animateBottomAreaDozingTransitions - } -} diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveBottomAreaAlphaUseCase.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveBottomAreaAlphaUseCase.kt deleted file mode 100644 index 151b704a017bd..0000000000000 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveBottomAreaAlphaUseCase.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.systemui.keyguard.domain.usecase - -import com.android.systemui.keyguard.data.repository.KeyguardRepository -import javax.inject.Inject -import kotlinx.coroutines.flow.Flow - -/** Use-case for observing the alpha of the bottom area */ -class ObserveBottomAreaAlphaUseCase -@Inject -constructor( - private val repository: KeyguardRepository, -) { - operator fun invoke(): Flow { - return repository.bottomAreaAlpha - } -} diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveClockPositionUseCase.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveClockPositionUseCase.kt deleted file mode 100644 index 02c573726db04..0000000000000 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveClockPositionUseCase.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.systemui.keyguard.domain.usecase - -import com.android.systemui.common.domain.model.Position -import com.android.systemui.common.domain.model.Position.Companion.toDomainLayer -import com.android.systemui.keyguard.data.repository.KeyguardRepository -import javax.inject.Inject -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.map - -/** Use-case for observing the position of the clock. */ -class ObserveClockPositionUseCase -@Inject -constructor( - private val repository: KeyguardRepository, -) { - operator fun invoke(): Flow { - return repository.clockPosition.map { it.toDomainLayer() } - } -} diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveDozeAmountUseCase.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveDozeAmountUseCase.kt deleted file mode 100644 index 56d61822a1210..0000000000000 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveDozeAmountUseCase.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.systemui.keyguard.domain.usecase - -import com.android.systemui.keyguard.data.repository.KeyguardRepository -import javax.inject.Inject -import kotlinx.coroutines.flow.Flow - -/** Use-case for observing the amount of doze the system is in. */ -class ObserveDozeAmountUseCase -@Inject -constructor( - private val repository: KeyguardRepository, -) { - operator fun invoke(): Flow { - return repository.dozeAmount - } -} diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveIsDozingUseCase.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveIsDozingUseCase.kt deleted file mode 100644 index 1d241d90ba5f0..0000000000000 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveIsDozingUseCase.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.systemui.keyguard.domain.usecase - -import com.android.systemui.keyguard.data.repository.KeyguardRepository -import javax.inject.Inject -import kotlinx.coroutines.flow.Flow - -/** Use-case for observing whether we are dozing. */ -class ObserveIsDozingUseCase -@Inject -constructor( - private val repository: KeyguardRepository, -) { - operator fun invoke(): Flow { - return repository.isDozing - } -} diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveKeyguardQuickAffordanceUseCase.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveKeyguardQuickAffordanceUseCase.kt deleted file mode 100644 index 8dee8b38bdb85..0000000000000 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveKeyguardQuickAffordanceUseCase.kt +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.systemui.keyguard.domain.usecase - -import com.android.systemui.keyguard.domain.model.KeyguardQuickAffordanceModel -import com.android.systemui.keyguard.domain.model.KeyguardQuickAffordancePosition -import com.android.systemui.keyguard.domain.quickaffordance.KeyguardQuickAffordanceConfig -import com.android.systemui.keyguard.domain.quickaffordance.KeyguardQuickAffordanceRegistry -import javax.inject.Inject -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.combine - -/** Defines interface for use-case for observing the model of a quick affordance in the keyguard. */ -interface ObserveKeyguardQuickAffordanceUseCase { - operator fun invoke( - position: KeyguardQuickAffordancePosition - ): Flow -} - -class ObserveKeyguardQuickAffordanceUseCaseImpl -@Inject -constructor( - private val registry: KeyguardQuickAffordanceRegistry, - private val isDozingUseCase: ObserveIsDozingUseCase, - private val isKeyguardShowingUseCase: ObserveIsKeyguardShowingUseCase, -) : ObserveKeyguardQuickAffordanceUseCase { - override fun invoke( - position: KeyguardQuickAffordancePosition - ): Flow { - return combine( - affordance(position), - isDozingUseCase(), - isKeyguardShowingUseCase(), - ) { affordance, isDozing, isKeyguardShowing -> - if (!isDozing && isKeyguardShowing) { - affordance - } else { - KeyguardQuickAffordanceModel.Hidden - } - } - } - - private fun affordance( - position: KeyguardQuickAffordancePosition - ): Flow { - val configs = registry.getAll(position) - return combine(configs.map { config -> config.state }) { states -> - val index = - states.indexOfFirst { state -> - state is KeyguardQuickAffordanceConfig.State.Visible - } - val visibleState = - if (index != -1) { - states[index] as KeyguardQuickAffordanceConfig.State.Visible - } else { - null - } - KeyguardQuickAffordanceModel.from(visibleState, configs[index]::class) - } - } -} diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/OnKeyguardQuickAffordanceClickedUseCase.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/OnKeyguardQuickAffordanceClickedUseCase.kt deleted file mode 100644 index 93153391ca419..0000000000000 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/OnKeyguardQuickAffordanceClickedUseCase.kt +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.systemui.keyguard.domain.usecase - -import com.android.systemui.animation.ActivityLaunchAnimator -import com.android.systemui.keyguard.domain.quickaffordance.KeyguardQuickAffordanceConfig -import com.android.systemui.keyguard.domain.quickaffordance.KeyguardQuickAffordanceConfig.OnClickedResult -import com.android.systemui.keyguard.domain.quickaffordance.KeyguardQuickAffordanceRegistry -import javax.inject.Inject -import kotlin.reflect.KClass - -/** Use-case for handling a click on a keyguard quick affordance (e.g. bottom button). */ -class OnKeyguardQuickAffordanceClickedUseCase -@Inject -constructor( - private val registry: KeyguardQuickAffordanceRegistry, - private val launchAffordanceUseCase: LaunchKeyguardQuickAffordanceUseCase, -) { - operator fun invoke( - configKey: KClass<*>, - animationController: ActivityLaunchAnimator.Controller?, - ) { - @Suppress("UNCHECKED_CAST") - val config = registry.get(configKey as KClass) - when (val result = config.onQuickAffordanceClicked(animationController)) { - is OnClickedResult.StartActivity -> - launchAffordanceUseCase( - intent = result.intent, - canShowWhileLocked = result.canShowWhileLocked, - animationController = animationController - ) - is OnClickedResult.Handled -> Unit - } - } -} diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/SetClockPositionUseCase.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/SetClockPositionUseCase.kt deleted file mode 100644 index 8f746e5765afd..0000000000000 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/SetClockPositionUseCase.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.systemui.keyguard.domain.usecase - -import com.android.systemui.keyguard.data.repository.KeyguardRepository -import javax.inject.Inject - -/** Use-case for setting the updated clock position. */ -class SetClockPositionUseCase -@Inject -constructor( - private val keyguardRepository: KeyguardRepository, -) { - operator fun invoke(x: Int, y: Int) { - keyguardRepository.setClockPosition(x, y) - } -} diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/SetKeyguardBottomAreaAlphaUseCase.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/SetKeyguardBottomAreaAlphaUseCase.kt deleted file mode 100644 index 90be1ecded507..0000000000000 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/SetKeyguardBottomAreaAlphaUseCase.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.systemui.keyguard.domain.usecase - -import com.android.systemui.keyguard.data.repository.KeyguardRepository -import javax.inject.Inject - -/** Use-case for setting the alpha that the keyguard bottom area should use */ -class SetKeyguardBottomAreaAlphaUseCase -@Inject -constructor( - private val repository: KeyguardRepository, -) { - operator fun invoke(alpha: Float) { - repository.setBottomAreaAlpha(alpha) - } -} diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/SetKeyguardBottomAreaAnimateDozingTransitionsUseCase.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/SetKeyguardBottomAreaAnimateDozingTransitionsUseCase.kt deleted file mode 100644 index 007780a6860a1..0000000000000 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/SetKeyguardBottomAreaAnimateDozingTransitionsUseCase.kt +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.systemui.keyguard.domain.usecase - -import com.android.systemui.keyguard.data.repository.KeyguardRepository -import javax.inject.Inject - -/** - * Use-case for setting whether the keyguard bottom area should animate the next doze transitions - */ -class SetKeyguardBottomAreaAnimateDozingTransitionsUseCase -@Inject -constructor( - private val repository: KeyguardRepository, -) { - operator fun invoke(animate: Boolean) { - repository.setAnimateDozingTransitions(animate) - } -} diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBottomAreaViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBottomAreaViewModel.kt index d296e76482ada..e987127335f33 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBottomAreaViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBottomAreaViewModel.kt @@ -17,15 +17,11 @@ package com.android.systemui.keyguard.ui.viewmodel import com.android.systemui.doze.util.BurnInHelperWrapper +import com.android.systemui.keyguard.domain.interactor.KeyguardBottomAreaInteractor +import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor +import com.android.systemui.keyguard.domain.interactor.KeyguardQuickAffordanceInteractor import com.android.systemui.keyguard.domain.model.KeyguardQuickAffordanceModel import com.android.systemui.keyguard.domain.model.KeyguardQuickAffordancePosition -import com.android.systemui.keyguard.domain.usecase.ObserveAnimateBottomAreaTransitionsUseCase -import com.android.systemui.keyguard.domain.usecase.ObserveBottomAreaAlphaUseCase -import com.android.systemui.keyguard.domain.usecase.ObserveClockPositionUseCase -import com.android.systemui.keyguard.domain.usecase.ObserveDozeAmountUseCase -import com.android.systemui.keyguard.domain.usecase.ObserveIsDozingUseCase -import com.android.systemui.keyguard.domain.usecase.ObserveKeyguardQuickAffordanceUseCase -import com.android.systemui.keyguard.domain.usecase.OnKeyguardQuickAffordanceClickedUseCase import javax.inject.Inject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine @@ -36,13 +32,9 @@ import kotlinx.coroutines.flow.map class KeyguardBottomAreaViewModel @Inject constructor( - private val observeQuickAffordanceUseCase: ObserveKeyguardQuickAffordanceUseCase, - private val onQuickAffordanceClickedUseCase: OnKeyguardQuickAffordanceClickedUseCase, - observeBottomAreaAlphaUseCase: ObserveBottomAreaAlphaUseCase, - observeIsDozingUseCase: ObserveIsDozingUseCase, - observeAnimateBottomAreaTransitionsUseCase: ObserveAnimateBottomAreaTransitionsUseCase, - private val observeDozeAmountUseCase: ObserveDozeAmountUseCase, - observeClockPositionUseCase: ObserveClockPositionUseCase, + private val keyguardInteractor: KeyguardInteractor, + private val quickAffordanceInteractor: KeyguardQuickAffordanceInteractor, + bottomAreaInteractor: KeyguardBottomAreaInteractor, private val burnInHelperWrapper: BurnInHelperWrapper, ) { /** An observable for the view-model of the "start button" quick affordance. */ @@ -56,12 +48,12 @@ constructor( * animate. */ val animateButtonReveal: Flow = - observeAnimateBottomAreaTransitionsUseCase().distinctUntilChanged() + bottomAreaInteractor.animateDozingTransitions.distinctUntilChanged() /** An observable for whether the overlay container should be visible. */ val isOverlayContainerVisible: Flow = - observeIsDozingUseCase().map { !it }.distinctUntilChanged() + keyguardInteractor.isDozing.map { !it }.distinctUntilChanged() /** An observable for the alpha level for the entire bottom area. */ - val alpha: Flow = observeBottomAreaAlphaUseCase().distinctUntilChanged() + val alpha: Flow = bottomAreaInteractor.alpha.distinctUntilChanged() /** An observable for whether the indication area should be padded. */ val isIndicationAreaPadded: Flow = combine(startButton, endButton) { startButtonModel, endButtonModel -> @@ -70,11 +62,11 @@ constructor( .distinctUntilChanged() /** An observable for the x-offset by which the indication area should be translated. */ val indicationAreaTranslationX: Flow = - observeClockPositionUseCase().map { it.x.toFloat() }.distinctUntilChanged() + bottomAreaInteractor.clockPosition.map { it.x.toFloat() }.distinctUntilChanged() /** Returns an observable for the y-offset by which the indication area should be translated. */ fun indicationAreaTranslationY(defaultBurnInOffset: Int): Flow { - return observeDozeAmountUseCase() + return keyguardInteractor.dozeAmount .map { dozeAmount -> dozeAmount * (burnInHelperWrapper.burnInOffset( @@ -88,7 +80,8 @@ constructor( private fun button( position: KeyguardQuickAffordancePosition ): Flow { - return observeQuickAffordanceUseCase(position) + return quickAffordanceInteractor + .quickAffordance(position) .map { model -> model.toViewModel() } .distinctUntilChanged() } @@ -102,7 +95,7 @@ constructor( icon = icon, contentDescriptionResourceId = contentDescriptionResourceId, onClicked = { parameters -> - onQuickAffordanceClickedUseCase( + quickAffordanceInteractor.onQuickAffordanceClicked( configKey = parameters.configKey, animationController = parameters.animationController, ) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordanceViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordanceViewModel.kt index 2417998784e4b..e637260554512 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordanceViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordanceViewModel.kt @@ -19,18 +19,19 @@ package com.android.systemui.keyguard.ui.viewmodel import androidx.annotation.StringRes import com.android.systemui.animation.ActivityLaunchAnimator import com.android.systemui.containeddrawable.ContainedDrawable +import com.android.systemui.keyguard.domain.quickaffordance.KeyguardQuickAffordanceConfig import kotlin.reflect.KClass /** Models the UI state of a keyguard quick affordance button. */ data class KeyguardQuickAffordanceViewModel( - val configKey: KClass<*>? = null, + val configKey: KClass? = null, val isVisible: Boolean = false, val icon: ContainedDrawable = ContainedDrawable.WithResource(0), @StringRes val contentDescriptionResourceId: Int = 0, val onClicked: (OnClickedParameters) -> Unit = {}, ) { data class OnClickedParameters( - val configKey: KClass<*>, + val configKey: KClass, val animationController: ActivityLaunchAnimator.Controller?, ) } diff --git a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java index 4b8379a67ac70..a353e8fee9458 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java +++ b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java @@ -127,9 +127,7 @@ import com.android.systemui.flags.Flags; import com.android.systemui.fragments.FragmentHostManager.FragmentListener; import com.android.systemui.fragments.FragmentService; import com.android.systemui.keyguard.KeyguardUnlockAnimationController; -import com.android.systemui.keyguard.domain.usecase.SetClockPositionUseCase; -import com.android.systemui.keyguard.domain.usecase.SetKeyguardBottomAreaAlphaUseCase; -import com.android.systemui.keyguard.domain.usecase.SetKeyguardBottomAreaAnimateDozingTransitionsUseCase; +import com.android.systemui.keyguard.domain.interactor.KeyguardBottomAreaInteractor; import com.android.systemui.keyguard.ui.viewmodel.KeyguardBottomAreaViewModel; import com.android.systemui.media.KeyguardMediaController; import com.android.systemui.media.MediaDataManager; @@ -705,11 +703,7 @@ public final class NotificationPanelViewController extends PanelViewController { private final CameraGestureHelper mCameraGestureHelper; private final Provider mKeyguardBottomAreaViewModelProvider; - private final Provider mSetClockPositionUseCaseProvider; - private final Provider - mSetKeyguardBottomAreaAlphaUseCaseProvider; - private final Provider - mSetKeyguardBottomAreaAnimateDozingTransitionsUseCaseProvider; + private final Provider mKeyguardBottomAreaInteractorProvider; @Inject public NotificationPanelViewController(NotificationPanelView view, @@ -781,10 +775,7 @@ public final class NotificationPanelViewController extends PanelViewController { SystemClock systemClock, CameraGestureHelper cameraGestureHelper, Provider keyguardBottomAreaViewModelProvider, - Provider setClockPositionUseCaseProvider, - Provider setKeyguardBottomAreaAlphaUseCaseProvider, - Provider - setKeyguardBottomAreaAnimateDozingTransitionsUseCaseProvider) { + Provider keyguardBottomAreaInteractorProvider) { super(view, falsingManager, dozeLog, @@ -966,10 +957,7 @@ public final class NotificationPanelViewController extends PanelViewController { } }); mCameraGestureHelper = cameraGestureHelper; - mSetClockPositionUseCaseProvider = setClockPositionUseCaseProvider; - mSetKeyguardBottomAreaAlphaUseCaseProvider = setKeyguardBottomAreaAlphaUseCaseProvider; - mSetKeyguardBottomAreaAnimateDozingTransitionsUseCaseProvider = - setKeyguardBottomAreaAnimateDozingTransitionsUseCaseProvider; + mKeyguardBottomAreaInteractorProvider = keyguardBottomAreaInteractorProvider; } @VisibleForTesting @@ -1487,7 +1475,7 @@ public final class NotificationPanelViewController extends PanelViewController { mKeyguardStatusViewController.getClockBottom(mStatusBarHeaderHeightKeyguard), mKeyguardStatusViewController.isClockTopAligned()); mClockPositionAlgorithm.run(mClockPositionResult); - mSetClockPositionUseCaseProvider.get().invoke( + mKeyguardBottomAreaInteractorProvider.get().setClockPosition( mClockPositionResult.clockX, mClockPositionResult.clockY); boolean animate = mNotificationStackScrollLayoutController.isAddOrRemoveAnimationPending(); boolean animateClock = (animate || mAnimateNextPositionUpdate) && shouldAnimateClockChange; @@ -3261,7 +3249,7 @@ public final class NotificationPanelViewController extends PanelViewController { float alpha = Math.min(expansionAlpha, 1 - computeQsExpansionFraction()); alpha *= mBottomAreaShadeAlpha; mKeyguardBottomArea.setComponentAlphas(alpha); - mSetKeyguardBottomAreaAlphaUseCaseProvider.get().invoke(alpha); + mKeyguardBottomAreaInteractorProvider.get().setAlpha(alpha); mLockIconViewController.setAlpha(alpha); } @@ -3461,7 +3449,7 @@ public final class NotificationPanelViewController extends PanelViewController { private void updateDozingVisibilities(boolean animate) { mKeyguardBottomArea.setDozing(mDozing, animate); - mSetKeyguardBottomAreaAnimateDozingTransitionsUseCaseProvider.get().invoke(animate); + mKeyguardBottomAreaInteractorProvider.get().setAnimateDozingTransitions(animate); if (!mDozing && animate) { mKeyguardStatusBarViewController.animateKeyguardStatusBarIn(); } @@ -3764,7 +3752,7 @@ public final class NotificationPanelViewController extends PanelViewController { mDozing = dozing; mNotificationStackScrollLayoutController.setDozing(mDozing, animate, wakeUpTouchLocation); mKeyguardBottomArea.setDozing(mDozing, animate); - mSetKeyguardBottomAreaAnimateDozingTransitionsUseCaseProvider.get().invoke(animate); + mKeyguardBottomAreaInteractorProvider.get().setAnimateDozingTransitions(animate); mKeyguardStatusBarViewController.setDozing(mDozing); if (dozing) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/FakeKeyguardRepository.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/FakeKeyguardRepository.kt index 38a3375631653..11eb4e3de3540 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/FakeKeyguardRepository.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/FakeKeyguardRepository.kt @@ -16,11 +16,10 @@ package com.android.systemui.keyguard.data.repository -import com.android.systemui.common.data.model.Position +import com.android.systemui.common.shared.model.Position import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.yield /** Fake implementation of [KeyguardRepository] */ class FakeKeyguardRepository : KeyguardRepository { @@ -56,30 +55,15 @@ class FakeKeyguardRepository : KeyguardRepository { _clockPosition.value = Position(x, y) } - suspend fun setKeyguardShowing(isShowing: Boolean) { + fun setKeyguardShowing(isShowing: Boolean) { _isKeyguardShowing.value = isShowing - // Yield to allow the test's collection coroutine to "catch up" and collect this value - // before the test continues to the next line. - // TODO(b/239834928): once coroutines.test is updated, switch to the approach described in - // https://developer.android.com/kotlin/flow/test#continuous-collection and remove this. - yield() } - suspend fun setDozing(isDozing: Boolean) { + fun setDozing(isDozing: Boolean) { _isDozing.value = isDozing - // Yield to allow the test's collection coroutine to "catch up" and collect this value - // before the test continues to the next line. - // TODO(b/239834928): once coroutines.test is updated, switch to the approach described in - // https://developer.android.com/kotlin/flow/test#continuous-collection and remove this. - yield() } - suspend fun setDozeAmount(dozeAmount: Float) { + fun setDozeAmount(dozeAmount: Float) { _dozeAmount.value = dozeAmount - // Yield to allow the test's collection coroutine to "catch up" and collect this value - // before the test continues to the next line. - // TODO(b/239834928): once coroutines.test is updated, switch to the approach described in - // https://developer.android.com/kotlin/flow/test#continuous-collection and remove this. - yield() } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardRepositoryImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardRepositoryImplTest.kt index 3d2c51a449c7f..3aa22669bbf24 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardRepositoryImplTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardRepositoryImplTest.kt @@ -18,7 +18,7 @@ package com.android.systemui.keyguard.data.repository import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase -import com.android.systemui.common.data.model.Position +import com.android.systemui.common.shared.model.Position import com.android.systemui.plugins.statusbar.StatusBarStateController import com.android.systemui.statusbar.policy.KeyguardStateController import com.android.systemui.util.mockito.argumentCaptor diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/quickaffordance/FakeKeyguardQuickAffordanceRegistry.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/quickaffordance/FakeKeyguardQuickAffordanceRegistry.kt index 1c9902b365176..e68c43f4abd7f 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/quickaffordance/FakeKeyguardQuickAffordanceRegistry.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/quickaffordance/FakeKeyguardQuickAffordanceRegistry.kt @@ -23,18 +23,18 @@ import kotlin.reflect.KClass /** Fake implementation of [FakeKeyguardQuickAffordanceRegistry], for tests. */ class FakeKeyguardQuickAffordanceRegistry( private val configsByPosition: - Map>, -) : KeyguardQuickAffordanceRegistry { + Map>, +) : KeyguardQuickAffordanceRegistry { override fun getAll( position: KeyguardQuickAffordancePosition - ): List { + ): List { return configsByPosition.getValue(position) } override fun get( - configClass: KClass - ): KeyguardQuickAffordanceConfig { + configClass: KClass + ): FakeKeyguardQuickAffordanceConfig { return configsByPosition.values .flatten() .associateBy { config -> config::class } diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/usecase/FakeLaunchKeyguardQuickAffordanceUseCase.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/usecase/FakeLaunchKeyguardQuickAffordanceUseCase.kt deleted file mode 100644 index ba0c31ffa9c92..0000000000000 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/usecase/FakeLaunchKeyguardQuickAffordanceUseCase.kt +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.systemui.keyguard.domain.usecase - -import android.content.Intent -import com.android.systemui.animation.ActivityLaunchAnimator - -/** Fake implementation of [LaunchKeyguardQuickAffordanceUseCase], for tests. */ -class FakeLaunchKeyguardQuickAffordanceUseCase : LaunchKeyguardQuickAffordanceUseCase { - - data class Invocation( - val intent: Intent, - val canShowWhileLocked: Boolean, - val animationController: ActivityLaunchAnimator.Controller? - ) - - private val _invocations = mutableListOf() - val invocations: List = _invocations - - override fun invoke( - intent: Intent, - canShowWhileLocked: Boolean, - animationController: ActivityLaunchAnimator.Controller? - ) { - _invocations.add( - Invocation( - intent = intent, - canShowWhileLocked = canShowWhileLocked, - animationController = animationController, - ) - ) - } -} diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/usecase/FakeObserveKeyguardQuickAffordanceUseCase.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/usecase/FakeObserveKeyguardQuickAffordanceUseCase.kt deleted file mode 100644 index 8982752c9fcc2..0000000000000 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/usecase/FakeObserveKeyguardQuickAffordanceUseCase.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package com.android.systemui.keyguard.domain.usecase - -import com.android.systemui.keyguard.domain.model.KeyguardQuickAffordanceModel -import com.android.systemui.keyguard.domain.model.KeyguardQuickAffordancePosition -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.MutableStateFlow - -class FakeObserveKeyguardQuickAffordanceUseCase : ObserveKeyguardQuickAffordanceUseCase { - - private val affordanceByPosition = - mutableMapOf< - KeyguardQuickAffordancePosition, MutableStateFlow>() - - init { - KeyguardQuickAffordancePosition.values().forEach { position -> - affordanceByPosition[position] = MutableStateFlow(KeyguardQuickAffordanceModel.Hidden) - } - } - - override fun invoke( - position: KeyguardQuickAffordancePosition - ): Flow { - return affordanceByPosition[position] ?: error("Flow unexpectedly missing!") - } - - fun setModel(position: KeyguardQuickAffordancePosition, model: KeyguardQuickAffordanceModel) { - affordanceByPosition[position]?.value = model - } -} diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/usecase/KeyguardQuickAffordanceInteractorParameterizedTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/usecase/KeyguardQuickAffordanceInteractorParameterizedTest.kt new file mode 100644 index 0000000000000..c5e828eadf9b5 --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/usecase/KeyguardQuickAffordanceInteractorParameterizedTest.kt @@ -0,0 +1,294 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.keyguard.domain.usecase + +import android.content.Intent +import androidx.test.filters.SmallTest +import com.android.internal.widget.LockPatternUtils +import com.android.systemui.SysuiTestCase +import com.android.systemui.animation.ActivityLaunchAnimator +import com.android.systemui.containeddrawable.ContainedDrawable +import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository +import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor +import com.android.systemui.keyguard.domain.interactor.KeyguardQuickAffordanceInteractor +import com.android.systemui.keyguard.domain.model.KeyguardQuickAffordancePosition +import com.android.systemui.keyguard.domain.quickaffordance.FakeKeyguardQuickAffordanceConfig +import com.android.systemui.keyguard.domain.quickaffordance.FakeKeyguardQuickAffordanceRegistry +import com.android.systemui.keyguard.domain.quickaffordance.KeyguardQuickAffordanceConfig +import com.android.systemui.plugins.ActivityStarter +import com.android.systemui.settings.UserTracker +import com.android.systemui.statusbar.policy.KeyguardStateController +import com.android.systemui.util.mockito.any +import com.android.systemui.util.mockito.mock +import kotlinx.coroutines.test.runBlockingTest +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.Parameterized +import org.junit.runners.Parameterized.Parameter +import org.junit.runners.Parameterized.Parameters +import org.mockito.ArgumentMatchers.eq +import org.mockito.ArgumentMatchers.same +import org.mockito.Mock +import org.mockito.Mockito.verify +import org.mockito.Mockito.verifyZeroInteractions +import org.mockito.Mockito.`when` as whenever +import org.mockito.MockitoAnnotations + +@SmallTest +@RunWith(Parameterized::class) +class KeyguardQuickAffordanceInteractorParameterizedTest : SysuiTestCase() { + + companion object { + private val INTENT = Intent("some.intent.action") + private val DRAWABLE = mock() + private const val CONTENT_DESCRIPTION_RESOURCE_ID = 1337 + + @Parameters( + name = + "needStrongAuthAfterBoot={0}, canShowWhileLocked={1}," + + " keyguardIsUnlocked={2}, needsToUnlockFirst={3}, startActivity={4}" + ) + @JvmStatic + fun data() = + listOf( + arrayOf( + /* needStrongAuthAfterBoot= */ false, + /* canShowWhileLocked= */ false, + /* keyguardIsUnlocked= */ false, + /* needsToUnlockFirst= */ true, + /* startActivity= */ false, + ), + arrayOf( + /* needStrongAuthAfterBoot= */ false, + /* canShowWhileLocked= */ false, + /* keyguardIsUnlocked= */ true, + /* needsToUnlockFirst= */ false, + /* startActivity= */ false, + ), + arrayOf( + /* needStrongAuthAfterBoot= */ false, + /* canShowWhileLocked= */ true, + /* keyguardIsUnlocked= */ false, + /* needsToUnlockFirst= */ false, + /* startActivity= */ false, + ), + arrayOf( + /* needStrongAuthAfterBoot= */ false, + /* canShowWhileLocked= */ true, + /* keyguardIsUnlocked= */ true, + /* needsToUnlockFirst= */ false, + /* startActivity= */ false, + ), + arrayOf( + /* needStrongAuthAfterBoot= */ true, + /* canShowWhileLocked= */ false, + /* keyguardIsUnlocked= */ false, + /* needsToUnlockFirst= */ true, + /* startActivity= */ false, + ), + arrayOf( + /* needStrongAuthAfterBoot= */ true, + /* canShowWhileLocked= */ false, + /* keyguardIsUnlocked= */ true, + /* needsToUnlockFirst= */ true, + /* startActivity= */ false, + ), + arrayOf( + /* needStrongAuthAfterBoot= */ true, + /* canShowWhileLocked= */ true, + /* keyguardIsUnlocked= */ false, + /* needsToUnlockFirst= */ true, + /* startActivity= */ false, + ), + arrayOf( + /* needStrongAuthAfterBoot= */ true, + /* canShowWhileLocked= */ true, + /* keyguardIsUnlocked= */ true, + /* needsToUnlockFirst= */ true, + /* startActivity= */ false, + ), + arrayOf( + /* needStrongAuthAfterBoot= */ false, + /* canShowWhileLocked= */ false, + /* keyguardIsUnlocked= */ false, + /* needsToUnlockFirst= */ true, + /* startActivity= */ true, + ), + arrayOf( + /* needStrongAuthAfterBoot= */ false, + /* canShowWhileLocked= */ false, + /* keyguardIsUnlocked= */ true, + /* needsToUnlockFirst= */ false, + /* startActivity= */ true, + ), + arrayOf( + /* needStrongAuthAfterBoot= */ false, + /* canShowWhileLocked= */ true, + /* keyguardIsUnlocked= */ false, + /* needsToUnlockFirst= */ false, + /* startActivity= */ true, + ), + arrayOf( + /* needStrongAuthAfterBoot= */ false, + /* canShowWhileLocked= */ true, + /* keyguardIsUnlocked= */ true, + /* needsToUnlockFirst= */ false, + /* startActivity= */ true, + ), + arrayOf( + /* needStrongAuthAfterBoot= */ true, + /* canShowWhileLocked= */ false, + /* keyguardIsUnlocked= */ false, + /* needsToUnlockFirst= */ true, + /* startActivity= */ true, + ), + arrayOf( + /* needStrongAuthAfterBoot= */ true, + /* canShowWhileLocked= */ false, + /* keyguardIsUnlocked= */ true, + /* needsToUnlockFirst= */ true, + /* startActivity= */ true, + ), + arrayOf( + /* needStrongAuthAfterBoot= */ true, + /* canShowWhileLocked= */ true, + /* keyguardIsUnlocked= */ false, + /* needsToUnlockFirst= */ true, + /* startActivity= */ true, + ), + arrayOf( + /* needStrongAuthAfterBoot= */ true, + /* canShowWhileLocked= */ true, + /* keyguardIsUnlocked= */ true, + /* needsToUnlockFirst= */ true, + /* startActivity= */ true, + ), + ) + } + + @Mock private lateinit var lockPatternUtils: LockPatternUtils + @Mock private lateinit var keyguardStateController: KeyguardStateController + @Mock private lateinit var userTracker: UserTracker + @Mock private lateinit var activityStarter: ActivityStarter + @Mock private lateinit var animationController: ActivityLaunchAnimator.Controller + + private lateinit var underTest: KeyguardQuickAffordanceInteractor + + @JvmField @Parameter(0) var needStrongAuthAfterBoot: Boolean = false + @JvmField @Parameter(1) var canShowWhileLocked: Boolean = false + @JvmField @Parameter(2) var keyguardIsUnlocked: Boolean = false + @JvmField @Parameter(3) var needsToUnlockFirst: Boolean = false + @JvmField @Parameter(4) var startActivity: Boolean = false + private lateinit var homeControls: FakeKeyguardQuickAffordanceConfig + + @Before + fun setUp() { + MockitoAnnotations.initMocks(this) + + homeControls = object : FakeKeyguardQuickAffordanceConfig() {} + underTest = + KeyguardQuickAffordanceInteractor( + keyguardInteractor = KeyguardInteractor(repository = FakeKeyguardRepository()), + registry = + FakeKeyguardQuickAffordanceRegistry( + mapOf( + KeyguardQuickAffordancePosition.BOTTOM_START to + listOf( + homeControls, + ), + KeyguardQuickAffordancePosition.BOTTOM_END to + listOf( + object : FakeKeyguardQuickAffordanceConfig() {}, + object : FakeKeyguardQuickAffordanceConfig() {}, + ), + ), + ), + lockPatternUtils = lockPatternUtils, + keyguardStateController = keyguardStateController, + userTracker = userTracker, + activityStarter = activityStarter, + ) + } + + @Test + fun onQuickAffordanceClicked() = runBlockingTest { + setUpMocks( + needStrongAuthAfterBoot = needStrongAuthAfterBoot, + keyguardIsUnlocked = keyguardIsUnlocked, + ) + + homeControls.setState( + state = + KeyguardQuickAffordanceConfig.State.Visible( + icon = DRAWABLE, + contentDescriptionResourceId = CONTENT_DESCRIPTION_RESOURCE_ID, + ) + ) + homeControls.onClickedResult = + if (startActivity) { + KeyguardQuickAffordanceConfig.OnClickedResult.StartActivity( + intent = INTENT, + canShowWhileLocked = canShowWhileLocked, + ) + } else { + KeyguardQuickAffordanceConfig.OnClickedResult.Handled + } + + underTest.onQuickAffordanceClicked( + configKey = homeControls::class, + animationController = animationController, + ) + + if (startActivity) { + if (needsToUnlockFirst) { + verify(activityStarter) + .postStartActivityDismissingKeyguard( + any(), + /* delay= */ eq(0), + same(animationController), + ) + } else { + verify(activityStarter) + .startActivity( + any(), + /* dismissShade= */ eq(true), + same(animationController), + /* showOverLockscreenWhenLocked= */ eq(true), + ) + } + } else { + verifyZeroInteractions(activityStarter) + } + } + + private fun setUpMocks( + needStrongAuthAfterBoot: Boolean = true, + keyguardIsUnlocked: Boolean = false, + ) { + whenever(userTracker.userHandle).thenReturn(mock()) + whenever(lockPatternUtils.getStrongAuthForUser(any())) + .thenReturn( + if (needStrongAuthAfterBoot) { + LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT + } else { + LockPatternUtils.StrongAuthTracker.STRONG_AUTH_NOT_REQUIRED + } + ) + whenever(keyguardStateController.isUnlocked).thenReturn(keyguardIsUnlocked) + } +} diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/usecase/ObserveKeyguardQuickAffordanceUseCaseImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/usecase/KeyguardQuickAffordanceInteractorTest.kt similarity index 74% rename from packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/usecase/ObserveKeyguardQuickAffordanceUseCaseImplTest.kt rename to packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/usecase/KeyguardQuickAffordanceInteractorTest.kt index 63eb68f423ee9..d3fc29f1a0f17 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/usecase/ObserveKeyguardQuickAffordanceUseCaseImplTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/usecase/KeyguardQuickAffordanceInteractorTest.kt @@ -17,14 +17,20 @@ package com.android.systemui.keyguard.domain.usecase import androidx.test.filters.SmallTest +import com.android.internal.widget.LockPatternUtils import com.android.systemui.SysuiTestCase import com.android.systemui.containeddrawable.ContainedDrawable import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository +import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor +import com.android.systemui.keyguard.domain.interactor.KeyguardQuickAffordanceInteractor import com.android.systemui.keyguard.domain.model.KeyguardQuickAffordanceModel import com.android.systemui.keyguard.domain.model.KeyguardQuickAffordancePosition import com.android.systemui.keyguard.domain.quickaffordance.FakeKeyguardQuickAffordanceConfig import com.android.systemui.keyguard.domain.quickaffordance.FakeKeyguardQuickAffordanceRegistry import com.android.systemui.keyguard.domain.quickaffordance.KeyguardQuickAffordanceConfig +import com.android.systemui.plugins.ActivityStarter +import com.android.systemui.settings.UserTracker +import com.android.systemui.statusbar.policy.KeyguardStateController import com.android.systemui.util.mockito.mock import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.flow.launchIn @@ -34,33 +40,39 @@ import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 +import org.mockito.Mock +import org.mockito.MockitoAnnotations @SmallTest @RunWith(JUnit4::class) -class ObserveKeyguardQuickAffordanceUseCaseImplTest : SysuiTestCase() { +class KeyguardQuickAffordanceInteractorTest : SysuiTestCase() { - private lateinit var underTest: ObserveKeyguardQuickAffordanceUseCase + @Mock private lateinit var lockPatternUtils: LockPatternUtils + @Mock private lateinit var keyguardStateController: KeyguardStateController + @Mock private lateinit var userTracker: UserTracker + @Mock private lateinit var activityStarter: ActivityStarter + + private lateinit var underTest: KeyguardQuickAffordanceInteractor private lateinit var repository: FakeKeyguardRepository - private lateinit var isDozingUseCase: ObserveIsDozingUseCase - private lateinit var isKeyguardShowingUseCase: ObserveIsKeyguardShowingUseCase private lateinit var homeControls: FakeKeyguardQuickAffordanceConfig private lateinit var quickAccessWallet: FakeKeyguardQuickAffordanceConfig private lateinit var qrCodeScanner: FakeKeyguardQuickAffordanceConfig @Before - fun setUp() = runBlockingTest { + fun setUp() { + MockitoAnnotations.initMocks(this) + repository = FakeKeyguardRepository() repository.setKeyguardShowing(true) - isDozingUseCase = ObserveIsDozingUseCase(repository) - isKeyguardShowingUseCase = ObserveIsKeyguardShowingUseCase(repository) homeControls = object : FakeKeyguardQuickAffordanceConfig() {} quickAccessWallet = object : FakeKeyguardQuickAffordanceConfig() {} qrCodeScanner = object : FakeKeyguardQuickAffordanceConfig() {} underTest = - ObserveKeyguardQuickAffordanceUseCaseImpl( + KeyguardQuickAffordanceInteractor( + keyguardInteractor = KeyguardInteractor(repository = repository), registry = FakeKeyguardQuickAffordanceRegistry( mapOf( @@ -75,13 +87,15 @@ class ObserveKeyguardQuickAffordanceUseCaseImplTest : SysuiTestCase() { ), ), ), - isDozingUseCase = isDozingUseCase, - isKeyguardShowingUseCase = isKeyguardShowingUseCase, + lockPatternUtils = lockPatternUtils, + keyguardStateController = keyguardStateController, + userTracker = userTracker, + activityStarter = activityStarter, ) } @Test - fun `invoke - bottom start affordance is visible`() = runBlockingTest { + fun `quickAffordance - bottom start affordance is visible`() = runBlockingTest { val configKey = homeControls::class homeControls.setState( KeyguardQuickAffordanceConfig.State.Visible( @@ -92,7 +106,8 @@ class ObserveKeyguardQuickAffordanceUseCaseImplTest : SysuiTestCase() { var latest: KeyguardQuickAffordanceModel? = null val job = - underTest(KeyguardQuickAffordancePosition.BOTTOM_START) + underTest + .quickAffordance(KeyguardQuickAffordancePosition.BOTTOM_START) .onEach { latest = it } .launchIn(this) @@ -106,7 +121,7 @@ class ObserveKeyguardQuickAffordanceUseCaseImplTest : SysuiTestCase() { } @Test - fun `invoke - bottom end affordance is visible`() = runBlockingTest { + fun `quickAffordance - bottom end affordance is visible`() = runBlockingTest { val configKey = quickAccessWallet::class quickAccessWallet.setState( KeyguardQuickAffordanceConfig.State.Visible( @@ -117,7 +132,8 @@ class ObserveKeyguardQuickAffordanceUseCaseImplTest : SysuiTestCase() { var latest: KeyguardQuickAffordanceModel? = null val job = - underTest(KeyguardQuickAffordancePosition.BOTTOM_END) + underTest + .quickAffordance(KeyguardQuickAffordancePosition.BOTTOM_END) .onEach { latest = it } .launchIn(this) @@ -131,7 +147,7 @@ class ObserveKeyguardQuickAffordanceUseCaseImplTest : SysuiTestCase() { } @Test - fun `invoke - bottom start affordance hidden while dozing`() = runBlockingTest { + fun `quickAffordance - bottom start affordance hidden while dozing`() = runBlockingTest { repository.setDozing(true) homeControls.setState( KeyguardQuickAffordanceConfig.State.Visible( @@ -142,7 +158,8 @@ class ObserveKeyguardQuickAffordanceUseCaseImplTest : SysuiTestCase() { var latest: KeyguardQuickAffordanceModel? = null val job = - underTest(KeyguardQuickAffordancePosition.BOTTOM_START) + underTest + .quickAffordance(KeyguardQuickAffordancePosition.BOTTOM_START) .onEach { latest = it } .launchIn(this) assertThat(latest).isEqualTo(KeyguardQuickAffordanceModel.Hidden) @@ -150,7 +167,7 @@ class ObserveKeyguardQuickAffordanceUseCaseImplTest : SysuiTestCase() { } @Test - fun `invoke - bottom start affordance hidden when lockscreen is not showing`() = + fun `quickAffordance - bottom start affordance hidden when lockscreen is not showing`() = runBlockingTest { repository.setKeyguardShowing(false) homeControls.setState( @@ -162,7 +179,8 @@ class ObserveKeyguardQuickAffordanceUseCaseImplTest : SysuiTestCase() { var latest: KeyguardQuickAffordanceModel? = null val job = - underTest(KeyguardQuickAffordancePosition.BOTTOM_START) + underTest + .quickAffordance(KeyguardQuickAffordancePosition.BOTTOM_START) .onEach { latest = it } .launchIn(this) assertThat(latest).isEqualTo(KeyguardQuickAffordanceModel.Hidden) diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/usecase/LaunchKeyguardQuickAffordanceUseCaseImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/usecase/LaunchKeyguardQuickAffordanceUseCaseImplTest.kt deleted file mode 100644 index b3c1ae0106cf3..0000000000000 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/usecase/LaunchKeyguardQuickAffordanceUseCaseImplTest.kt +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.systemui.keyguard.domain.usecase - -import android.content.Intent -import androidx.test.filters.SmallTest -import com.android.internal.widget.LockPatternUtils -import com.android.systemui.SysuiTestCase -import com.android.systemui.animation.ActivityLaunchAnimator -import com.android.systemui.plugins.ActivityStarter -import com.android.systemui.settings.UserTracker -import com.android.systemui.statusbar.policy.KeyguardStateController -import com.android.systemui.util.mockito.any -import com.android.systemui.util.mockito.mock -import org.junit.Before -import org.junit.Test -import org.junit.runner.RunWith -import org.junit.runners.Parameterized -import org.junit.runners.Parameterized.Parameter -import org.junit.runners.Parameterized.Parameters -import org.mockito.Mock -import org.mockito.Mockito.verify -import org.mockito.Mockito.`when` as whenever -import org.mockito.MockitoAnnotations - -@SmallTest -@RunWith(Parameterized::class) -class LaunchKeyguardQuickAffordanceUseCaseImplTest : SysuiTestCase() { - - companion object { - private val INTENT = Intent("some.intent.action") - - @Parameters( - name = - "needStrongAuthAfterBoot={0}, canShowWhileLocked={1}," + - " keyguardIsUnlocked={2}, needsToUnlockFirst={3}" - ) - @JvmStatic - fun data() = - listOf( - arrayOf( - /* needStrongAuthAfterBoot= */ false, - /* canShowWhileLocked= */ false, - /* keyguardIsUnlocked= */ false, - /* needsToUnlockFirst= */ true, - ), - arrayOf( - /* needStrongAuthAfterBoot= */ false, - /* canShowWhileLocked= */ false, - /* keyguardIsUnlocked= */ true, - /* needsToUnlockFirst= */ false, - ), - arrayOf( - /* needStrongAuthAfterBoot= */ false, - /* canShowWhileLocked= */ true, - /* keyguardIsUnlocked= */ false, - /* needsToUnlockFirst= */ false, - ), - arrayOf( - /* needStrongAuthAfterBoot= */ false, - /* canShowWhileLocked= */ true, - /* keyguardIsUnlocked= */ true, - /* needsToUnlockFirst= */ false, - ), - arrayOf( - /* needStrongAuthAfterBoot= */ true, - /* canShowWhileLocked= */ false, - /* keyguardIsUnlocked= */ false, - /* needsToUnlockFirst= */ true, - ), - arrayOf( - /* needStrongAuthAfterBoot= */ true, - /* canShowWhileLocked= */ false, - /* keyguardIsUnlocked= */ true, - /* needsToUnlockFirst= */ true, - ), - arrayOf( - /* needStrongAuthAfterBoot= */ true, - /* canShowWhileLocked= */ true, - /* keyguardIsUnlocked= */ false, - /* needsToUnlockFirst= */ true, - ), - arrayOf( - /* needStrongAuthAfterBoot= */ true, - /* canShowWhileLocked= */ true, - /* keyguardIsUnlocked= */ true, - /* needsToUnlockFirst= */ true, - ), - ) - } - - @Mock private lateinit var lockPatternUtils: LockPatternUtils - @Mock private lateinit var keyguardStateController: KeyguardStateController - @Mock private lateinit var userTracker: UserTracker - @Mock private lateinit var activityStarter: ActivityStarter - @Mock private lateinit var animationController: ActivityLaunchAnimator.Controller - - private lateinit var underTest: LaunchKeyguardQuickAffordanceUseCase - - @JvmField @Parameter(0) var needStrongAuthAfterBoot: Boolean = false - @JvmField @Parameter(1) var canShowWhileLocked: Boolean = false - @JvmField @Parameter(2) var keyguardIsUnlocked: Boolean = false - @JvmField @Parameter(3) var needsToUnlockFirst: Boolean = false - - @Before - fun setUp() { - MockitoAnnotations.initMocks(this) - - underTest = - LaunchKeyguardQuickAffordanceUseCaseImpl( - lockPatternUtils = lockPatternUtils, - keyguardStateController = keyguardStateController, - userTracker = userTracker, - activityStarter = activityStarter, - ) - } - - @Test - fun invoke() { - setUpMocks( - needStrongAuthAfterBoot = needStrongAuthAfterBoot, - keyguardIsUnlocked = keyguardIsUnlocked, - ) - - underTest( - intent = INTENT, - canShowWhileLocked = canShowWhileLocked, - animationController = animationController, - ) - - if (needsToUnlockFirst) { - verify(activityStarter) - .postStartActivityDismissingKeyguard( - INTENT, - /* delay= */ 0, - animationController, - ) - } else { - verify(activityStarter) - .startActivity( - INTENT, - /* dismissShade= */ true, - animationController, - /* showOverLockscreenWhenLocked= */ true, - ) - } - } - - private fun setUpMocks( - needStrongAuthAfterBoot: Boolean = true, - keyguardIsUnlocked: Boolean = false, - ) { - whenever(userTracker.userHandle).thenReturn(mock()) - whenever(lockPatternUtils.getStrongAuthForUser(any())) - .thenReturn( - if (needStrongAuthAfterBoot) { - LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT - } else { - LockPatternUtils.StrongAuthTracker.STRONG_AUTH_NOT_REQUIRED - } - ) - whenever(keyguardStateController.isUnlocked).thenReturn(keyguardIsUnlocked) - } -} diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBottomAreaViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBottomAreaViewModelTest.kt index 8758ce5eade62..c7385d720d8a7 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBottomAreaViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBottomAreaViewModelTest.kt @@ -18,24 +18,22 @@ package com.android.systemui.keyguard.ui.viewmodel import android.content.Intent import androidx.test.filters.SmallTest +import com.android.internal.widget.LockPatternUtils import com.android.systemui.SysuiTestCase import com.android.systemui.animation.ActivityLaunchAnimator import com.android.systemui.containeddrawable.ContainedDrawable import com.android.systemui.doze.util.BurnInHelperWrapper import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository -import com.android.systemui.keyguard.domain.model.KeyguardQuickAffordanceModel +import com.android.systemui.keyguard.domain.interactor.KeyguardBottomAreaInteractor +import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor +import com.android.systemui.keyguard.domain.interactor.KeyguardQuickAffordanceInteractor import com.android.systemui.keyguard.domain.model.KeyguardQuickAffordancePosition import com.android.systemui.keyguard.domain.quickaffordance.FakeKeyguardQuickAffordanceConfig import com.android.systemui.keyguard.domain.quickaffordance.FakeKeyguardQuickAffordanceRegistry import com.android.systemui.keyguard.domain.quickaffordance.KeyguardQuickAffordanceConfig -import com.android.systemui.keyguard.domain.usecase.FakeLaunchKeyguardQuickAffordanceUseCase -import com.android.systemui.keyguard.domain.usecase.FakeObserveKeyguardQuickAffordanceUseCase -import com.android.systemui.keyguard.domain.usecase.ObserveAnimateBottomAreaTransitionsUseCase -import com.android.systemui.keyguard.domain.usecase.ObserveBottomAreaAlphaUseCase -import com.android.systemui.keyguard.domain.usecase.ObserveClockPositionUseCase -import com.android.systemui.keyguard.domain.usecase.ObserveDozeAmountUseCase -import com.android.systemui.keyguard.domain.usecase.ObserveIsDozingUseCase -import com.android.systemui.keyguard.domain.usecase.OnKeyguardQuickAffordanceClickedUseCase +import com.android.systemui.plugins.ActivityStarter +import com.android.systemui.settings.UserTracker +import com.android.systemui.statusbar.policy.KeyguardStateController import com.android.systemui.util.mockito.any import com.android.systemui.util.mockito.mock import com.google.common.truth.Truth.assertThat @@ -49,6 +47,8 @@ import org.junit.runner.RunWith import org.junit.runners.JUnit4 import org.mockito.ArgumentMatchers.anyInt import org.mockito.Mock +import org.mockito.Mockito +import org.mockito.Mockito.verifyZeroInteractions import org.mockito.Mockito.`when` as whenever import org.mockito.MockitoAnnotations @@ -58,17 +58,18 @@ class KeyguardBottomAreaViewModelTest : SysuiTestCase() { @Mock private lateinit var animationController: ActivityLaunchAnimator.Controller @Mock private lateinit var burnInHelperWrapper: BurnInHelperWrapper + @Mock private lateinit var lockPatternUtils: LockPatternUtils + @Mock private lateinit var keyguardStateController: KeyguardStateController + @Mock private lateinit var userTracker: UserTracker + @Mock private lateinit var activityStarter: ActivityStarter private lateinit var underTest: KeyguardBottomAreaViewModel private lateinit var repository: FakeKeyguardRepository private lateinit var registry: FakeKeyguardQuickAffordanceRegistry - private lateinit var isDozingUseCase: ObserveIsDozingUseCase - private lateinit var launchQuickAffordanceUseCase: FakeLaunchKeyguardQuickAffordanceUseCase private lateinit var homeControlsQuickAffordanceConfig: FakeKeyguardQuickAffordanceConfig private lateinit var quickAccessWalletAffordanceConfig: FakeKeyguardQuickAffordanceConfig private lateinit var qrCodeScannerAffordanceConfig: FakeKeyguardQuickAffordanceConfig - private lateinit var observeQuickAffordanceUseCase: FakeObserveKeyguardQuickAffordanceUseCase @Before fun setUp() { @@ -94,57 +95,31 @@ class KeyguardBottomAreaViewModelTest : SysuiTestCase() { ), ) repository = FakeKeyguardRepository() - isDozingUseCase = - ObserveIsDozingUseCase( - repository = repository, - ) - launchQuickAffordanceUseCase = FakeLaunchKeyguardQuickAffordanceUseCase() - observeQuickAffordanceUseCase = FakeObserveKeyguardQuickAffordanceUseCase() + val keyguardInteractor = KeyguardInteractor(repository = repository) + whenever(userTracker.userHandle).thenReturn(mock()) + whenever(lockPatternUtils.getStrongAuthForUser(anyInt())) + .thenReturn(LockPatternUtils.StrongAuthTracker.STRONG_AUTH_NOT_REQUIRED) underTest = KeyguardBottomAreaViewModel( - observeQuickAffordanceUseCase = observeQuickAffordanceUseCase, - onQuickAffordanceClickedUseCase = - OnKeyguardQuickAffordanceClickedUseCase( - registry = - FakeKeyguardQuickAffordanceRegistry( - mapOf( - KeyguardQuickAffordancePosition.BOTTOM_START to - listOf( - homeControlsQuickAffordanceConfig, - ), - KeyguardQuickAffordancePosition.BOTTOM_END to - listOf( - quickAccessWalletAffordanceConfig, - qrCodeScannerAffordanceConfig, - ), - ), - ), - launchAffordanceUseCase = launchQuickAffordanceUseCase, - ), - observeBottomAreaAlphaUseCase = - ObserveBottomAreaAlphaUseCase( - repository = repository, - ), - observeIsDozingUseCase = isDozingUseCase, - observeAnimateBottomAreaTransitionsUseCase = - ObserveAnimateBottomAreaTransitionsUseCase( - repository = repository, - ), - observeDozeAmountUseCase = - ObserveDozeAmountUseCase( - repository = repository, - ), - observeClockPositionUseCase = - ObserveClockPositionUseCase( - repository = repository, + keyguardInteractor = keyguardInteractor, + quickAffordanceInteractor = + KeyguardQuickAffordanceInteractor( + keyguardInteractor = keyguardInteractor, + registry = registry, + lockPatternUtils = lockPatternUtils, + keyguardStateController = keyguardStateController, + userTracker = userTracker, + activityStarter = activityStarter, ), + bottomAreaInteractor = KeyguardBottomAreaInteractor(repository = repository), burnInHelperWrapper = burnInHelperWrapper, ) } @Test fun `startButton - present - visible model - starts activity on click`() = runBlockingTest { + repository.setKeyguardShowing(true) var latest: KeyguardQuickAffordanceViewModel? = null val job = underTest.startButton.onEach { latest = it }.launchIn(this) @@ -171,6 +146,7 @@ class KeyguardBottomAreaViewModelTest : SysuiTestCase() { @Test fun `endButton - present - visible model - do nothing on click`() = runBlockingTest { + repository.setKeyguardShowing(true) var latest: KeyguardQuickAffordanceViewModel? = null val job = underTest.endButton.onEach { latest = it }.launchIn(this) @@ -357,7 +333,7 @@ class KeyguardBottomAreaViewModelTest : SysuiTestCase() { private suspend fun setUpQuickAffordanceModel( position: KeyguardQuickAffordancePosition, testConfig: TestConfig, - ): KClass<*> { + ): KClass { val config = when (position) { KeyguardQuickAffordancePosition.BOTTOM_START -> homeControlsQuickAffordanceConfig @@ -381,20 +357,13 @@ class KeyguardBottomAreaViewModelTest : SysuiTestCase() { KeyguardQuickAffordanceConfig.State.Hidden } config.setState(state) - - val configKey = config::class - observeQuickAffordanceUseCase.setModel( - position, - KeyguardQuickAffordanceModel.from(state, configKey) - ) - - return configKey + return config::class } private fun assertQuickAffordanceViewModel( viewModel: KeyguardQuickAffordanceViewModel?, testConfig: TestConfig, - configKey: KClass<*>, + configKey: KClass, ) { checkNotNull(viewModel) assertThat(viewModel.isVisible).isEqualTo(testConfig.isVisible) @@ -406,19 +375,11 @@ class KeyguardBottomAreaViewModelTest : SysuiTestCase() { animationController = animationController, ) ) - testConfig.intent?.let { intent -> - assertThat(launchQuickAffordanceUseCase.invocations) - .isEqualTo( - listOf( - FakeLaunchKeyguardQuickAffordanceUseCase.Invocation( - intent = intent, - canShowWhileLocked = testConfig.canShowWhileLocked, - animationController = animationController, - ) - ) - ) + if (testConfig.intent != null) { + assertThat(Mockito.mockingDetails(activityStarter).invocations).hasSize(1) + } else { + verifyZeroInteractions(activityStarter) } - ?: run { assertThat(launchQuickAffordanceUseCase.invocations).isEmpty() } } else { assertThat(viewModel.isVisible).isFalse() } diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerTest.java index fc28349e1e570..3f4e2a9b4d650 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerTest.java @@ -98,9 +98,7 @@ import com.android.systemui.flags.FeatureFlags; import com.android.systemui.fragments.FragmentHostManager; import com.android.systemui.fragments.FragmentService; import com.android.systemui.keyguard.KeyguardUnlockAnimationController; -import com.android.systemui.keyguard.domain.usecase.SetClockPositionUseCase; -import com.android.systemui.keyguard.domain.usecase.SetKeyguardBottomAreaAlphaUseCase; -import com.android.systemui.keyguard.domain.usecase.SetKeyguardBottomAreaAnimateDozingTransitionsUseCase; +import com.android.systemui.keyguard.domain.interactor.KeyguardBottomAreaInteractor; import com.android.systemui.keyguard.ui.viewmodel.KeyguardBottomAreaViewModel; import com.android.systemui.media.KeyguardMediaController; import com.android.systemui.media.MediaDataManager; @@ -379,10 +377,7 @@ public class NotificationPanelViewControllerTest extends SysuiTestCase { @Mock private ViewTreeObserver mViewTreeObserver; @Mock private KeyguardBottomAreaViewModel mKeyguardBottomAreaViewModel; - @Mock private SetClockPositionUseCase mSetClockPositionUseCase; - @Mock private SetKeyguardBottomAreaAlphaUseCase mSetKeyguardBottomAreaAlphaUseCase; - @Mock private SetKeyguardBottomAreaAnimateDozingTransitionsUseCase - mSetKeyguardBottomAreaAnimateDozingTransitionsUseCase; + @Mock private KeyguardBottomAreaInteractor mKeyguardBottomAreaInteractor; private NotificationPanelViewController.PanelEventsEmitter mPanelEventsEmitter; private Optional mSysUIUnfoldComponent = Optional.empty(); private SysuiStatusBarStateController mStatusBarStateController; @@ -577,9 +572,7 @@ public class NotificationPanelViewControllerTest extends SysuiTestCase { mSystemClock, mock(CameraGestureHelper.class), () -> mKeyguardBottomAreaViewModel, - () -> mSetClockPositionUseCase, - () -> mSetKeyguardBottomAreaAlphaUseCase, - () -> mSetKeyguardBottomAreaAnimateDozingTransitionsUseCase); + () -> mKeyguardBottomAreaInteractor); mNotificationPanelViewController.initDependencies( mCentralSurfaces, () -> {},