Merge "KeyguardQuickAffordanceConfig: some renames" into tm-qpr-dev am: 4a3655b2db

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20275188

Change-Id: Ib28f40f9ea7f8bc1d90095d7acccc1db40ea9edd
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Ale Nijamkin
2022-10-27 17:34:31 +00:00
committed by Automerger Merge Worker
16 changed files with 219 additions and 207 deletions

View File

@@ -53,19 +53,19 @@ constructor(
override val key: String = BuiltInKeyguardQuickAffordanceKeys.HOME_CONTROLS
override val state: Flow<KeyguardQuickAffordanceConfig.State> =
override val lockScreenState: Flow<KeyguardQuickAffordanceConfig.LockScreenState> =
component.canShowWhileLockedSetting.flatMapLatest { canShowWhileLocked ->
if (canShowWhileLocked) {
stateInternal(component.getControlsListingController().getOrNull())
} else {
flowOf(KeyguardQuickAffordanceConfig.State.Hidden)
flowOf(KeyguardQuickAffordanceConfig.LockScreenState.Hidden)
}
}
override fun onQuickAffordanceClicked(
override fun onTriggered(
expandable: Expandable?,
): KeyguardQuickAffordanceConfig.OnClickedResult {
return KeyguardQuickAffordanceConfig.OnClickedResult.StartActivity(
): KeyguardQuickAffordanceConfig.OnTriggeredResult {
return KeyguardQuickAffordanceConfig.OnTriggeredResult.StartActivity(
intent =
Intent(appContext, ControlsActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
@@ -79,9 +79,9 @@ constructor(
private fun stateInternal(
listingController: ControlsListingController?,
): Flow<KeyguardQuickAffordanceConfig.State> {
): Flow<KeyguardQuickAffordanceConfig.LockScreenState> {
if (listingController == null) {
return flowOf(KeyguardQuickAffordanceConfig.State.Hidden)
return flowOf(KeyguardQuickAffordanceConfig.LockScreenState.Hidden)
}
return conflatedCallbackFlow {
@@ -116,7 +116,7 @@ constructor(
hasServiceInfos: Boolean,
visibility: ControlsComponent.Visibility,
@DrawableRes iconResourceId: Int?,
): KeyguardQuickAffordanceConfig.State {
): KeyguardQuickAffordanceConfig.LockScreenState {
return if (
isFeatureEnabled &&
hasFavorites &&
@@ -124,7 +124,7 @@ constructor(
iconResourceId != null &&
visibility == ControlsComponent.Visibility.AVAILABLE
) {
KeyguardQuickAffordanceConfig.State.Visible(
KeyguardQuickAffordanceConfig.LockScreenState.Visible(
icon =
Icon.Resource(
res = iconResourceId,
@@ -135,7 +135,7 @@ constructor(
),
)
} else {
KeyguardQuickAffordanceConfig.State.Hidden
KeyguardQuickAffordanceConfig.LockScreenState.Hidden
}
}

View File

@@ -20,7 +20,7 @@ package com.android.systemui.keyguard.data.quickaffordance
import android.content.Intent
import com.android.systemui.animation.Expandable
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.keyguard.shared.quickaffordance.KeyguardQuickAffordanceToggleState
import com.android.systemui.keyguard.shared.quickaffordance.ActivationState
import kotlinx.coroutines.flow.Flow
/** Defines interface that can act as data source for a single quick affordance model. */
@@ -29,51 +29,54 @@ interface KeyguardQuickAffordanceConfig {
/** Unique identifier for this quick affordance. It must be globally unique. */
val key: String
/** The observable [State] of the affordance. */
val state: Flow<State>
/**
* The ever-changing state of the affordance.
*
* Used to populate the lock screen.
*/
val lockScreenState: Flow<LockScreenState>
/**
* Notifies that the affordance was clicked by the user.
*
* @param expandable An [Expandable] to use when animating dialogs or activities
* @return An [OnClickedResult] telling the caller what to do next
* @return An [OnTriggeredResult] telling the caller what to do next
*/
fun onQuickAffordanceClicked(expandable: Expandable?): OnClickedResult
fun onTriggered(expandable: Expandable?): OnTriggeredResult
/**
* Encapsulates the state of a "quick affordance" in the keyguard bottom area (for example, a
* button on the lock-screen).
*/
sealed class State {
sealed class LockScreenState {
/** No affordance should show up. */
object Hidden : State()
object Hidden : LockScreenState()
/** An affordance is visible. */
data class Visible(
/** An icon for the affordance. */
val icon: Icon,
/** The toggle state for the affordance. */
val toggle: KeyguardQuickAffordanceToggleState =
KeyguardQuickAffordanceToggleState.NotSupported,
) : State()
/** The activation state of the affordance. */
val activationState: ActivationState = ActivationState.NotSupported,
) : LockScreenState()
}
sealed class OnClickedResult {
sealed class OnTriggeredResult {
/**
* Returning this as a result from the [onQuickAffordanceClicked] method means that the
* implementation has taken care of the click, the system will do nothing.
* Returning this as a result from the [onTriggered] method means that the implementation
* has taken care of the action, the system will do nothing.
*/
object Handled : OnClickedResult()
object Handled : OnTriggeredResult()
/**
* Returning this as a result from the [onQuickAffordanceClicked] method means that the
* implementation has _not_ taken care of the click and the system should start an activity
* using the given [Intent].
* Returning this as a result from the [onTriggered] method means that the implementation
* has _not_ taken care of the action and the system should start an activity using the
* given [Intent].
*/
data class StartActivity(
val intent: Intent,
val canShowWhileLocked: Boolean,
) : OnClickedResult()
) : OnTriggeredResult()
}
}

View File

@@ -39,46 +39,47 @@ constructor(
override val key: String = BuiltInKeyguardQuickAffordanceKeys.QR_CODE_SCANNER
override val state: Flow<KeyguardQuickAffordanceConfig.State> = conflatedCallbackFlow {
val callback =
object : QRCodeScannerController.Callback {
override fun onQRCodeScannerActivityChanged() {
trySendWithFailureLogging(state(), TAG)
override val lockScreenState: Flow<KeyguardQuickAffordanceConfig.LockScreenState> =
conflatedCallbackFlow {
val callback =
object : QRCodeScannerController.Callback {
override fun onQRCodeScannerActivityChanged() {
trySendWithFailureLogging(state(), TAG)
}
override fun onQRCodeScannerPreferenceChanged() {
trySendWithFailureLogging(state(), TAG)
}
}
override fun onQRCodeScannerPreferenceChanged() {
trySendWithFailureLogging(state(), TAG)
}
}
controller.addCallback(callback)
controller.registerQRCodeScannerChangeObservers(
QRCodeScannerController.DEFAULT_QR_CODE_SCANNER_CHANGE,
QRCodeScannerController.QR_CODE_SCANNER_PREFERENCE_CHANGE
)
// Registering does not push an initial update.
trySendWithFailureLogging(state(), "initial state", TAG)
awaitClose {
controller.unregisterQRCodeScannerChangeObservers(
controller.addCallback(callback)
controller.registerQRCodeScannerChangeObservers(
QRCodeScannerController.DEFAULT_QR_CODE_SCANNER_CHANGE,
QRCodeScannerController.QR_CODE_SCANNER_PREFERENCE_CHANGE
)
controller.removeCallback(callback)
}
}
// Registering does not push an initial update.
trySendWithFailureLogging(state(), "initial state", TAG)
override fun onQuickAffordanceClicked(
awaitClose {
controller.unregisterQRCodeScannerChangeObservers(
QRCodeScannerController.DEFAULT_QR_CODE_SCANNER_CHANGE,
QRCodeScannerController.QR_CODE_SCANNER_PREFERENCE_CHANGE
)
controller.removeCallback(callback)
}
}
override fun onTriggered(
expandable: Expandable?,
): KeyguardQuickAffordanceConfig.OnClickedResult {
return KeyguardQuickAffordanceConfig.OnClickedResult.StartActivity(
): KeyguardQuickAffordanceConfig.OnTriggeredResult {
return KeyguardQuickAffordanceConfig.OnTriggeredResult.StartActivity(
intent = controller.intent,
canShowWhileLocked = true,
)
}
private fun state(): KeyguardQuickAffordanceConfig.State {
private fun state(): KeyguardQuickAffordanceConfig.LockScreenState {
return if (controller.isEnabledForLockScreenButton) {
KeyguardQuickAffordanceConfig.State.Visible(
KeyguardQuickAffordanceConfig.LockScreenState.Visible(
icon =
Icon.Resource(
res = R.drawable.ic_qr_code_scanner,
@@ -89,7 +90,7 @@ constructor(
),
)
} else {
KeyguardQuickAffordanceConfig.State.Hidden
KeyguardQuickAffordanceConfig.LockScreenState.Hidden
}
}

View File

@@ -46,63 +46,64 @@ constructor(
override val key: String = BuiltInKeyguardQuickAffordanceKeys.QUICK_ACCESS_WALLET
override val state: Flow<KeyguardQuickAffordanceConfig.State> = conflatedCallbackFlow {
val callback =
object : QuickAccessWalletClient.OnWalletCardsRetrievedCallback {
override fun onWalletCardsRetrieved(response: GetWalletCardsResponse?) {
trySendWithFailureLogging(
state(
isFeatureEnabled = walletController.isWalletEnabled,
hasCard = response?.walletCards?.isNotEmpty() == true,
tileIcon = walletController.walletClient.tileIcon,
),
TAG,
)
override val lockScreenState: Flow<KeyguardQuickAffordanceConfig.LockScreenState> =
conflatedCallbackFlow {
val callback =
object : QuickAccessWalletClient.OnWalletCardsRetrievedCallback {
override fun onWalletCardsRetrieved(response: GetWalletCardsResponse?) {
trySendWithFailureLogging(
state(
isFeatureEnabled = walletController.isWalletEnabled,
hasCard = response?.walletCards?.isNotEmpty() == true,
tileIcon = walletController.walletClient.tileIcon,
),
TAG,
)
}
override fun onWalletCardRetrievalError(error: GetWalletCardsError?) {
Log.e(TAG, "Wallet card retrieval error, message: \"${error?.message}\"")
trySendWithFailureLogging(
KeyguardQuickAffordanceConfig.LockScreenState.Hidden,
TAG,
)
}
}
override fun onWalletCardRetrievalError(error: GetWalletCardsError?) {
Log.e(TAG, "Wallet card retrieval error, message: \"${error?.message}\"")
trySendWithFailureLogging(
KeyguardQuickAffordanceConfig.State.Hidden,
TAG,
)
}
}
walletController.setupWalletChangeObservers(
callback,
QuickAccessWalletController.WalletChangeEvent.WALLET_PREFERENCE_CHANGE,
QuickAccessWalletController.WalletChangeEvent.DEFAULT_PAYMENT_APP_CHANGE
)
walletController.updateWalletPreference()
walletController.queryWalletCards(callback)
awaitClose {
walletController.unregisterWalletChangeObservers(
walletController.setupWalletChangeObservers(
callback,
QuickAccessWalletController.WalletChangeEvent.WALLET_PREFERENCE_CHANGE,
QuickAccessWalletController.WalletChangeEvent.DEFAULT_PAYMENT_APP_CHANGE
)
}
}
walletController.updateWalletPreference()
walletController.queryWalletCards(callback)
override fun onQuickAffordanceClicked(
awaitClose {
walletController.unregisterWalletChangeObservers(
QuickAccessWalletController.WalletChangeEvent.WALLET_PREFERENCE_CHANGE,
QuickAccessWalletController.WalletChangeEvent.DEFAULT_PAYMENT_APP_CHANGE
)
}
}
override fun onTriggered(
expandable: Expandable?,
): KeyguardQuickAffordanceConfig.OnClickedResult {
): KeyguardQuickAffordanceConfig.OnTriggeredResult {
walletController.startQuickAccessUiIntent(
activityStarter,
expandable?.activityLaunchController(),
/* hasCard= */ true,
)
return KeyguardQuickAffordanceConfig.OnClickedResult.Handled
return KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled
}
private fun state(
isFeatureEnabled: Boolean,
hasCard: Boolean,
tileIcon: Drawable?,
): KeyguardQuickAffordanceConfig.State {
): KeyguardQuickAffordanceConfig.LockScreenState {
return if (isFeatureEnabled && hasCard && tileIcon != null) {
KeyguardQuickAffordanceConfig.State.Visible(
KeyguardQuickAffordanceConfig.LockScreenState.Visible(
icon =
Icon.Loaded(
drawable = tileIcon,
@@ -113,7 +114,7 @@ constructor(
),
)
} else {
KeyguardQuickAffordanceConfig.State.Hidden
KeyguardQuickAffordanceConfig.LockScreenState.Hidden
}
}

View File

@@ -62,25 +62,25 @@ constructor(
}
/**
* Notifies that a quick affordance has been clicked by the user.
* Notifies that a quick affordance has been "triggered" (clicked) by the user.
*
* @param configKey The configuration key corresponding to the [KeyguardQuickAffordanceModel] of
* the affordance that was clicked
* @param expandable An optional [Expandable] for the activity- or dialog-launch animation
*/
fun onQuickAffordanceClicked(
fun onQuickAffordanceTriggered(
configKey: String,
expandable: Expandable?,
) {
@Suppress("UNCHECKED_CAST") val config = registry.get(configKey)
when (val result = config.onQuickAffordanceClicked(expandable)) {
is KeyguardQuickAffordanceConfig.OnClickedResult.StartActivity ->
when (val result = config.onTriggered(expandable)) {
is KeyguardQuickAffordanceConfig.OnTriggeredResult.StartActivity ->
launchQuickAffordance(
intent = result.intent,
canShowWhileLocked = result.canShowWhileLocked,
expandable = expandable,
)
is KeyguardQuickAffordanceConfig.OnClickedResult.Handled -> Unit
is KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled -> Unit
}
}
@@ -94,16 +94,20 @@ constructor(
// value and avoid subtle bugs where the downstream isn't receiving any values
// because one config implementation is not emitting an initial value. For example,
// see b/244296596.
config.state.onStart { emit(KeyguardQuickAffordanceConfig.State.Hidden) }
config.lockScreenState.onStart {
emit(KeyguardQuickAffordanceConfig.LockScreenState.Hidden)
}
}
) { states ->
val index = states.indexOfFirst { it is KeyguardQuickAffordanceConfig.State.Visible }
val index =
states.indexOfFirst { it is KeyguardQuickAffordanceConfig.LockScreenState.Visible }
if (index != -1) {
val visibleState = states[index] as KeyguardQuickAffordanceConfig.State.Visible
val visibleState =
states[index] as KeyguardQuickAffordanceConfig.LockScreenState.Visible
KeyguardQuickAffordanceModel.Visible(
configKey = configs[index].key,
icon = visibleState.icon,
toggle = visibleState.toggle,
activationState = visibleState.activationState,
)
} else {
KeyguardQuickAffordanceModel.Hidden

View File

@@ -18,7 +18,7 @@
package com.android.systemui.keyguard.domain.model
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.keyguard.shared.quickaffordance.KeyguardQuickAffordanceToggleState
import com.android.systemui.keyguard.shared.quickaffordance.ActivationState
/**
* Models a "quick affordance" in the keyguard bottom area (for example, a button on the
@@ -34,7 +34,7 @@ sealed class KeyguardQuickAffordanceModel {
val configKey: String,
/** An icon for the affordance. */
val icon: Icon,
/** The toggle state for the affordance. */
val toggle: KeyguardQuickAffordanceToggleState,
/** The activation state of the affordance. */
val activationState: ActivationState,
) : KeyguardQuickAffordanceModel()
}

View File

@@ -17,12 +17,12 @@
package com.android.systemui.keyguard.shared.quickaffordance
/** Enumerates all possible toggle states for a quick affordance on the lock-screen. */
sealed class KeyguardQuickAffordanceToggleState {
/** Toggling is not supported. */
object NotSupported : KeyguardQuickAffordanceToggleState()
/** Enumerates all possible activation states for a quick affordance on the lock-screen. */
sealed class ActivationState {
/** Activation is not supported. */
object NotSupported : ActivationState()
/** The quick affordance is on. */
object On : KeyguardQuickAffordanceToggleState()
object Active : ActivationState()
/** The quick affordance is off. */
object Off : KeyguardQuickAffordanceToggleState()
object Inactive : ActivationState()
}

View File

@@ -22,8 +22,8 @@ import com.android.systemui.keyguard.domain.interactor.KeyguardBottomAreaInterac
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.shared.quickaffordance.ActivationState
import com.android.systemui.keyguard.shared.quickaffordance.KeyguardQuickAffordancePosition
import com.android.systemui.keyguard.shared.quickaffordance.KeyguardQuickAffordanceToggleState
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
@@ -118,13 +118,13 @@ constructor(
animateReveal = animateReveal,
icon = icon,
onClicked = { parameters ->
quickAffordanceInteractor.onQuickAffordanceClicked(
quickAffordanceInteractor.onQuickAffordanceTriggered(
configKey = parameters.configKey,
expandable = parameters.expandable,
)
},
isClickable = isClickable,
isActivated = toggle is KeyguardQuickAffordanceToggleState.On,
isActivated = activationState is ActivationState.Active,
)
is KeyguardQuickAffordanceModel.Hidden -> KeyguardQuickAffordanceViewModel()
}

View File

@@ -18,7 +18,7 @@
package com.android.systemui.keyguard.data.quickaffordance
import com.android.systemui.animation.Expandable
import com.android.systemui.keyguard.data.quickaffordance.KeyguardQuickAffordanceConfig.OnClickedResult
import com.android.systemui.keyguard.data.quickaffordance.KeyguardQuickAffordanceConfig.OnTriggeredResult
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.yield
@@ -33,22 +33,23 @@ abstract class FakeKeyguardQuickAffordanceConfig(
override val key: String,
) : KeyguardQuickAffordanceConfig {
var onClickedResult: OnClickedResult = OnClickedResult.Handled
var onTriggeredResult: OnTriggeredResult = OnTriggeredResult.Handled
private val _state =
MutableStateFlow<KeyguardQuickAffordanceConfig.State>(
KeyguardQuickAffordanceConfig.State.Hidden
private val _lockScreenState =
MutableStateFlow<KeyguardQuickAffordanceConfig.LockScreenState>(
KeyguardQuickAffordanceConfig.LockScreenState.Hidden
)
override val state: Flow<KeyguardQuickAffordanceConfig.State> = _state
override val lockScreenState: Flow<KeyguardQuickAffordanceConfig.LockScreenState> =
_lockScreenState
override fun onQuickAffordanceClicked(
override fun onTriggered(
expandable: Expandable?,
): OnClickedResult {
return onClickedResult
): OnTriggeredResult {
return onTriggeredResult
}
suspend fun setState(state: KeyguardQuickAffordanceConfig.State) {
_state.value = state
suspend fun setState(lockScreenState: KeyguardQuickAffordanceConfig.LockScreenState) {
_lockScreenState.value = lockScreenState
// 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

View File

@@ -122,8 +122,8 @@ class HomeControlsKeyguardQuickAffordanceConfigParameterizedStateTest : SysuiTes
emptyList()
}
)
val values = mutableListOf<KeyguardQuickAffordanceConfig.State>()
val job = underTest.state.onEach(values::add).launchIn(this)
val values = mutableListOf<KeyguardQuickAffordanceConfig.LockScreenState>()
val job = underTest.lockScreenState.onEach(values::add).launchIn(this)
if (canShowWhileLocked) {
verify(controlsListingController).addCallback(callbackCaptor.capture())
@@ -139,9 +139,9 @@ class HomeControlsKeyguardQuickAffordanceConfigParameterizedStateTest : SysuiTes
assertThat(values.last())
.isInstanceOf(
if (isVisibleExpected) {
KeyguardQuickAffordanceConfig.State.Visible::class.java
KeyguardQuickAffordanceConfig.LockScreenState.Visible::class.java
} else {
KeyguardQuickAffordanceConfig.State.Hidden::class.java
KeyguardQuickAffordanceConfig.LockScreenState.Hidden::class.java
}
)
job.cancel()

View File

@@ -23,7 +23,7 @@ import com.android.systemui.SysuiTestCase
import com.android.systemui.animation.Expandable
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.data.quickaffordance.KeyguardQuickAffordanceConfig.OnTriggeredResult
import com.android.systemui.util.mockito.mock
import com.google.common.truth.Truth.assertThat
import java.util.Optional
@@ -72,11 +72,11 @@ class HomeControlsKeyguardQuickAffordanceConfigTest : SysuiTestCase() {
whenever(component.getVisibility()).thenReturn(ControlsComponent.Visibility.AVAILABLE)
whenever(controlsController.getFavorites()).thenReturn(listOf(mock()))
val values = mutableListOf<KeyguardQuickAffordanceConfig.State>()
val job = underTest.state.onEach(values::add).launchIn(this)
val values = mutableListOf<KeyguardQuickAffordanceConfig.LockScreenState>()
val job = underTest.lockScreenState.onEach(values::add).launchIn(this)
assertThat(values.last())
.isInstanceOf(KeyguardQuickAffordanceConfig.State.Hidden::class.java)
.isInstanceOf(KeyguardQuickAffordanceConfig.LockScreenState.Hidden::class.java)
job.cancel()
}
@@ -91,31 +91,32 @@ class HomeControlsKeyguardQuickAffordanceConfigTest : SysuiTestCase() {
whenever(component.getVisibility()).thenReturn(ControlsComponent.Visibility.AVAILABLE)
whenever(controlsController.getFavorites()).thenReturn(listOf(mock()))
val values = mutableListOf<KeyguardQuickAffordanceConfig.State>()
val job = underTest.state.onEach(values::add).launchIn(this)
val values = mutableListOf<KeyguardQuickAffordanceConfig.LockScreenState>()
val job = underTest.lockScreenState.onEach(values::add).launchIn(this)
assertThat(values.last())
.isInstanceOf(KeyguardQuickAffordanceConfig.State.Hidden::class.java)
.isInstanceOf(KeyguardQuickAffordanceConfig.LockScreenState.Hidden::class.java)
job.cancel()
}
@Test
fun `onQuickAffordanceClicked - canShowWhileLockedSetting is true`() = runBlockingTest {
fun `onQuickAffordanceTriggered - canShowWhileLockedSetting is true`() = runBlockingTest {
whenever(component.canShowWhileLockedSetting).thenReturn(MutableStateFlow(true))
val onClickedResult = underTest.onQuickAffordanceClicked(expandable)
val onClickedResult = underTest.onTriggered(expandable)
assertThat(onClickedResult).isInstanceOf(OnClickedResult.StartActivity::class.java)
assertThat((onClickedResult as OnClickedResult.StartActivity).canShowWhileLocked).isTrue()
assertThat(onClickedResult).isInstanceOf(OnTriggeredResult.StartActivity::class.java)
assertThat((onClickedResult as OnTriggeredResult.StartActivity).canShowWhileLocked).isTrue()
}
@Test
fun `onQuickAffordanceClicked - canShowWhileLockedSetting is false`() = runBlockingTest {
fun `onQuickAffordanceTriggered - canShowWhileLockedSetting is false`() = runBlockingTest {
whenever(component.canShowWhileLockedSetting).thenReturn(MutableStateFlow(false))
val onClickedResult = underTest.onQuickAffordanceClicked(expandable)
val onClickedResult = underTest.onTriggered(expandable)
assertThat(onClickedResult).isInstanceOf(OnClickedResult.StartActivity::class.java)
assertThat((onClickedResult as OnClickedResult.StartActivity).canShowWhileLocked).isFalse()
assertThat(onClickedResult).isInstanceOf(OnTriggeredResult.StartActivity::class.java)
assertThat((onClickedResult as OnTriggeredResult.StartActivity).canShowWhileLocked)
.isFalse()
}
}

View File

@@ -20,7 +20,7 @@ package com.android.systemui.keyguard.data.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.data.quickaffordance.KeyguardQuickAffordanceConfig.OnTriggeredResult
import com.android.systemui.qrcodescanner.controller.QRCodeScannerController
import com.android.systemui.util.mockito.argumentCaptor
import com.android.systemui.util.mockito.mock
@@ -56,9 +56,9 @@ class QrCodeScannerKeyguardQuickAffordanceConfigTest : SysuiTestCase() {
@Test
fun `affordance - sets up registration and delivers initial model`() = runBlockingTest {
whenever(controller.isEnabledForLockScreenButton).thenReturn(true)
var latest: KeyguardQuickAffordanceConfig.State? = null
var latest: KeyguardQuickAffordanceConfig.LockScreenState? = null
val job = underTest.state.onEach { latest = it }.launchIn(this)
val job = underTest.lockScreenState.onEach { latest = it }.launchIn(this)
val callbackCaptor = argumentCaptor<QRCodeScannerController.Callback>()
verify(controller).addCallback(callbackCaptor.capture())
@@ -77,8 +77,8 @@ class QrCodeScannerKeyguardQuickAffordanceConfigTest : SysuiTestCase() {
fun `affordance - scanner activity changed - delivers model with updated intent`() =
runBlockingTest {
whenever(controller.isEnabledForLockScreenButton).thenReturn(true)
var latest: KeyguardQuickAffordanceConfig.State? = null
val job = underTest.state.onEach { latest = it }.launchIn(this)
var latest: KeyguardQuickAffordanceConfig.LockScreenState? = null
val job = underTest.lockScreenState.onEach { latest = it }.launchIn(this)
val callbackCaptor = argumentCaptor<QRCodeScannerController.Callback>()
verify(controller).addCallback(callbackCaptor.capture())
@@ -93,8 +93,8 @@ class QrCodeScannerKeyguardQuickAffordanceConfigTest : SysuiTestCase() {
@Test
fun `affordance - scanner preference changed - delivers visible model`() = runBlockingTest {
var latest: KeyguardQuickAffordanceConfig.State? = null
val job = underTest.state.onEach { latest = it }.launchIn(this)
var latest: KeyguardQuickAffordanceConfig.LockScreenState? = null
val job = underTest.lockScreenState.onEach { latest = it }.launchIn(this)
val callbackCaptor = argumentCaptor<QRCodeScannerController.Callback>()
verify(controller).addCallback(callbackCaptor.capture())
@@ -109,34 +109,35 @@ class QrCodeScannerKeyguardQuickAffordanceConfigTest : SysuiTestCase() {
@Test
fun `affordance - scanner preference changed - delivers none`() = runBlockingTest {
var latest: KeyguardQuickAffordanceConfig.State? = null
val job = underTest.state.onEach { latest = it }.launchIn(this)
var latest: KeyguardQuickAffordanceConfig.LockScreenState? = null
val job = underTest.lockScreenState.onEach { latest = it }.launchIn(this)
val callbackCaptor = argumentCaptor<QRCodeScannerController.Callback>()
verify(controller).addCallback(callbackCaptor.capture())
whenever(controller.isEnabledForLockScreenButton).thenReturn(false)
callbackCaptor.value.onQRCodeScannerPreferenceChanged()
assertThat(latest).isEqualTo(KeyguardQuickAffordanceConfig.State.Hidden)
assertThat(latest).isEqualTo(KeyguardQuickAffordanceConfig.LockScreenState.Hidden)
job.cancel()
verify(controller).removeCallback(callbackCaptor.value)
}
@Test
fun onQuickAffordanceClicked() {
assertThat(underTest.onQuickAffordanceClicked(mock()))
fun onQuickAffordanceTriggered() {
assertThat(underTest.onTriggered(mock()))
.isEqualTo(
OnClickedResult.StartActivity(
OnTriggeredResult.StartActivity(
intent = INTENT_1,
canShowWhileLocked = true,
)
)
}
private fun assertVisibleState(latest: KeyguardQuickAffordanceConfig.State?) {
assertThat(latest).isInstanceOf(KeyguardQuickAffordanceConfig.State.Visible::class.java)
val visibleState = latest as KeyguardQuickAffordanceConfig.State.Visible
private fun assertVisibleState(latest: KeyguardQuickAffordanceConfig.LockScreenState?) {
assertThat(latest)
.isInstanceOf(KeyguardQuickAffordanceConfig.LockScreenState.Visible::class.java)
val visibleState = latest as KeyguardQuickAffordanceConfig.LockScreenState.Visible
assertThat(visibleState.icon).isNotNull()
assertThat(visibleState.icon.contentDescription).isNotNull()
}

View File

@@ -67,11 +67,11 @@ class QuickAccessWalletKeyguardQuickAffordanceConfigTest : SysuiTestCase() {
@Test
fun `affordance - keyguard showing - has wallet card - visible model`() = runBlockingTest {
setUpState()
var latest: KeyguardQuickAffordanceConfig.State? = null
var latest: KeyguardQuickAffordanceConfig.LockScreenState? = null
val job = underTest.state.onEach { latest = it }.launchIn(this)
val job = underTest.lockScreenState.onEach { latest = it }.launchIn(this)
val visibleModel = latest as KeyguardQuickAffordanceConfig.State.Visible
val visibleModel = latest as KeyguardQuickAffordanceConfig.LockScreenState.Visible
assertThat(visibleModel.icon)
.isEqualTo(
Icon.Loaded(
@@ -88,11 +88,11 @@ class QuickAccessWalletKeyguardQuickAffordanceConfigTest : SysuiTestCase() {
@Test
fun `affordance - wallet not enabled - model is none`() = runBlockingTest {
setUpState(isWalletEnabled = false)
var latest: KeyguardQuickAffordanceConfig.State? = null
var latest: KeyguardQuickAffordanceConfig.LockScreenState? = null
val job = underTest.state.onEach { latest = it }.launchIn(this)
val job = underTest.lockScreenState.onEach { latest = it }.launchIn(this)
assertThat(latest).isEqualTo(KeyguardQuickAffordanceConfig.State.Hidden)
assertThat(latest).isEqualTo(KeyguardQuickAffordanceConfig.LockScreenState.Hidden)
job.cancel()
}
@@ -100,11 +100,11 @@ class QuickAccessWalletKeyguardQuickAffordanceConfigTest : SysuiTestCase() {
@Test
fun `affordance - query not successful - model is none`() = runBlockingTest {
setUpState(isWalletQuerySuccessful = false)
var latest: KeyguardQuickAffordanceConfig.State? = null
var latest: KeyguardQuickAffordanceConfig.LockScreenState? = null
val job = underTest.state.onEach { latest = it }.launchIn(this)
val job = underTest.lockScreenState.onEach { latest = it }.launchIn(this)
assertThat(latest).isEqualTo(KeyguardQuickAffordanceConfig.State.Hidden)
assertThat(latest).isEqualTo(KeyguardQuickAffordanceConfig.LockScreenState.Hidden)
job.cancel()
}
@@ -112,11 +112,11 @@ class QuickAccessWalletKeyguardQuickAffordanceConfigTest : SysuiTestCase() {
@Test
fun `affordance - missing icon - model is none`() = runBlockingTest {
setUpState(hasWalletIcon = false)
var latest: KeyguardQuickAffordanceConfig.State? = null
var latest: KeyguardQuickAffordanceConfig.LockScreenState? = null
val job = underTest.state.onEach { latest = it }.launchIn(this)
val job = underTest.lockScreenState.onEach { latest = it }.launchIn(this)
assertThat(latest).isEqualTo(KeyguardQuickAffordanceConfig.State.Hidden)
assertThat(latest).isEqualTo(KeyguardQuickAffordanceConfig.LockScreenState.Hidden)
job.cancel()
}
@@ -124,24 +124,24 @@ class QuickAccessWalletKeyguardQuickAffordanceConfigTest : SysuiTestCase() {
@Test
fun `affordance - no selected card - model is none`() = runBlockingTest {
setUpState(hasWalletIcon = false)
var latest: KeyguardQuickAffordanceConfig.State? = null
var latest: KeyguardQuickAffordanceConfig.LockScreenState? = null
val job = underTest.state.onEach { latest = it }.launchIn(this)
val job = underTest.lockScreenState.onEach { latest = it }.launchIn(this)
assertThat(latest).isEqualTo(KeyguardQuickAffordanceConfig.State.Hidden)
assertThat(latest).isEqualTo(KeyguardQuickAffordanceConfig.LockScreenState.Hidden)
job.cancel()
}
@Test
fun onQuickAffordanceClicked() {
fun onQuickAffordanceTriggered() {
val animationController: ActivityLaunchAnimator.Controller = mock()
val expandable: Expandable = mock {
whenever(this.activityLaunchController()).thenReturn(animationController)
}
assertThat(underTest.onQuickAffordanceClicked(expandable))
.isEqualTo(KeyguardQuickAffordanceConfig.OnClickedResult.Handled)
assertThat(underTest.onTriggered(expandable))
.isEqualTo(KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled)
verify(walletController)
.startQuickAccessUiIntent(
activityStarter,

View File

@@ -248,29 +248,29 @@ class KeyguardQuickAffordanceInteractorParameterizedTest : SysuiTestCase() {
}
@Test
fun onQuickAffordanceClicked() = runBlockingTest {
fun onQuickAffordanceTriggered() = runBlockingTest {
setUpMocks(
needStrongAuthAfterBoot = needStrongAuthAfterBoot,
keyguardIsUnlocked = keyguardIsUnlocked,
)
homeControls.setState(
state =
KeyguardQuickAffordanceConfig.State.Visible(
lockScreenState =
KeyguardQuickAffordanceConfig.LockScreenState.Visible(
icon = DRAWABLE,
)
)
homeControls.onClickedResult =
homeControls.onTriggeredResult =
if (startActivity) {
KeyguardQuickAffordanceConfig.OnClickedResult.StartActivity(
KeyguardQuickAffordanceConfig.OnTriggeredResult.StartActivity(
intent = INTENT,
canShowWhileLocked = canShowWhileLocked,
)
} else {
KeyguardQuickAffordanceConfig.OnClickedResult.Handled
KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled
}
underTest.onQuickAffordanceClicked(
underTest.onQuickAffordanceTriggered(
configKey = BuiltInKeyguardQuickAffordanceKeys.HOME_CONTROLS,
expandable = expandable,
)

View File

@@ -28,8 +28,8 @@ import com.android.systemui.keyguard.data.quickaffordance.KeyguardQuickAffordanc
import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository
import com.android.systemui.keyguard.domain.model.KeyguardQuickAffordanceModel
import com.android.systemui.keyguard.domain.quickaffordance.FakeKeyguardQuickAffordanceRegistry
import com.android.systemui.keyguard.shared.quickaffordance.ActivationState
import com.android.systemui.keyguard.shared.quickaffordance.KeyguardQuickAffordancePosition
import com.android.systemui.keyguard.shared.quickaffordance.KeyguardQuickAffordanceToggleState
import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.settings.UserTracker
import com.android.systemui.statusbar.policy.KeyguardStateController
@@ -114,9 +114,9 @@ class KeyguardQuickAffordanceInteractorTest : SysuiTestCase() {
fun `quickAffordance - bottom start affordance is visible`() = runBlockingTest {
val configKey = BuiltInKeyguardQuickAffordanceKeys.HOME_CONTROLS
homeControls.setState(
KeyguardQuickAffordanceConfig.State.Visible(
KeyguardQuickAffordanceConfig.LockScreenState.Visible(
icon = ICON,
toggle = KeyguardQuickAffordanceToggleState.On,
activationState = ActivationState.Active,
)
)
@@ -137,7 +137,7 @@ class KeyguardQuickAffordanceInteractorTest : SysuiTestCase() {
assertThat(visibleModel.icon).isEqualTo(ICON)
assertThat(visibleModel.icon.contentDescription)
.isEqualTo(ContentDescription.Resource(res = CONTENT_DESCRIPTION_RESOURCE_ID))
assertThat(visibleModel.toggle).isEqualTo(KeyguardQuickAffordanceToggleState.On)
assertThat(visibleModel.activationState).isEqualTo(ActivationState.Active)
job.cancel()
}
@@ -145,7 +145,7 @@ class KeyguardQuickAffordanceInteractorTest : SysuiTestCase() {
fun `quickAffordance - bottom end affordance is visible`() = runBlockingTest {
val configKey = BuiltInKeyguardQuickAffordanceKeys.QUICK_ACCESS_WALLET
quickAccessWallet.setState(
KeyguardQuickAffordanceConfig.State.Visible(
KeyguardQuickAffordanceConfig.LockScreenState.Visible(
icon = ICON,
)
)
@@ -167,7 +167,7 @@ class KeyguardQuickAffordanceInteractorTest : SysuiTestCase() {
assertThat(visibleModel.icon).isEqualTo(ICON)
assertThat(visibleModel.icon.contentDescription)
.isEqualTo(ContentDescription.Resource(res = CONTENT_DESCRIPTION_RESOURCE_ID))
assertThat(visibleModel.toggle).isEqualTo(KeyguardQuickAffordanceToggleState.NotSupported)
assertThat(visibleModel.activationState).isEqualTo(ActivationState.NotSupported)
job.cancel()
}
@@ -175,7 +175,7 @@ class KeyguardQuickAffordanceInteractorTest : SysuiTestCase() {
fun `quickAffordance - bottom start affordance hidden while dozing`() = runBlockingTest {
repository.setDozing(true)
homeControls.setState(
KeyguardQuickAffordanceConfig.State.Visible(
KeyguardQuickAffordanceConfig.LockScreenState.Visible(
icon = ICON,
)
)
@@ -195,7 +195,7 @@ class KeyguardQuickAffordanceInteractorTest : SysuiTestCase() {
runBlockingTest {
repository.setKeyguardShowing(false)
homeControls.setState(
KeyguardQuickAffordanceConfig.State.Visible(
KeyguardQuickAffordanceConfig.LockScreenState.Visible(
icon = ICON,
)
)

View File

@@ -31,8 +31,8 @@ import com.android.systemui.keyguard.domain.interactor.KeyguardBottomAreaInterac
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
import com.android.systemui.keyguard.domain.interactor.KeyguardQuickAffordanceInteractor
import com.android.systemui.keyguard.domain.quickaffordance.FakeKeyguardQuickAffordanceRegistry
import com.android.systemui.keyguard.shared.quickaffordance.ActivationState
import com.android.systemui.keyguard.shared.quickaffordance.KeyguardQuickAffordancePosition
import com.android.systemui.keyguard.shared.quickaffordance.KeyguardQuickAffordanceToggleState
import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.settings.UserTracker
import com.android.systemui.statusbar.policy.KeyguardStateController
@@ -508,28 +508,28 @@ class KeyguardBottomAreaViewModelTest : SysuiTestCase() {
KeyguardQuickAffordancePosition.BOTTOM_END -> quickAccessWalletAffordanceConfig
}
val state =
val lockScreenState =
if (testConfig.isVisible) {
if (testConfig.intent != null) {
config.onClickedResult =
KeyguardQuickAffordanceConfig.OnClickedResult.StartActivity(
config.onTriggeredResult =
KeyguardQuickAffordanceConfig.OnTriggeredResult.StartActivity(
intent = testConfig.intent,
canShowWhileLocked = testConfig.canShowWhileLocked,
)
}
KeyguardQuickAffordanceConfig.State.Visible(
KeyguardQuickAffordanceConfig.LockScreenState.Visible(
icon = testConfig.icon ?: error("Icon is unexpectedly null!"),
toggle =
activationState =
when (testConfig.isActivated) {
true -> KeyguardQuickAffordanceToggleState.On
false -> KeyguardQuickAffordanceToggleState.Off
null -> KeyguardQuickAffordanceToggleState.NotSupported
true -> ActivationState.Active
false -> ActivationState.Inactive
null -> ActivationState.NotSupported
}
)
} else {
KeyguardQuickAffordanceConfig.State.Hidden
KeyguardQuickAffordanceConfig.LockScreenState.Hidden
}
config.setState(state)
config.setState(lockScreenState)
return config.key
}