Long-press to configure quick affordances (1/2).

Adds logic to allow quick affordance configuration through a long-press
in the wallpaper picker UI. Also adds such a configuration long-press
for the Do Not Disturbe (DND) affordance.

Fix: 261747112
Test: unit test added
Test: manually verified that long-press on the DND quick affordance
opens the DND settings activity
Test: manually verified that select/unselect all still work

Change-Id: Iabc67f62a106f5d48d6a0dab32096a27d1ff5fed
This commit is contained in:
Alejandro Nijamkin
2022-12-28 14:11:58 -08:00
parent ba739bc09f
commit c26282edc4
14 changed files with 281 additions and 190 deletions

View File

@@ -20,12 +20,15 @@ package com.android.systemui.shared.customization.data.content
import android.annotation.SuppressLint
import android.content.ContentValues
import android.content.Context
import android.content.Intent
import android.database.ContentObserver
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.net.Uri
import android.util.Log
import androidx.annotation.DrawableRes
import com.android.systemui.shared.customization.data.content.CustomizationProviderContract as Contract
import java.net.URISyntaxException
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
@@ -169,6 +172,8 @@ interface CustomizationProviderClient {
* If `null`, the button should not be shown.
*/
val enablementActionComponentName: String? = null,
/** Optional [Intent] to use to start an activity to configure this affordance. */
val configureIntent: Intent? = null,
)
/** Models a selection of a quick affordance on a slot. */
@@ -337,6 +342,11 @@ class CustomizationProviderClientImpl(
Contract.LockScreenQuickAffordances.AffordanceTable.Columns
.ENABLEMENT_COMPONENT_NAME
)
val configureIntentColumnIndex =
cursor.getColumnIndex(
Contract.LockScreenQuickAffordances.AffordanceTable.Columns
.CONFIGURE_INTENT
)
if (
idColumnIndex == -1 ||
nameColumnIndex == -1 ||
@@ -344,15 +354,17 @@ class CustomizationProviderClientImpl(
isEnabledColumnIndex == -1 ||
enablementInstructionsColumnIndex == -1 ||
enablementActionTextColumnIndex == -1 ||
enablementComponentNameColumnIndex == -1
enablementComponentNameColumnIndex == -1 ||
configureIntentColumnIndex == -1
) {
return@buildList
}
while (cursor.moveToNext()) {
val affordanceId = cursor.getString(idColumnIndex)
add(
CustomizationProviderClient.Affordance(
id = cursor.getString(idColumnIndex),
id = affordanceId,
name = cursor.getString(nameColumnIndex),
iconResourceId = cursor.getInt(iconColumnIndex),
isEnabled = cursor.getInt(isEnabledColumnIndex) == 1,
@@ -367,6 +379,10 @@ class CustomizationProviderClientImpl(
cursor.getString(enablementActionTextColumnIndex),
enablementActionComponentName =
cursor.getString(enablementComponentNameColumnIndex),
configureIntent =
cursor
.getString(configureIntentColumnIndex)
?.toIntent(affordanceId = affordanceId),
)
)
}
@@ -504,7 +520,19 @@ class CustomizationProviderClientImpl(
.onStart { emit(Unit) }
}
private fun String.toIntent(
affordanceId: String,
): Intent? {
return try {
Intent.parseUri(this, 0)
} catch (e: URISyntaxException) {
Log.w(TAG, "Cannot parse Uri into Intent for affordance with ID \"$affordanceId\"!")
null
}
}
companion object {
private const val TAG = "CustomizationProviderClient"
private const val SYSTEM_UI_PACKAGE_NAME = "com.android.systemui"
}
}

View File

@@ -113,6 +113,11 @@ object CustomizationProviderContract {
* opens a destination where the user can re-enable the disabled affordance.
*/
const val ENABLEMENT_COMPONENT_NAME = "enablement_action_intent"
/**
* Byte array. Optional parcelled `Intent` to use to start an activity that can be
* used to configure the affordance.
*/
const val CONFIGURE_INTENT = "configure_intent"
}
}

View File

