diff options
| author | 2022-08-12 01:41:20 +0000 | |
|---|---|---|
| committer | 2022-08-12 01:41:20 +0000 | |
| commit | b86df9ca03d86b9b6ac86a2838e2c5ab1fb32aea (patch) | |
| tree | 5c2a756d2f3087c2aa6f0f88be8ee5833a94a625 | |
| parent | e830c6b55f14dd7fab06d94257990e39936563de (diff) | |
| parent | 5b1e1f9bc7a55feed92ea150cc5e1b0e3e1b28ed (diff) | |
Merge "Moves quick affordances into domain layer." into tm-qpr-dev am: ef8f854aba am: 5b1e1f9bc7
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19561657
Change-Id: I85b85e3346a428e2207c1d0a4e5b851723a23380
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
29 files changed, 414 insertions, 657 deletions
diff --git a/packages/SystemUI/docs/device-entry/quickaffordance.md b/packages/SystemUI/docs/device-entry/quickaffordance.md index a96e533933f4..38d636d7ff82 100644 --- a/packages/SystemUI/docs/device-entry/quickaffordance.md +++ b/packages/SystemUI/docs/device-entry/quickaffordance.md @@ -6,16 +6,16 @@ credit card, etc. ## Adding a new Quick Affordance ### Step 1: create a new quick affordance config -* Create a new class under the [systemui/keyguard/data/quickaffordance](../../src/com/android/systemui/keyguard/data/quickaffordance) directory +* Create a new class under the [systemui/keyguard/domain/quickaffordance](../../src/com/android/systemui/keyguard/domain/quickaffordance) directory * Please make sure that the class is injected through the Dagger dependency injection system by using the `@Inject` annotation on its main constructor and the `@SysUISingleton` annotation at class level, to make sure only one instance of the class is ever instantiated -* Have the class implement the [KeyguardQuickAffordanceConfig](../../src/com/android/systemui/keyguard/data/quickaffordance/KeyguardQuickAffordanceConfig.kt) interface, notes: +* Have the class implement the [KeyguardQuickAffordanceConfig](../../src/com/android/systemui/keyguard/domain/quickaffordance/KeyguardQuickAffordanceConfig.kt) interface, notes: * The `state` Flow property must emit `State.Hidden` when the feature is not enabled! * It is safe to assume that `onQuickAffordanceClicked` will not be invoked if-and-only-if the previous rule is followed * When implementing `onQuickAffordanceClicked`, the implementation can do something or it can ask the framework to start an activity using an `Intent` provided by the implementation -* Please include a unit test for your new implementation under [the correct directory](../../tests/src/com/android/systemui/keyguard/data/quickaffordance) +* Please include a unit test for your new implementation under [the correct directory](../../tests/src/com/android/systemui/keyguard/domain/quickaffordance) ### Step 2: choose a position and priority -* Add the new class as a dependency in the constructor of [KeyguardQuickAffordanceConfigs](../../src/com/android/systemui/keyguard/data/repository/KeyguardQuickAffordanceConfigs.kt) +* Add the new class as a dependency in the constructor of [KeyguardQuickAffordanceRegistry](../../src/com/android/systemui/keyguard/domain/quickaffordance/KeyguardQuickAffordanceRegistry.kt) * Place the new class in one of the available positions in the `configsByPosition` property, note: * In each position, there is a list. The order matters. The order of that list is the priority order in which the framework considers each config. The first config whose state property returns `State.Visible` determines the button that is shown for that position * Please only add to one position. The framework treats each position individually and there is no good way to prevent the same config from making its button appear in more than one position at the same time 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 4ff008ffb33a..430b59cd4027 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java @@ -43,6 +43,7 @@ import com.android.systemui.keyguard.DismissCallbackRegistry; 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; @@ -70,6 +71,7 @@ import dagger.Provides; KeyguardUserSwitcherComponent.class}, includes = { FalsingModule.class, + KeyguardQuickAffordanceModule.class, KeyguardRepositoryModule.class, KeyguardUseCaseModule.class, }) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardQuickAffordanceRepository.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardQuickAffordanceRepository.kt deleted file mode 100644 index 43c4fa06367b..000000000000 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardQuickAffordanceRepository.kt +++ /dev/null @@ -1,65 +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.data.repository - -import com.android.systemui.dagger.SysUISingleton -import com.android.systemui.keyguard.data.config.KeyguardQuickAffordanceConfigs -import com.android.systemui.keyguard.data.quickaffordance.KeyguardQuickAffordanceConfig.State -import com.android.systemui.keyguard.shared.model.KeyguardQuickAffordanceModel -import com.android.systemui.keyguard.shared.model.KeyguardQuickAffordancePosition -import javax.inject.Inject -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.combine - -/** Defines interface for classes that encapsulate quick affordance state for the keyguard. */ -interface KeyguardQuickAffordanceRepository { - fun affordance(position: KeyguardQuickAffordancePosition): Flow<KeyguardQuickAffordanceModel> -} - -/** Real implementation of [KeyguardQuickAffordanceRepository] */ -@SysUISingleton -class KeyguardQuickAffordanceRepositoryImpl -@Inject -constructor( - private val configs: KeyguardQuickAffordanceConfigs, -) : KeyguardQuickAffordanceRepository { - - /** Returns an observable for the quick affordance model in the given position. */ - override fun affordance( - position: KeyguardQuickAffordancePosition - ): Flow<KeyguardQuickAffordanceModel> { - val configs = configs.getAll(position) - return combine(configs.map { config -> config.state }) { states -> - val index = states.indexOfFirst { state -> state is State.Visible } - val visibleState = - if (index != -1) { - states[index] as State.Visible - } else { - null - } - if (visibleState != null) { - KeyguardQuickAffordanceModel.Visible( - configKey = configs[index]::class, - icon = visibleState.icon, - contentDescriptionResourceId = visibleState.contentDescriptionResourceId, - ) - } else { - KeyguardQuickAffordanceModel.Hidden - } - } - } -} diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardRepositoryModule.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardRepositoryModule.kt index 1a5670c7e807..d15d7f25bbde 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardRepositoryModule.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardRepositoryModule.kt @@ -16,22 +16,10 @@ package com.android.systemui.keyguard.data.repository -import com.android.systemui.keyguard.data.config.KeyguardQuickAffordanceConfigs -import com.android.systemui.keyguard.data.config.KeyguardQuickAffordanceConfigsImpl import dagger.Binds import dagger.Module @Module interface KeyguardRepositoryModule { @Binds fun keyguardRepository(impl: KeyguardRepositoryImpl): KeyguardRepository - - @Binds - fun keyguardQuickAffordanceRepository( - impl: KeyguardQuickAffordanceRepositoryImpl - ): KeyguardQuickAffordanceRepository - - @Binds - fun keyguardQuickAffordanceConfigs( - impl: KeyguardQuickAffordanceConfigsImpl - ): KeyguardQuickAffordanceConfigs } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/shared/model/KeyguardQuickAffordanceModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/model/KeyguardQuickAffordanceModel.kt index 09785dfa3c03..411a2ca5ffe2 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/shared/model/KeyguardQuickAffordanceModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/model/KeyguardQuickAffordanceModel.kt @@ -15,11 +15,11 @@ * */ -package com.android.systemui.keyguard.shared.model +package com.android.systemui.keyguard.domain.model import androidx.annotation.StringRes import com.android.systemui.containeddrawable.ContainedDrawable -import com.android.systemui.keyguard.data.quickaffordance.KeyguardQuickAffordanceConfig +import com.android.systemui.keyguard.domain.quickaffordance.KeyguardQuickAffordanceConfig import kotlin.reflect.KClass /** @@ -27,7 +27,6 @@ import kotlin.reflect.KClass * lock-screen). */ sealed class KeyguardQuickAffordanceModel { - /** No affordance should show up. */ object Hidden : KeyguardQuickAffordanceModel() @@ -43,4 +42,21 @@ sealed class KeyguardQuickAffordanceModel { */ @StringRes val contentDescriptionResourceId: Int, ) : KeyguardQuickAffordanceModel() + + companion object { + fun from( + state: KeyguardQuickAffordanceConfig.State?, + configKey: KClass<out KeyguardQuickAffordanceConfig>, + ): 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/shared/model/KeyguardQuickAffordancePosition.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/model/KeyguardQuickAffordancePosition.kt index b71e15d34afe..581dafa33df7 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/shared/model/KeyguardQuickAffordancePosition.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/model/KeyguardQuickAffordancePosition.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.systemui.keyguard.shared.model +package com.android.systemui.keyguard.domain.model /** Enumerates all possible positions for quick affordances that can appear on the lock-screen. */ enum class KeyguardQuickAffordancePosition { diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/HomeControlsKeyguardQuickAffordanceConfig.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/quickaffordance/HomeControlsKeyguardQuickAffordanceConfig.kt index df44957ec591..8f32ff9db50c 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/HomeControlsKeyguardQuickAffordanceConfig.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/quickaffordance/HomeControlsKeyguardQuickAffordanceConfig.kt @@ -15,7 +15,7 @@ * */ -package com.android.systemui.keyguard.data.quickaffordance +package com.android.systemui.keyguard.domain.quickaffordance import android.content.Context import android.content.Intent diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/KeyguardQuickAffordanceConfig.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/quickaffordance/KeyguardQuickAffordanceConfig.kt index 67a776eddccb..8fb952c217bd 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/KeyguardQuickAffordanceConfig.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/quickaffordance/KeyguardQuickAffordanceConfig.kt @@ -15,7 +15,7 @@ * */ -package com.android.systemui.keyguard.data.quickaffordance +package com.android.systemui.keyguard.domain.quickaffordance import android.content.Intent import androidx.annotation.StringRes 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 new file mode 100644 index 000000000000..a7b38282d0aa --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/quickaffordance/KeyguardQuickAffordanceModule.kt @@ -0,0 +1,29 @@ +/* + * 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.quickaffordance + +import dagger.Binds +import dagger.Module + +@Module +interface KeyguardQuickAffordanceModule { + @Binds + fun keyguardQuickAffordanceRegistry( + impl: KeyguardQuickAffordanceRegistryImpl + ): KeyguardQuickAffordanceRegistry +} diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardQuickAffordanceConfigs.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/quickaffordance/KeyguardQuickAffordanceRegistry.kt index 7164215eb2ae..2c37f93de435 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardQuickAffordanceConfigs.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/quickaffordance/KeyguardQuickAffordanceRegistry.kt @@ -15,29 +15,25 @@ * */ -package com.android.systemui.keyguard.data.config +package com.android.systemui.keyguard.domain.quickaffordance -import com.android.systemui.keyguard.data.quickaffordance.HomeControlsKeyguardQuickAffordanceConfig -import com.android.systemui.keyguard.data.quickaffordance.KeyguardQuickAffordanceConfig -import com.android.systemui.keyguard.data.quickaffordance.QrCodeScannerKeyguardQuickAffordanceConfig -import com.android.systemui.keyguard.data.quickaffordance.QuickAccessWalletKeyguardQuickAffordanceConfig -import com.android.systemui.keyguard.shared.model.KeyguardQuickAffordancePosition +import com.android.systemui.keyguard.domain.model.KeyguardQuickAffordancePosition import javax.inject.Inject import kotlin.reflect.KClass -/** Injectable provider of the positioning of the known quick affordance configs. */ -interface KeyguardQuickAffordanceConfigs { +/** Central registry of all known quick affordance configs. */ +interface KeyguardQuickAffordanceRegistry { fun getAll(position: KeyguardQuickAffordancePosition): List<KeyguardQuickAffordanceConfig> fun get(configClass: KClass<out KeyguardQuickAffordanceConfig>): KeyguardQuickAffordanceConfig } -class KeyguardQuickAffordanceConfigsImpl +class KeyguardQuickAffordanceRegistryImpl @Inject constructor( homeControls: HomeControlsKeyguardQuickAffordanceConfig, quickAccessWallet: QuickAccessWalletKeyguardQuickAffordanceConfig, qrCodeScanner: QrCodeScannerKeyguardQuickAffordanceConfig, -) : KeyguardQuickAffordanceConfigs { +) : KeyguardQuickAffordanceRegistry { private val configsByPosition = mapOf( KeyguardQuickAffordancePosition.BOTTOM_START to diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/QrCodeScannerKeyguardQuickAffordanceConfig.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/quickaffordance/QrCodeScannerKeyguardQuickAffordanceConfig.kt index ea6497ebcf3a..c8e5e4aebea0 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/QrCodeScannerKeyguardQuickAffordanceConfig.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/quickaffordance/QrCodeScannerKeyguardQuickAffordanceConfig.kt @@ -15,7 +15,7 @@ * */ -package com.android.systemui.keyguard.data.quickaffordance +package com.android.systemui.keyguard.domain.quickaffordance import com.android.systemui.R import com.android.systemui.animation.ActivityLaunchAnimator diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/QuickAccessWalletKeyguardQuickAffordanceConfig.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/quickaffordance/QuickAccessWalletKeyguardQuickAffordanceConfig.kt index cc5a9972af93..885af3343533 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/QuickAccessWalletKeyguardQuickAffordanceConfig.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/quickaffordance/QuickAccessWalletKeyguardQuickAffordanceConfig.kt @@ -15,7 +15,7 @@ * */ -package com.android.systemui.keyguard.data.quickaffordance +package com.android.systemui.keyguard.domain.quickaffordance import android.graphics.drawable.Drawable import android.service.quickaccesswallet.GetWalletCardsError 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 index c44c2c9901a1..403d34352c7b 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/KeyguardUseCaseModule.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/KeyguardUseCaseModule.kt @@ -26,4 +26,9 @@ interface KeyguardUseCaseModule { fun launchQuickAffordance( impl: LaunchKeyguardQuickAffordanceUseCaseImpl ): LaunchKeyguardQuickAffordanceUseCase + + @Binds + fun observeKeyguardQuickAffordance( + impl: ObserveKeyguardQuickAffordanceUseCaseImpl + ): ObserveKeyguardQuickAffordanceUseCase } 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 index eef8ec3e68f5..8dee8b38bdb8 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveKeyguardQuickAffordanceUseCase.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/ObserveKeyguardQuickAffordanceUseCase.kt @@ -16,26 +16,33 @@ package com.android.systemui.keyguard.domain.usecase -import com.android.systemui.keyguard.data.repository.KeyguardQuickAffordanceRepository -import com.android.systemui.keyguard.shared.model.KeyguardQuickAffordanceModel -import com.android.systemui.keyguard.shared.model.KeyguardQuickAffordancePosition +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 -/** Use-case for observing the model of a quick affordance in the keyguard. */ -class ObserveKeyguardQuickAffordanceUseCase +/** Defines interface for use-case for observing the model of a quick affordance in the keyguard. */ +interface ObserveKeyguardQuickAffordanceUseCase { + operator fun invoke( + position: KeyguardQuickAffordancePosition + ): Flow<KeyguardQuickAffordanceModel> +} + +class ObserveKeyguardQuickAffordanceUseCaseImpl @Inject constructor( - private val repository: KeyguardQuickAffordanceRepository, + private val registry: KeyguardQuickAffordanceRegistry, private val isDozingUseCase: ObserveIsDozingUseCase, private val isKeyguardShowingUseCase: ObserveIsKeyguardShowingUseCase, -) { - operator fun invoke( +) : ObserveKeyguardQuickAffordanceUseCase { + override fun invoke( position: KeyguardQuickAffordancePosition ): Flow<KeyguardQuickAffordanceModel> { return combine( - repository.affordance(position), + affordance(position), isDozingUseCase(), isKeyguardShowingUseCase(), ) { affordance, isDozing, isKeyguardShowing -> @@ -46,4 +53,23 @@ constructor( } } } + + private fun affordance( + position: KeyguardQuickAffordancePosition + ): Flow<KeyguardQuickAffordanceModel> { + 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 index f8db90f02540..93153391ca41 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/OnKeyguardQuickAffordanceClickedUseCase.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/usecase/OnKeyguardQuickAffordanceClickedUseCase.kt @@ -17,9 +17,9 @@ package com.android.systemui.keyguard.domain.usecase import com.android.systemui.animation.ActivityLaunchAnimator -import com.android.systemui.keyguard.data.config.KeyguardQuickAffordanceConfigs -import com.android.systemui.keyguard.data.quickaffordance.KeyguardQuickAffordanceConfig -import com.android.systemui.keyguard.data.quickaffordance.KeyguardQuickAffordanceConfig.OnClickedResult +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 @@ -27,7 +27,7 @@ import kotlin.reflect.KClass class OnKeyguardQuickAffordanceClickedUseCase @Inject constructor( - private val configs: KeyguardQuickAffordanceConfigs, + private val registry: KeyguardQuickAffordanceRegistry, private val launchAffordanceUseCase: LaunchKeyguardQuickAffordanceUseCase, ) { operator fun invoke( @@ -35,7 +35,7 @@ constructor( animationController: ActivityLaunchAnimator.Controller?, ) { @Suppress("UNCHECKED_CAST") - val config = configs.get(configKey as KClass<out KeyguardQuickAffordanceConfig>) + val config = registry.get(configKey as KClass<out KeyguardQuickAffordanceConfig>) when (val result = config.onQuickAffordanceClicked(animationController)) { is OnClickedResult.StartActivity -> launchAffordanceUseCase( 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 4b69a81c8996..d296e76482ad 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,6 +17,8 @@ package com.android.systemui.keyguard.ui.viewmodel import com.android.systemui.doze.util.BurnInHelperWrapper +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 @@ -24,8 +26,6 @@ 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 com.android.systemui.keyguard.shared.model.KeyguardQuickAffordanceModel -import com.android.systemui.keyguard.shared.model.KeyguardQuickAffordancePosition import javax.inject.Inject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/FakeKeyguardQuickAffordanceConfigs.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/FakeKeyguardQuickAffordanceConfigs.kt deleted file mode 100644 index a24fc93fedc2..000000000000 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/FakeKeyguardQuickAffordanceConfigs.kt +++ /dev/null @@ -1,44 +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.data.repository - -import com.android.systemui.keyguard.data.config.KeyguardQuickAffordanceConfigs -import com.android.systemui.keyguard.data.quickaffordance.KeyguardQuickAffordanceConfig -import com.android.systemui.keyguard.shared.model.KeyguardQuickAffordancePosition -import kotlin.reflect.KClass - -/** Fake implementation of [KeyguardQuickAffordanceConfigs], for tests. */ -class FakeKeyguardQuickAffordanceConfigs( - private val configsByPosition: - Map<KeyguardQuickAffordancePosition, List<KeyguardQuickAffordanceConfig>>, -) : KeyguardQuickAffordanceConfigs { - - override fun getAll( - position: KeyguardQuickAffordancePosition - ): List<KeyguardQuickAffordanceConfig> { - return configsByPosition.getValue(position) - } - - override fun get( - configClass: KClass<out KeyguardQuickAffordanceConfig> - ): KeyguardQuickAffordanceConfig { - return configsByPosition.values - .flatten() - .associateBy { config -> config::class } - .getValue(configClass) - } -} diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/FakeKeyguardQuickAffordanceRepository.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/FakeKeyguardQuickAffordanceRepository.kt deleted file mode 100644 index 10d2e4de631d..000000000000 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/FakeKeyguardQuickAffordanceRepository.kt +++ /dev/null @@ -1,55 +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.data.repository - -import com.android.systemui.keyguard.shared.model.KeyguardQuickAffordanceModel -import com.android.systemui.keyguard.shared.model.KeyguardQuickAffordancePosition -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.yield - -/** Fake implementation of [KeyguardQuickAffordanceRepository], for tests. */ -class FakeKeyguardQuickAffordanceRepository : KeyguardQuickAffordanceRepository { - - private val modelByPosition = - mutableMapOf< - KeyguardQuickAffordancePosition, MutableStateFlow<KeyguardQuickAffordanceModel>>() - - init { - KeyguardQuickAffordancePosition.values().forEach { value -> - modelByPosition[value] = MutableStateFlow(KeyguardQuickAffordanceModel.Hidden) - } - } - - override fun affordance( - position: KeyguardQuickAffordancePosition - ): Flow<KeyguardQuickAffordanceModel> { - return modelByPosition.getValue(position) - } - - suspend fun setModel( - position: KeyguardQuickAffordancePosition, - model: KeyguardQuickAffordanceModel - ) { - modelByPosition.getValue(position).value = model - // 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/FakeKeyguardRepository.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/FakeKeyguardRepository.kt index d40b985f64de..38a337563165 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 @@ -20,6 +20,7 @@ import com.android.systemui.common.data.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 { @@ -43,11 +44,6 @@ class FakeKeyguardRepository : KeyguardRepository { private val _dozeAmount = MutableStateFlow(0f) override val dozeAmount: Flow<Float> = _dozeAmount - init { - setDozeAmount(0f) - setDozing(false) - } - override fun setAnimateDozingTransitions(animate: Boolean) { _animateBottomAreaDozingTransitions.tryEmit(animate) } @@ -60,15 +56,30 @@ class FakeKeyguardRepository : KeyguardRepository { _clockPosition.value = Position(x, y) } - fun setKeyguardShowing(isShowing: Boolean) { + suspend 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() } - fun setDozing(isDozing: Boolean) { + suspend 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() } - fun setDozeAmount(dozeAmount: Float) { + suspend 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/KeyguardQuickAffordanceRepositoryImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardQuickAffordanceRepositoryImplTest.kt deleted file mode 100644 index dc0e6f7663ff..000000000000 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardQuickAffordanceRepositoryImplTest.kt +++ /dev/null @@ -1,193 +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.data.repository - -import androidx.test.filters.SmallTest -import com.android.systemui.SysuiTestCase -import com.android.systemui.keyguard.data.quickaffordance.KeyguardQuickAffordanceConfig -import com.android.systemui.keyguard.shared.model.KeyguardQuickAffordanceModel -import com.android.systemui.keyguard.shared.model.KeyguardQuickAffordancePosition -import com.android.systemui.util.mockito.mock -import com.google.common.truth.Truth.assertThat -import kotlin.reflect.KClass -import kotlinx.coroutines.flow.launchIn -import kotlinx.coroutines.flow.onEach -import kotlinx.coroutines.test.runBlockingTest -import org.junit.Before -import org.junit.Test -import org.junit.runner.RunWith -import org.junit.runners.JUnit4 -import org.mockito.MockitoAnnotations - -@SmallTest -@RunWith(JUnit4::class) -class KeyguardQuickAffordanceRepositoryImplTest : SysuiTestCase() { - - private lateinit var underTest: KeyguardQuickAffordanceRepository - - private lateinit var homeControls: FakeKeyguardQuickAffordanceConfig - private lateinit var quickAccessWallet: FakeKeyguardQuickAffordanceConfig - private lateinit var qrCodeScanner: FakeKeyguardQuickAffordanceConfig - - @Before - fun setUp() { - MockitoAnnotations.initMocks(this) - - homeControls = object : FakeKeyguardQuickAffordanceConfig() {} - quickAccessWallet = object : FakeKeyguardQuickAffordanceConfig() {} - qrCodeScanner = object : FakeKeyguardQuickAffordanceConfig() {} - - underTest = - KeyguardQuickAffordanceRepositoryImpl( - configs = - FakeKeyguardQuickAffordanceConfigs( - mapOf( - KeyguardQuickAffordancePosition.BOTTOM_START to - listOf( - homeControls, - ), - KeyguardQuickAffordancePosition.BOTTOM_END to - listOf( - quickAccessWallet, - qrCodeScanner, - ), - ), - ), - ) - } - - @Test - fun `bottom start affordance - none`() = runBlockingTest { - // TODO(b/239834928): once coroutines.test is updated, switch to the approach described in - // https://developer.android.com/kotlin/flow/test#continuous-collection - var latest: KeyguardQuickAffordanceModel? = null - val job = - underTest - .affordance(KeyguardQuickAffordancePosition.BOTTOM_START) - .onEach { latest = it } - .launchIn(this) - - assertThat(latest).isEqualTo(KeyguardQuickAffordanceModel.Hidden) - job.cancel() - } - - @Test - fun `bottom start affordance - home controls`() = runBlockingTest { - // TODO(b/239834928): once coroutines.test is updated, switch to the approach described in - // https://developer.android.com/kotlin/flow/test#continuous-collection - var latest: KeyguardQuickAffordanceModel? = null - val job = - underTest - .affordance(KeyguardQuickAffordancePosition.BOTTOM_START) - .onEach { latest = it } - .launchIn(this) - - val state = - KeyguardQuickAffordanceConfig.State.Visible( - icon = mock(), - contentDescriptionResourceId = CONTENT_DESCRIPTION_RESOURCE_ID, - ) - homeControls.setState(state) - - assertThat(latest).isEqualTo(state.toModel(homeControls::class)) - job.cancel() - } - - @Test - fun `bottom end affordance - none`() = runBlockingTest { - // TODO(b/239834928): once coroutines.test is updated, switch to the approach described in - // https://developer.android.com/kotlin/flow/test#continuous-collection - var latest: KeyguardQuickAffordanceModel? = null - val job = - underTest - .affordance(KeyguardQuickAffordancePosition.BOTTOM_END) - .onEach { latest = it } - .launchIn(this) - - assertThat(latest).isEqualTo(KeyguardQuickAffordanceModel.Hidden) - job.cancel() - } - - @Test - fun `bottom end affordance - quick access wallet`() = runBlockingTest { - // TODO(b/239834928): once coroutines.test is updated, switch to the approach described in - // https://developer.android.com/kotlin/flow/test#continuous-collection - var latest: KeyguardQuickAffordanceModel? = null - val job = - underTest - .affordance(KeyguardQuickAffordancePosition.BOTTOM_END) - .onEach { latest = it } - .launchIn(this) - - val quickAccessWalletState = - KeyguardQuickAffordanceConfig.State.Visible( - icon = mock(), - contentDescriptionResourceId = CONTENT_DESCRIPTION_RESOURCE_ID, - ) - quickAccessWallet.setState(quickAccessWalletState) - val qrCodeScannerState = - KeyguardQuickAffordanceConfig.State.Visible( - icon = mock(), - contentDescriptionResourceId = CONTENT_DESCRIPTION_RESOURCE_ID, - ) - qrCodeScanner.setState(qrCodeScannerState) - - assertThat(latest).isEqualTo(quickAccessWalletState.toModel(quickAccessWallet::class)) - job.cancel() - } - - @Test - fun `bottom end affordance - qr code scanner`() = runBlockingTest { - // TODO(b/239834928): once coroutines.test is updated, switch to the approach described in - // https://developer.android.com/kotlin/flow/test#continuous-collection - var latest: KeyguardQuickAffordanceModel? = null - val job = - underTest - .affordance(KeyguardQuickAffordancePosition.BOTTOM_END) - .onEach { latest = it } - .launchIn(this) - - val state = - KeyguardQuickAffordanceConfig.State.Visible( - icon = mock(), - contentDescriptionResourceId = CONTENT_DESCRIPTION_RESOURCE_ID, - ) - qrCodeScanner.setState(state) - - assertThat(latest).isEqualTo(state.toModel(qrCodeScanner::class)) - job.cancel() - } - - private fun KeyguardQuickAffordanceConfig.State?.toModel( - configKey: KClass<out KeyguardQuickAffordanceConfig>, - ): KeyguardQuickAffordanceModel? { - return when (this) { - is KeyguardQuickAffordanceConfig.State.Visible -> - KeyguardQuickAffordanceModel.Visible( - configKey = configKey, - icon = icon, - contentDescriptionResourceId = CONTENT_DESCRIPTION_RESOURCE_ID, - ) - is KeyguardQuickAffordanceConfig.State.Hidden -> KeyguardQuickAffordanceModel.Hidden - null -> null - } - } - - companion object { - private const val CONTENT_DESCRIPTION_RESOURCE_ID = 1337 - } -} diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/FakeKeyguardQuickAffordanceConfig.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/quickaffordance/FakeKeyguardQuickAffordanceConfig.kt index 6fff440ec2fa..6ea1daa7704f 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/FakeKeyguardQuickAffordanceConfig.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/quickaffordance/FakeKeyguardQuickAffordanceConfig.kt @@ -1,24 +1,24 @@ /* - * Copyright (C) 2022 The Android Open Source Project + * 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 + * 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 + * 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. * - * 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.data.repository +package com.android.systemui.keyguard.domain.quickaffordance import com.android.systemui.animation.ActivityLaunchAnimator -import com.android.systemui.keyguard.data.quickaffordance.KeyguardQuickAffordanceConfig -import com.android.systemui.keyguard.data.quickaffordance.KeyguardQuickAffordanceConfig.OnClickedResult +import com.android.systemui.keyguard.domain.quickaffordance.KeyguardQuickAffordanceConfig.OnClickedResult import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.yield @@ -31,9 +31,6 @@ import kotlinx.coroutines.yield */ abstract class FakeKeyguardQuickAffordanceConfig : KeyguardQuickAffordanceConfig { - private val _onClickedInvocations = mutableListOf<ActivityLaunchAnimator.Controller?>() - val onClickedInvocations: List<ActivityLaunchAnimator.Controller?> = _onClickedInvocations - var onClickedResult: OnClickedResult = OnClickedResult.Handled private val _state = @@ -45,7 +42,6 @@ abstract class FakeKeyguardQuickAffordanceConfig : KeyguardQuickAffordanceConfig override fun onQuickAffordanceClicked( animationController: ActivityLaunchAnimator.Controller?, ): OnClickedResult { - _onClickedInvocations.add(animationController) return onClickedResult } 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 new file mode 100644 index 000000000000..1c9902b36517 --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/quickaffordance/FakeKeyguardQuickAffordanceRegistry.kt @@ -0,0 +1,43 @@ +/* + * 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.quickaffordance + +import com.android.systemui.keyguard.domain.model.KeyguardQuickAffordancePosition +import kotlin.reflect.KClass + +/** Fake implementation of [FakeKeyguardQuickAffordanceRegistry], for tests. */ +class FakeKeyguardQuickAffordanceRegistry( + private val configsByPosition: + Map<KeyguardQuickAffordancePosition, List<KeyguardQuickAffordanceConfig>>, +) : KeyguardQuickAffordanceRegistry { + + override fun getAll( + position: KeyguardQuickAffordancePosition + ): List<KeyguardQuickAffordanceConfig> { + return configsByPosition.getValue(position) + } + + override fun get( + configClass: KClass<out KeyguardQuickAffordanceConfig> + ): KeyguardQuickAffordanceConfig { + return configsByPosition.values + .flatten() + .associateBy { config -> config::class } + .getValue(configClass) + } +} diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/HomeControlsKeyguardQuickAffordanceConfigParameterizedStateTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/quickaffordance/HomeControlsKeyguardQuickAffordanceConfigParameterizedStateTest.kt index 810c6dc4776d..9acd21cc6398 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/HomeControlsKeyguardQuickAffordanceConfigParameterizedStateTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/quickaffordance/HomeControlsKeyguardQuickAffordanceConfigParameterizedStateTest.kt @@ -1,20 +1,21 @@ /* - * Copyright (C) 2022 The Android Open Source Project + * 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 + * 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 + * 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. * - * 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.data.quickaffordance +package com.android.systemui.keyguard.domain.quickaffordance import androidx.test.filters.SmallTest import com.android.systemui.R diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/HomeControlsKeyguardQuickAffordanceConfigTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/quickaffordance/HomeControlsKeyguardQuickAffordanceConfigTest.kt index ef588f5ce255..059487dfdbc8 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/HomeControlsKeyguardQuickAffordanceConfigTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/quickaffordance/HomeControlsKeyguardQuickAffordanceConfigTest.kt @@ -15,7 +15,7 @@ * */ -package com.android.systemui.keyguard.data.quickaffordance +package com.android.systemui.keyguard.domain.quickaffordance import androidx.test.filters.SmallTest import com.android.systemui.R @@ -23,7 +23,7 @@ import com.android.systemui.SysuiTestCase import com.android.systemui.animation.ActivityLaunchAnimator import com.android.systemui.controls.controller.ControlsController import com.android.systemui.controls.dagger.ControlsComponent -import com.android.systemui.keyguard.data.quickaffordance.KeyguardQuickAffordanceConfig.OnClickedResult +import com.android.systemui.keyguard.domain.quickaffordance.KeyguardQuickAffordanceConfig.OnClickedResult import com.android.systemui.util.mockito.mock import com.google.common.truth.Truth.assertThat import java.util.Optional diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/QrCodeScannerKeyguardQuickAffordanceConfigTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/quickaffordance/QrCodeScannerKeyguardQuickAffordanceConfigTest.kt index 6fd04de8c9ac..d4fba4126127 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/QrCodeScannerKeyguardQuickAffordanceConfigTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/quickaffordance/QrCodeScannerKeyguardQuickAffordanceConfigTest.kt @@ -15,12 +15,12 @@ * */ -package com.android.systemui.keyguard.data.quickaffordance +package com.android.systemui.keyguard.domain.quickaffordance import android.content.Intent import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase -import com.android.systemui.keyguard.data.quickaffordance.KeyguardQuickAffordanceConfig.OnClickedResult +import com.android.systemui.keyguard.domain.quickaffordance.KeyguardQuickAffordanceConfig.OnClickedResult import com.android.systemui.qrcodescanner.controller.QRCodeScannerController import com.android.systemui.util.mockito.argumentCaptor import com.android.systemui.util.mockito.mock diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/QuickAccessWalletKeyguardQuickAffordanceConfigTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/quickaffordance/QuickAccessWalletKeyguardQuickAffordanceConfigTest.kt index 345c51f6f760..5a3a78e9cb04 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/QuickAccessWalletKeyguardQuickAffordanceConfigTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/quickaffordance/QuickAccessWalletKeyguardQuickAffordanceConfigTest.kt @@ -15,7 +15,7 @@ * */ -package com.android.systemui.keyguard.data.quickaffordance +package com.android.systemui.keyguard.domain.quickaffordance import android.graphics.drawable.Drawable import android.service.quickaccesswallet.GetWalletCardsResponse 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 new file mode 100644 index 000000000000..8982752c9fcc --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/usecase/FakeObserveKeyguardQuickAffordanceUseCase.kt @@ -0,0 +1,46 @@ +/* + * 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<KeyguardQuickAffordanceModel>>() + + init { + KeyguardQuickAffordancePosition.values().forEach { position -> + affordanceByPosition[position] = MutableStateFlow(KeyguardQuickAffordanceModel.Hidden) + } + } + + override fun invoke( + position: KeyguardQuickAffordancePosition + ): Flow<KeyguardQuickAffordanceModel> { + 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/ObserveKeyguardQuickAffordanceUseCaseTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/usecase/ObserveKeyguardQuickAffordanceUseCaseImplTest.kt index b90400be16d8..63eb68f423ee 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/usecase/ObserveKeyguardQuickAffordanceUseCaseTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/usecase/ObserveKeyguardQuickAffordanceUseCaseImplTest.kt @@ -19,11 +19,12 @@ package com.android.systemui.keyguard.domain.usecase import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.containeddrawable.ContainedDrawable -import com.android.systemui.keyguard.data.quickaffordance.HomeControlsKeyguardQuickAffordanceConfig -import com.android.systemui.keyguard.data.repository.FakeKeyguardQuickAffordanceRepository import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository -import com.android.systemui.keyguard.shared.model.KeyguardQuickAffordanceModel -import com.android.systemui.keyguard.shared.model.KeyguardQuickAffordancePosition +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.util.mockito.mock import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.flow.launchIn @@ -36,48 +37,62 @@ import org.junit.runners.JUnit4 @SmallTest @RunWith(JUnit4::class) -class ObserveKeyguardQuickAffordanceUseCaseTest : SysuiTestCase() { +class ObserveKeyguardQuickAffordanceUseCaseImplTest : SysuiTestCase() { private lateinit var underTest: ObserveKeyguardQuickAffordanceUseCase private lateinit var repository: FakeKeyguardRepository - private lateinit var quickAffordanceRepository: FakeKeyguardQuickAffordanceRepository 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() { + fun setUp() = runBlockingTest { repository = FakeKeyguardRepository() repository.setKeyguardShowing(true) isDozingUseCase = ObserveIsDozingUseCase(repository) isKeyguardShowingUseCase = ObserveIsKeyguardShowingUseCase(repository) - quickAffordanceRepository = FakeKeyguardQuickAffordanceRepository() + + homeControls = object : FakeKeyguardQuickAffordanceConfig() {} + quickAccessWallet = object : FakeKeyguardQuickAffordanceConfig() {} + qrCodeScanner = object : FakeKeyguardQuickAffordanceConfig() {} underTest = - ObserveKeyguardQuickAffordanceUseCase( - repository = quickAffordanceRepository, + ObserveKeyguardQuickAffordanceUseCaseImpl( + registry = + FakeKeyguardQuickAffordanceRegistry( + mapOf( + KeyguardQuickAffordancePosition.BOTTOM_START to + listOf( + homeControls, + ), + KeyguardQuickAffordancePosition.BOTTOM_END to + listOf( + quickAccessWallet, + qrCodeScanner, + ), + ), + ), isDozingUseCase = isDozingUseCase, isKeyguardShowingUseCase = isKeyguardShowingUseCase, ) } @Test - fun `invoke - affordance is visible`() = runBlockingTest { - val configKey = HomeControlsKeyguardQuickAffordanceConfig::class - val model = - KeyguardQuickAffordanceModel.Visible( - configKey = configKey, + fun `invoke - bottom start affordance is visible`() = runBlockingTest { + val configKey = homeControls::class + homeControls.setState( + KeyguardQuickAffordanceConfig.State.Visible( icon = ICON, contentDescriptionResourceId = CONTENT_DESCRIPTION_RESOURCE_ID, ) - quickAffordanceRepository.setModel( - KeyguardQuickAffordancePosition.BOTTOM_END, - model, ) var latest: KeyguardQuickAffordanceModel? = null val job = - underTest(KeyguardQuickAffordancePosition.BOTTOM_END) + underTest(KeyguardQuickAffordancePosition.BOTTOM_START) .onEach { latest = it } .launchIn(this) @@ -91,18 +106,13 @@ class ObserveKeyguardQuickAffordanceUseCaseTest : SysuiTestCase() { } @Test - fun `invoke - affordance not visible while dozing`() = runBlockingTest { - repository.setDozing(true) - val configKey = HomeControlsKeyguardQuickAffordanceConfig::class - val model = - KeyguardQuickAffordanceModel.Visible( - configKey = configKey, + fun `invoke - bottom end affordance is visible`() = runBlockingTest { + val configKey = quickAccessWallet::class + quickAccessWallet.setState( + KeyguardQuickAffordanceConfig.State.Visible( icon = ICON, contentDescriptionResourceId = CONTENT_DESCRIPTION_RESOURCE_ID, ) - quickAffordanceRepository.setModel( - KeyguardQuickAffordancePosition.BOTTOM_END, - model, ) var latest: KeyguardQuickAffordanceModel? = null @@ -110,28 +120,29 @@ class ObserveKeyguardQuickAffordanceUseCaseTest : SysuiTestCase() { underTest(KeyguardQuickAffordancePosition.BOTTOM_END) .onEach { latest = it } .launchIn(this) - assertThat(latest).isEqualTo(KeyguardQuickAffordanceModel.Hidden) + + assertThat(latest).isInstanceOf(KeyguardQuickAffordanceModel.Visible::class.java) + val visibleModel = latest as KeyguardQuickAffordanceModel.Visible + assertThat(visibleModel.configKey).isEqualTo(configKey) + assertThat(visibleModel.icon).isEqualTo(ICON) + assertThat(visibleModel.contentDescriptionResourceId) + .isEqualTo(CONTENT_DESCRIPTION_RESOURCE_ID) job.cancel() } @Test - fun `invoke - affordance not visible when lockscreen is not showing`() = runBlockingTest { - repository.setKeyguardShowing(false) - val configKey = HomeControlsKeyguardQuickAffordanceConfig::class - val model = - KeyguardQuickAffordanceModel.Visible( - configKey = configKey, + fun `invoke - bottom start affordance hidden while dozing`() = runBlockingTest { + repository.setDozing(true) + homeControls.setState( + KeyguardQuickAffordanceConfig.State.Visible( icon = ICON, contentDescriptionResourceId = CONTENT_DESCRIPTION_RESOURCE_ID, ) - quickAffordanceRepository.setModel( - KeyguardQuickAffordancePosition.BOTTOM_END, - model, ) var latest: KeyguardQuickAffordanceModel? = null val job = - underTest(KeyguardQuickAffordancePosition.BOTTOM_END) + underTest(KeyguardQuickAffordancePosition.BOTTOM_START) .onEach { latest = it } .launchIn(this) assertThat(latest).isEqualTo(KeyguardQuickAffordanceModel.Hidden) @@ -139,20 +150,24 @@ class ObserveKeyguardQuickAffordanceUseCaseTest : SysuiTestCase() { } @Test - fun `invoke - affordance is none`() = runBlockingTest { - quickAffordanceRepository.setModel( - KeyguardQuickAffordancePosition.BOTTOM_START, - KeyguardQuickAffordanceModel.Hidden, - ) + fun `invoke - bottom start affordance hidden when lockscreen is not showing`() = + runBlockingTest { + repository.setKeyguardShowing(false) + homeControls.setState( + KeyguardQuickAffordanceConfig.State.Visible( + icon = ICON, + contentDescriptionResourceId = CONTENT_DESCRIPTION_RESOURCE_ID, + ) + ) - var latest: KeyguardQuickAffordanceModel? = null - val job = - underTest(KeyguardQuickAffordancePosition.BOTTOM_START) - .onEach { latest = it } - .launchIn(this) - assertThat(latest).isEqualTo(KeyguardQuickAffordanceModel.Hidden) - job.cancel() - } + var latest: KeyguardQuickAffordanceModel? = null + val job = + underTest(KeyguardQuickAffordancePosition.BOTTOM_START) + .onEach { latest = it } + .launchIn(this) + assertThat(latest).isEqualTo(KeyguardQuickAffordanceModel.Hidden) + job.cancel() + } companion object { private val ICON: ContainedDrawable = mock() 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 00dd58e19142..8758ce5eade6 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 @@ -22,22 +22,20 @@ 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.quickaffordance.KeyguardQuickAffordanceConfig -import com.android.systemui.keyguard.data.repository.FakeKeyguardQuickAffordanceConfig -import com.android.systemui.keyguard.data.repository.FakeKeyguardQuickAffordanceConfigs -import com.android.systemui.keyguard.data.repository.FakeKeyguardQuickAffordanceRepository import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository +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.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.ObserveIsKeyguardShowingUseCase -import com.android.systemui.keyguard.domain.usecase.ObserveKeyguardQuickAffordanceUseCase import com.android.systemui.keyguard.domain.usecase.OnKeyguardQuickAffordanceClickedUseCase -import com.android.systemui.keyguard.shared.model.KeyguardQuickAffordanceModel -import com.android.systemui.keyguard.shared.model.KeyguardQuickAffordancePosition import com.android.systemui.util.mockito.any import com.android.systemui.util.mockito.mock import com.google.common.truth.Truth.assertThat @@ -63,14 +61,14 @@ class KeyguardBottomAreaViewModelTest : SysuiTestCase() { private lateinit var underTest: KeyguardBottomAreaViewModel - private lateinit var affordanceRepository: FakeKeyguardQuickAffordanceRepository private lateinit var repository: FakeKeyguardRepository + private lateinit var registry: FakeKeyguardQuickAffordanceRegistry private lateinit var isDozingUseCase: ObserveIsDozingUseCase - private lateinit var isKeyguardShowingUseCase: ObserveIsKeyguardShowingUseCase 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() { @@ -78,33 +76,38 @@ class KeyguardBottomAreaViewModelTest : SysuiTestCase() { whenever(burnInHelperWrapper.burnInOffset(anyInt(), any())) .thenReturn(RETURNED_BURN_IN_OFFSET) - affordanceRepository = FakeKeyguardQuickAffordanceRepository() + homeControlsQuickAffordanceConfig = object : FakeKeyguardQuickAffordanceConfig() {} + quickAccessWalletAffordanceConfig = object : FakeKeyguardQuickAffordanceConfig() {} + qrCodeScannerAffordanceConfig = object : FakeKeyguardQuickAffordanceConfig() {} + registry = + FakeKeyguardQuickAffordanceRegistry( + mapOf( + KeyguardQuickAffordancePosition.BOTTOM_START to + listOf( + homeControlsQuickAffordanceConfig, + ), + KeyguardQuickAffordancePosition.BOTTOM_END to + listOf( + quickAccessWalletAffordanceConfig, + qrCodeScannerAffordanceConfig, + ), + ), + ) repository = FakeKeyguardRepository() isDozingUseCase = ObserveIsDozingUseCase( repository = repository, ) - isKeyguardShowingUseCase = - ObserveIsKeyguardShowingUseCase( - repository = repository, - ) launchQuickAffordanceUseCase = FakeLaunchKeyguardQuickAffordanceUseCase() - homeControlsQuickAffordanceConfig = object : FakeKeyguardQuickAffordanceConfig() {} - quickAccessWalletAffordanceConfig = object : FakeKeyguardQuickAffordanceConfig() {} - qrCodeScannerAffordanceConfig = object : FakeKeyguardQuickAffordanceConfig() {} + observeQuickAffordanceUseCase = FakeObserveKeyguardQuickAffordanceUseCase() underTest = KeyguardBottomAreaViewModel( - observeQuickAffordanceUseCase = - ObserveKeyguardQuickAffordanceUseCase( - repository = affordanceRepository, - isDozingUseCase = isDozingUseCase, - isKeyguardShowingUseCase = isKeyguardShowingUseCase, - ), + observeQuickAffordanceUseCase = observeQuickAffordanceUseCase, onQuickAffordanceClickedUseCase = OnKeyguardQuickAffordanceClickedUseCase( - configs = - FakeKeyguardQuickAffordanceConfigs( + registry = + FakeKeyguardQuickAffordanceRegistry( mapOf( KeyguardQuickAffordancePosition.BOTTOM_START to listOf( @@ -141,146 +144,79 @@ class KeyguardBottomAreaViewModelTest : SysuiTestCase() { } @Test - fun `startButton - present - not dozing - lockscreen showing - visible model - starts activity on click`() = // ktlint-disable max-line-length - runBlockingTest { - var latest: KeyguardQuickAffordanceViewModel? = null - val job = underTest.startButton.onEach { latest = it }.launchIn(this) - - repository.setDozing(false) - repository.setKeyguardShowing(true) - val testConfig = - TestConfig( - isVisible = true, - icon = mock(), - canShowWhileLocked = false, - intent = Intent("action"), - ) - val configKey = - setUpQuickAffordanceModel( - position = KeyguardQuickAffordancePosition.BOTTOM_START, - testConfig = testConfig, - ) + fun `startButton - present - visible model - starts activity on click`() = runBlockingTest { + var latest: KeyguardQuickAffordanceViewModel? = null + val job = underTest.startButton.onEach { latest = it }.launchIn(this) - assertQuickAffordanceViewModel( - viewModel = latest, - testConfig = testConfig, - configKey = configKey, + val testConfig = + TestConfig( + isVisible = true, + icon = mock(), + canShowWhileLocked = false, + intent = Intent("action"), ) - job.cancel() - } - - @Test - fun `endButton - present - not dozing - lockscreen showing - visible model - do nothing on click`() = // ktlint-disable max-line-length - runBlockingTest { - var latest: KeyguardQuickAffordanceViewModel? = null - val job = underTest.endButton.onEach { latest = it }.launchIn(this) - - repository.setDozing(false) - repository.setKeyguardShowing(true) - val config = - TestConfig( - isVisible = true, - icon = mock(), - canShowWhileLocked = false, - intent = - null, // This will cause it to tell the system that the click was handled. - ) - val configKey = - setUpQuickAffordanceModel( - position = KeyguardQuickAffordancePosition.BOTTOM_END, - testConfig = config, - ) - - assertQuickAffordanceViewModel( - viewModel = latest, - testConfig = config, - configKey = configKey, + val configKey = + setUpQuickAffordanceModel( + position = KeyguardQuickAffordancePosition.BOTTOM_START, + testConfig = testConfig, ) - job.cancel() - } - @Test - fun `startButton - not present - not dozing - lockscreen showing - model is none`() = - runBlockingTest { - var latest: KeyguardQuickAffordanceViewModel? = null - val job = underTest.startButton.onEach { latest = it }.launchIn(this) - - repository.setDozing(false) - repository.setKeyguardShowing(true) - val config = - TestConfig( - isVisible = false, - ) - val configKey = - setUpQuickAffordanceModel( - position = KeyguardQuickAffordancePosition.BOTTOM_START, - testConfig = config, - ) - - assertQuickAffordanceViewModel( - viewModel = latest, - testConfig = config, - configKey = configKey, - ) - job.cancel() - } + assertQuickAffordanceViewModel( + viewModel = latest, + testConfig = testConfig, + configKey = configKey, + ) + job.cancel() + } @Test - fun `startButton - present - dozing - lockscreen showing - model is none`() = runBlockingTest { + fun `endButton - present - visible model - do nothing on click`() = runBlockingTest { var latest: KeyguardQuickAffordanceViewModel? = null - val job = underTest.startButton.onEach { latest = it }.launchIn(this) + val job = underTest.endButton.onEach { latest = it }.launchIn(this) - repository.setDozing(true) - repository.setKeyguardShowing(true) val config = TestConfig( isVisible = true, icon = mock(), canShowWhileLocked = false, - intent = Intent("action"), + intent = null, // This will cause it to tell the system that the click was handled. ) val configKey = setUpQuickAffordanceModel( - position = KeyguardQuickAffordancePosition.BOTTOM_START, + position = KeyguardQuickAffordancePosition.BOTTOM_END, testConfig = config, ) assertQuickAffordanceViewModel( viewModel = latest, - testConfig = TestConfig(isVisible = false), + testConfig = config, configKey = configKey, ) job.cancel() } @Test - fun `startButton - present - not dozing - lockscreen not showing - model is none`() = - runBlockingTest { - var latest: KeyguardQuickAffordanceViewModel? = null - val job = underTest.startButton.onEach { latest = it }.launchIn(this) - - repository.setDozing(false) - repository.setKeyguardShowing(false) - val config = - TestConfig( - isVisible = true, - icon = mock(), - canShowWhileLocked = false, - intent = Intent("action"), - ) - val configKey = - setUpQuickAffordanceModel( - position = KeyguardQuickAffordancePosition.BOTTOM_START, - testConfig = config, - ) + fun `startButton - not present - model is hidden`() = runBlockingTest { + var latest: KeyguardQuickAffordanceViewModel? = null + val job = underTest.startButton.onEach { latest = it }.launchIn(this) - assertQuickAffordanceViewModel( - viewModel = latest, - testConfig = TestConfig(isVisible = false), - configKey = configKey, + val config = + TestConfig( + isVisible = false, + ) + val configKey = + setUpQuickAffordanceModel( + position = KeyguardQuickAffordancePosition.BOTTOM_START, + testConfig = config, ) - job.cancel() - } + + assertQuickAffordanceViewModel( + viewModel = latest, + testConfig = config, + configKey = configKey, + ) + job.cancel() + } @Test fun animateButtonReveal() = runBlockingTest { @@ -413,7 +349,7 @@ class KeyguardBottomAreaViewModelTest : SysuiTestCase() { job.cancel() } - private fun setDozeAmountAndCalculateExpectedTranslationY(dozeAmount: Float): Float { + private suspend fun setDozeAmountAndCalculateExpectedTranslationY(dozeAmount: Float): Float { repository.setDozeAmount(dozeAmount) return dozeAmount * (RETURNED_BURN_IN_OFFSET - DEFAULT_BURN_IN_OFFSET) } @@ -428,27 +364,31 @@ class KeyguardBottomAreaViewModelTest : SysuiTestCase() { KeyguardQuickAffordancePosition.BOTTOM_END -> quickAccessWalletAffordanceConfig } - affordanceRepository.setModel( - position = position, - model = - if (testConfig.isVisible) { - if (testConfig.intent != null) { - config.onClickedResult = - KeyguardQuickAffordanceConfig.OnClickedResult.StartActivity( - intent = testConfig.intent, - canShowWhileLocked = testConfig.canShowWhileLocked, - ) - } - KeyguardQuickAffordanceModel.Visible( - configKey = config::class, - icon = testConfig.icon ?: error("Icon is unexpectedly null!"), - contentDescriptionResourceId = CONTENT_DESCRIPTION_RESOURCE_ID, - ) - } else { - KeyguardQuickAffordanceModel.Hidden + val state = + if (testConfig.isVisible) { + if (testConfig.intent != null) { + config.onClickedResult = + KeyguardQuickAffordanceConfig.OnClickedResult.StartActivity( + intent = testConfig.intent, + canShowWhileLocked = testConfig.canShowWhileLocked, + ) } + KeyguardQuickAffordanceConfig.State.Visible( + icon = testConfig.icon ?: error("Icon is unexpectedly null!"), + contentDescriptionResourceId = CONTENT_DESCRIPTION_RESOURCE_ID, + ) + } else { + KeyguardQuickAffordanceConfig.State.Hidden + } + config.setState(state) + + val configKey = config::class + observeQuickAffordanceUseCase.setModel( + position, + KeyguardQuickAffordanceModel.from(state, configKey) ) - return config::class + + return configKey } private fun assertQuickAffordanceViewModel( |