@@ -282,6 +282,7 @@ class CustomizationProvider :
.ENABLEMENT_ACTION_TEXT,
Contract.LockScreenQuickAffordances.AffordanceTable.Columns
.ENABLEMENT_COMPONENT_NAME,
Contract.LockScreenQuickAffordances.AffordanceTable.Columns.CONFIGURE_INTENT,
)
)
.apply {
@@ -298,6 +299,7 @@ class CustomizationProvider :
),
representation.actionText,
representation.actionComponentName,
representation.configureIntent?.toUri(0),
)
)
}

View File

@@ -17,6 +17,7 @@
package com.android.systemui.keyguard.data.quickaffordance
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.provider.Settings
import android.provider.Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS
@@ -39,6 +40,7 @@ import com.android.systemui.settings.UserTracker
import com.android.systemui.statusbar.policy.ZenModeController
import com.android.systemui.util.settings.SecureSettings
import com.android.systemui.util.settings.SettingsProxyExt.observerFlow
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
@@ -48,10 +50,10 @@ import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onStart
import javax.inject.Inject
@SysUISingleton
class DoNotDisturbQuickAffordanceConfig constructor(
class DoNotDisturbQuickAffordanceConfig
constructor(
private val context: Context,
private val controller: ZenModeController,
private val secureSettings: SecureSettings,
@@ -59,7 +61,7 @@ class DoNotDisturbQuickAffordanceConfig constructor(
@Background private val backgroundDispatcher: CoroutineDispatcher,
private val testConditionId: Uri?,
testDialog: EnableZenModeDialog?,
): KeyguardQuickAffordanceConfig {
) : KeyguardQuickAffordanceConfig {
@Inject
constructor(
@@ -76,20 +78,23 @@ class DoNotDisturbQuickAffordanceConfig constructor(
private val conditionUri: Uri
get() =
testConditionId ?: ZenModeConfig.toTimeCondition(
context,
settingsValue,
userTracker.userId,
true, /* shortVersion */
).id
testConditionId
?: ZenModeConfig.toTimeCondition(
context,
settingsValue,
userTracker.userId,
true, /* shortVersion */
)
.id
private val dialog: EnableZenModeDialog by lazy {
testDialog ?: EnableZenModeDialog(
context,
R.style.Theme_SystemUI_Dialog,
true, /* cancelIsNeutral */
ZenModeDialogMetricsLogger(context),
)
testDialog
?: EnableZenModeDialog(
context,
R.style.Theme_SystemUI_Dialog,
true, /* cancelIsNeutral */
ZenModeDialogMetricsLogger(context),
)
}
override val key: String = BuiltInKeyguardQuickAffordanceKeys.DO_NOT_DISTURB
@@ -98,58 +103,62 @@ class DoNotDisturbQuickAffordanceConfig constructor(
override val pickerIconResourceId: Int = R.drawable.ic_do_not_disturb
override val lockScreenState: Flow<KeyguardQuickAffordanceConfig.LockScreenState> = combine(
conflatedCallbackFlow {
val callback = object: ZenModeController.Callback {
override fun onZenChanged(zen: Int) {
dndMode = zen
trySendWithFailureLogging(updateState(), TAG)
}
override val lockScreenState: Flow<KeyguardQuickAffordanceConfig.LockScreenState> =
combine(
conflatedCallbackFlow {
val callback =
object : ZenModeController.Callback {
override fun onZenChanged(zen: Int) {
dndMode = zen
trySendWithFailureLogging(updateState(), TAG)
}
override fun onZenAvailableChanged(available: Boolean) {
isAvailable = available
trySendWithFailureLogging(updateState(), TAG)
}
}
override fun onZenAvailableChanged(available: Boolean) {
isAvailable = available
trySendWithFailureLogging(updateState(), TAG)
}
}
dndMode = controller.zen
isAvailable = controller.isZenAvailable
trySendWithFailureLogging(updateState(), TAG)
dndMode = controller.zen
isAvailable = controller.isZenAvailable
trySendWithFailureLogging(updateState(), TAG)
controller.addCallback(callback)
controller.addCallback(callback)
awaitClose { controller.removeCallback(callback) }
},
secureSettings
.observerFlow(Settings.Secure.ZEN_DURATION)
.onStart { emit(Unit) }
.map { secureSettings.getInt(Settings.Secure.ZEN_DURATION, ZEN_MODE_OFF) }
.flowOn(backgroundDispatcher)
.distinctUntilChanged()
.onEach { settingsValue = it }
) { callbackFlowValue, _ -> callbackFlowValue }
awaitClose { controller.removeCallback(callback) }
},
secureSettings
.observerFlow(Settings.Secure.ZEN_DURATION)
.onStart { emit(Unit) }
.map { secureSettings.getInt(Settings.Secure.ZEN_DURATION, ZEN_MODE_OFF) }
.flowOn(backgroundDispatcher)
.distinctUntilChanged()
.onEach { settingsValue = it }
) { callbackFlowValue, _ -> callbackFlowValue }
override suspend fun getPickerScreenState(): KeyguardQuickAffordanceConfig.PickerScreenState {
return if (controller.isZenAvailable) {
KeyguardQuickAffordanceConfig.PickerScreenState.Default
KeyguardQuickAffordanceConfig.PickerScreenState.Default(
configureIntent = Intent(Settings.ACTION_ZEN_MODE_SETTINGS)
)
} else {
KeyguardQuickAffordanceConfig.PickerScreenState.UnavailableOnDevice
}
}
override fun onTriggered(expandable: Expandable?):
KeyguardQuickAffordanceConfig.OnTriggeredResult {
override fun onTriggered(
expandable: Expandable?
): KeyguardQuickAffordanceConfig.OnTriggeredResult {
return when {
!isAvailable ->
KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled
!isAvailable -> KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled
dndMode != ZEN_MODE_OFF -> {
controller.setZen(ZEN_MODE_OFF, null, TAG)
KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled
}
settingsValue == ZEN_DURATION_PROMPT ->
KeyguardQuickAffordanceConfig.OnTriggeredResult.ShowDialog(
dialog.createDialog(),
expandable
dialog.createDialog(),
expandable
)
settingsValue == ZEN_DURATION_FOREVER -> {
controller.setZen(ZEN_MODE_IMPORTANT_INTERRUPTIONS, null, TAG)
@@ -187,4 +196,4 @@ class DoNotDisturbQuickAffordanceConfig constructor(
companion object {
const val TAG = "DoNotDisturbQuickAffordanceConfig"
}
}
}

View File

@@ -135,7 +135,7 @@ constructor(
override suspend fun getPickerScreenState(): KeyguardQuickAffordanceConfig.PickerScreenState =
if (flashlightController.isAvailable) {
KeyguardQuickAffordanceConfig.PickerScreenState.Default
KeyguardQuickAffordanceConfig.PickerScreenState.Default()
} else {
KeyguardQuickAffordanceConfig.PickerScreenState.UnavailableOnDevice
}

View File

@@ -90,7 +90,7 @@ constructor(
)
}
return KeyguardQuickAffordanceConfig.PickerScreenState.Default
return KeyguardQuickAffordanceConfig.PickerScreenState.Default()
}
override fun onTriggered(

View File

@@ -46,7 +46,7 @@ interface KeyguardQuickAffordanceConfig {
* Returns the [PickerScreenState] representing the affordance in the settings or selector
* experience.
*/
suspend fun getPickerScreenState(): PickerScreenState = PickerScreenState.Default
suspend fun getPickerScreenState(): PickerScreenState = PickerScreenState.Default()
/**
* Notifies that the affordance was clicked by the user.
@@ -63,7 +63,10 @@ interface KeyguardQuickAffordanceConfig {
sealed class PickerScreenState {
/** The picker shows the item for selecting this affordance as it normally would. */
object Default : PickerScreenState()
data class Default(
/** Optional [Intent] to use to start an activity to configure this affordance. */
val configureIntent: Intent? = null,
) : PickerScreenState()
/**
* The picker does not show an item for selecting this affordance as it is not supported on

View File

@@ -89,7 +89,7 @@ constructor(
),
),
)
else -> KeyguardQuickAffordanceConfig.PickerScreenState.Default
else -> KeyguardQuickAffordanceConfig.PickerScreenState.Default()
}
}

View File

@@ -128,7 +128,7 @@ constructor(
actionComponentName = componentName,
)
}
else -> KeyguardQuickAffordanceConfig.PickerScreenState.Default
else -> KeyguardQuickAffordanceConfig.PickerScreenState.Default()
}
}

View File

@@ -187,6 +187,8 @@ constructor(
pickerState is KeyguardQuickAffordanceConfig.PickerScreenState.UnavailableOnDevice
}
.map { (config, pickerState) ->
val defaultPickerState =
pickerState as? KeyguardQuickAffordanceConfig.PickerScreenState.Default
val disabledPickerState =
pickerState as? KeyguardQuickAffordanceConfig.PickerScreenState.Disabled
KeyguardQuickAffordancePickerRepresentation(
@@ -198,6 +200,7 @@ constructor(
instructions = disabledPickerState?.instructions,
actionText = disabledPickerState?.actionText,
actionComponentName = disabledPickerState?.actionComponentName,
configureIntent = defaultPickerState?.configureIntent,
)
}
}

View File

@@ -17,6 +17,7 @@
package com.android.systemui.keyguard.shared.model
import android.content.Intent
import androidx.annotation.DrawableRes
/**
@@ -45,4 +46,7 @@ data class KeyguardQuickAffordancePickerRepresentation(
* user to a destination where they can re-enable it.
*/
val actionComponentName: String? = null,
/** Optional [Intent] to use to start an activity to configure this affordance. */
val configureIntent: Intent? = null,
)

View File

@@ -38,6 +38,7 @@ import com.android.systemui.util.mockito.eq
import com.android.systemui.util.mockito.mock
import com.android.systemui.util.mockito.whenever
import com.android.systemui.util.settings.FakeSettings
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.TestDispatcher
@@ -83,169 +84,205 @@ class DoNotDisturbQuickAffordanceConfigTest : SysuiTestCase() {
settings = FakeSettings()
underTest = DoNotDisturbQuickAffordanceConfig(
context,
zenModeController,
settings,
userTracker,
testDispatcher,
conditionUri,
enableZenModeDialog,
)
underTest =
DoNotDisturbQuickAffordanceConfig(
context,
zenModeController,
settings,
userTracker,
testDispatcher,
conditionUri,
enableZenModeDialog,
)
}
@Test
fun `dnd not available - picker state hidden`() = testScope.runTest {
//given
whenever(zenModeController.isZenAvailable).thenReturn(false)
fun `dnd not available - picker state hidden`() =
testScope.runTest {
// given
whenever(zenModeController.isZenAvailable).thenReturn(false)
//when
val result = underTest.getPickerScreenState()
// when
val result = underTest.getPickerScreenState()
//then
assertEquals(KeyguardQuickAffordanceConfig.PickerScreenState.UnavailableOnDevice, result)
}
// then
assertEquals(
KeyguardQuickAffordanceConfig.PickerScreenState.UnavailableOnDevice,
result
)
}
@Test
fun `dnd available - picker state visible`() = testScope.runTest {
//given
whenever(zenModeController.isZenAvailable).thenReturn(true)
fun `dnd available - picker state visible`() =
testScope.runTest {
// given
whenever(zenModeController.isZenAvailable).thenReturn(true)
//when
val result = underTest.getPickerScreenState()
// when
val result = underTest.getPickerScreenState()
//then
assertEquals(KeyguardQuickAffordanceConfig.PickerScreenState.Default, result)
}
// then
assertThat(result)
.isInstanceOf(KeyguardQuickAffordanceConfig.PickerScreenState.Default::class.java)
val defaultPickerState =
result as KeyguardQuickAffordanceConfig.PickerScreenState.Default
assertThat(defaultPickerState.configureIntent).isNotNull()
assertThat(defaultPickerState.configureIntent?.action)
.isEqualTo(Settings.ACTION_ZEN_MODE_SETTINGS)
}
@Test
fun `onTriggered - dnd mode is not ZEN_MODE_OFF - set to ZEN_MODE_OFF`() = testScope.runTest {
//given
whenever(zenModeController.isZenAvailable).thenReturn(true)
whenever(zenModeController.zen).thenReturn(-1)
settings.putInt(Settings.Secure.ZEN_DURATION, -2)
collectLastValue(underTest.lockScreenState)
runCurrent()
fun `onTriggered - dnd mode is not ZEN_MODE_OFF - set to ZEN_MODE_OFF`() =
testScope.runTest {
// given
whenever(zenModeController.isZenAvailable).thenReturn(true)
whenever(zenModeController.zen).thenReturn(-1)
settings.putInt(Settings.Secure.ZEN_DURATION, -2)
collectLastValue(underTest.lockScreenState)
runCurrent()
//when
val result = underTest.onTriggered(null)
verify(zenModeController).setZen(spyZenMode.capture(), spyConditionId.capture(), eq(DoNotDisturbQuickAffordanceConfig.TAG))
// when
val result = underTest.onTriggered(null)
verify(zenModeController)
.setZen(
spyZenMode.capture(),
spyConditionId.capture(),
eq(DoNotDisturbQuickAffordanceConfig.TAG)
)
//then
assertEquals(KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled, result)
assertEquals(ZEN_MODE_OFF, spyZenMode.value)
assertNull(spyConditionId.value)
}
// then
assertEquals(KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled, result)
assertEquals(ZEN_MODE_OFF, spyZenMode.value)
assertNull(spyConditionId.value)
}
@Test
fun `onTriggered - dnd mode is ZEN_MODE_OFF - setting is FOREVER - set zen with no condition`() = testScope.runTest {
//given
whenever(zenModeController.isZenAvailable).thenReturn(true)
whenever(zenModeController.zen).thenReturn(ZEN_MODE_OFF)
settings.putInt(Settings.Secure.ZEN_DURATION, ZEN_DURATION_FOREVER)
collectLastValue(underTest.lockScreenState)
runCurrent()
fun `onTriggered - dnd mode is ZEN_MODE_OFF - setting FOREVER - set zen without condition`() =
testScope.runTest {
// given
whenever(zenModeController.isZenAvailable).thenReturn(true)
whenever(zenModeController.zen).thenReturn(ZEN_MODE_OFF)
settings.putInt(Settings.Secure.ZEN_DURATION, ZEN_DURATION_FOREVER)
collectLastValue(underTest.lockScreenState)
runCurrent()
//when
val result = underTest.onTriggered(null)
verify(zenModeController).setZen(spyZenMode.capture(), spyConditionId.capture(), eq(DoNotDisturbQuickAffordanceConfig.TAG))
// when
val result = underTest.onTriggered(null)
verify(zenModeController)
.setZen(
spyZenMode.capture(),
spyConditionId.capture(),
eq(DoNotDisturbQuickAffordanceConfig.TAG)
)
//then
assertEquals(KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled, result)
assertEquals(ZEN_MODE_IMPORTANT_INTERRUPTIONS, spyZenMode.value)
assertNull(spyConditionId.value)
}
// then
assertEquals(KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled, result)
assertEquals(ZEN_MODE_IMPORTANT_INTERRUPTIONS, spyZenMode.value)
assertNull(spyConditionId.value)
}
@Test
fun `onTriggered - dnd mode is ZEN_MODE_OFF - setting is not FOREVER or PROMPT - set zen with condition`() = testScope.runTest {
//given
whenever(zenModeController.isZenAvailable).thenReturn(true)
whenever(zenModeController.zen).thenReturn(ZEN_MODE_OFF)
settings.putInt(Settings.Secure.ZEN_DURATION, -900)
collectLastValue(underTest.lockScreenState)
runCurrent()
fun `onTriggered - dnd ZEN_MODE_OFF - setting not FOREVER or PROMPT - zen with condition`() =
testScope.runTest {
// given
whenever(zenModeController.isZenAvailable).thenReturn(true)
whenever(zenModeController.zen).thenReturn(ZEN_MODE_OFF)
settings.putInt(Settings.Secure.ZEN_DURATION, -900)
collectLastValue(underTest.lockScreenState)
runCurrent()
//when
val result = underTest.onTriggered(null)
verify(zenModeController).setZen(spyZenMode.capture(), spyConditionId.capture(), eq(DoNotDisturbQuickAffordanceConfig.TAG))
// when
val result = underTest.onTriggered(null)
verify(zenModeController)
.setZen(
spyZenMode.capture(),
spyConditionId.capture(),
eq(DoNotDisturbQuickAffordanceConfig.TAG)
)
//then
assertEquals(KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled, result)
assertEquals(ZEN_MODE_IMPORTANT_INTERRUPTIONS, spyZenMode.value)
assertEquals(conditionUri, spyConditionId.value)
}
// then
assertEquals(KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled, result)
assertEquals(ZEN_MODE_IMPORTANT_INTERRUPTIONS, spyZenMode.value)
assertEquals(conditionUri, spyConditionId.value)
}
@Test
fun `onTriggered - dnd mode is ZEN_MODE_OFF - setting is PROMPT - show dialog`() = testScope.runTest {
//given
val expandable: Expandable = mock()
whenever(zenModeController.isZenAvailable).thenReturn(true)
whenever(zenModeController.zen).thenReturn(ZEN_MODE_OFF)
settings.putInt(Settings.Secure.ZEN_DURATION, ZEN_DURATION_PROMPT)
whenever(enableZenModeDialog.createDialog()).thenReturn(mock())
collectLastValue(underTest.lockScreenState)
runCurrent()
fun `onTriggered - dnd mode is ZEN_MODE_OFF - setting is PROMPT - show dialog`() =
testScope.runTest {
// given
val expandable: Expandable = mock()
whenever(zenModeController.isZenAvailable).thenReturn(true)
whenever(zenModeController.zen).thenReturn(ZEN_MODE_OFF)
settings.putInt(Settings.Secure.ZEN_DURATION, ZEN_DURATION_PROMPT)
whenever(enableZenModeDialog.createDialog()).thenReturn(mock())
collectLastValue(underTest.lockScreenState)
runCurrent()
//when
val result = underTest.onTriggered(expandable)
// when
val result = underTest.onTriggered(expandable)
//then
assertTrue(result is KeyguardQuickAffordanceConfig.OnTriggeredResult.ShowDialog)
assertEquals(expandable, (result as KeyguardQuickAffordanceConfig.OnTriggeredResult.ShowDialog).expandable)
}
// then
assertTrue(result is KeyguardQuickAffordanceConfig.OnTriggeredResult.ShowDialog)
assertEquals(
expandable,
(result as KeyguardQuickAffordanceConfig.OnTriggeredResult.ShowDialog).expandable
)
}
@Test
fun `lockScreenState - dndAvailable starts as true - changes to false - State moves to Hidden`() = testScope.runTest {
//given
whenever(zenModeController.isZenAvailable).thenReturn(true)
val callbackCaptor: ArgumentCaptor<ZenModeController.Callback> = argumentCaptor()
val valueSnapshot = collectLastValue(underTest.lockScreenState)
val secondLastValue = valueSnapshot()
verify(zenModeController).addCallback(callbackCaptor.capture())
fun `lockScreenState - dndAvailable starts as true - change to false - State is Hidden`() =
testScope.runTest {
// given
whenever(zenModeController.isZenAvailable).thenReturn(true)
val callbackCaptor: ArgumentCaptor<ZenModeController.Callback> = argumentCaptor()
val valueSnapshot = collectLastValue(underTest.lockScreenState)
val secondLastValue = valueSnapshot()
verify(zenModeController).addCallback(callbackCaptor.capture())
//when
callbackCaptor.value.onZenAvailableChanged(false)
val lastValue = valueSnapshot()
// when
callbackCaptor.value.onZenAvailableChanged(false)
val lastValue = valueSnapshot()
//then
assertTrue(secondLastValue is KeyguardQuickAffordanceConfig.LockScreenState.Visible)
assertTrue(lastValue is KeyguardQuickAffordanceConfig.LockScreenState.Hidden)
}
// then
assertTrue(secondLastValue is KeyguardQuickAffordanceConfig.LockScreenState.Visible)
assertTrue(lastValue is KeyguardQuickAffordanceConfig.LockScreenState.Hidden)
}
@Test
fun `lockScreenState - dndMode starts as ZEN_MODE_OFF - changes to not OFF - State moves to Visible`() = testScope.runTest {
//given
whenever(zenModeController.isZenAvailable).thenReturn(true)
whenever(zenModeController.zen).thenReturn(ZEN_MODE_OFF)
val valueSnapshot = collectLastValue(underTest.lockScreenState)
val secondLastValue = valueSnapshot()
val callbackCaptor: ArgumentCaptor<ZenModeController.Callback> = argumentCaptor()
verify(zenModeController).addCallback(callbackCaptor.capture())
fun `lockScreenState - dndMode starts as ZEN_MODE_OFF - change to not OFF - State Visible`() =
testScope.runTest {
// given
whenever(zenModeController.isZenAvailable).thenReturn(true)
whenever(zenModeController.zen).thenReturn(ZEN_MODE_OFF)
val valueSnapshot = collectLastValue(underTest.lockScreenState)
val secondLastValue = valueSnapshot()
val callbackCaptor: ArgumentCaptor<ZenModeController.Callback> = argumentCaptor()
verify(zenModeController).addCallback(callbackCaptor.capture())
//when
callbackCaptor.value.onZenChanged(ZEN_MODE_IMPORTANT_INTERRUPTIONS)
val lastValue = valueSnapshot()
// when
callbackCaptor.value.onZenChanged(ZEN_MODE_IMPORTANT_INTERRUPTIONS)
val lastValue = valueSnapshot()
//then
assertEquals(
KeyguardQuickAffordanceConfig.LockScreenState.Visible(
Icon.Resource(
R.drawable.qs_dnd_icon_off,
ContentDescription.Resource(R.string.dnd_is_off)
// then
assertEquals(
KeyguardQuickAffordanceConfig.LockScreenState.Visible(
Icon.Resource(
R.drawable.qs_dnd_icon_off,
ContentDescription.Resource(R.string.dnd_is_off)
),
ActivationState.Inactive
),
ActivationState.Inactive
),
secondLastValue,
)
assertEquals(
KeyguardQuickAffordanceConfig.LockScreenState.Visible(
Icon.Resource(
R.drawable.qs_dnd_icon_on,
ContentDescription.Resource(R.string.dnd_is_on)
secondLastValue,
)
assertEquals(
KeyguardQuickAffordanceConfig.LockScreenState.Visible(
Icon.Resource(
R.drawable.qs_dnd_icon_on,
ContentDescription.Resource(R.string.dnd_is_on)
),
ActivationState.Active
),
ActivationState.Active
),
lastValue,
)
}
}
lastValue,
)
}
}

View File

@@ -141,7 +141,7 @@ class QrCodeScannerKeyguardQuickAffordanceConfigTest : SysuiTestCase() {
whenever(controller.isAbleToOpenCameraApp).thenReturn(true)
assertThat(underTest.getPickerScreenState())
.isEqualTo(KeyguardQuickAffordanceConfig.PickerScreenState.Default)
.isEqualTo(KeyguardQuickAffordanceConfig.PickerScreenState.Default())
}
@Test

View File

@@ -159,7 +159,7 @@ class QuickAccessWalletKeyguardQuickAffordanceConfigTest : SysuiTestCase() {
setUpState()
assertThat(underTest.getPickerScreenState())
.isEqualTo(KeyguardQuickAffordanceConfig.PickerScreenState.Default)
.isEqualTo(KeyguardQuickAffordanceConfig.PickerScreenState.Default())
}
@Test