Merge "Long-press to configure quick affordances (1/2)." into tm-qpr-dev am: 7eb00fa994
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20839423 Change-Id: I574b1279eb56c18a50142396431c5d382e4d85a1 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -20,12 +20,15 @@ package com.android.systemui.shared.customization.data.content
|
|||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.ContentValues
|
import android.content.ContentValues
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
import android.database.ContentObserver
|
import android.database.ContentObserver
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.util.Log
|
||||||
import androidx.annotation.DrawableRes
|
import androidx.annotation.DrawableRes
|
||||||
import com.android.systemui.shared.customization.data.content.CustomizationProviderContract as Contract
|
import com.android.systemui.shared.customization.data.content.CustomizationProviderContract as Contract
|
||||||
|
import java.net.URISyntaxException
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.channels.awaitClose
|
import kotlinx.coroutines.channels.awaitClose
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
@@ -169,6 +172,8 @@ interface CustomizationProviderClient {
|
|||||||
* If `null`, the button should not be shown.
|
* If `null`, the button should not be shown.
|
||||||
*/
|
*/
|
||||||
val enablementActionComponentName: String? = null,
|
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. */
|
/** Models a selection of a quick affordance on a slot. */
|
||||||
@@ -337,6 +342,11 @@ class CustomizationProviderClientImpl(
|
|||||||
Contract.LockScreenQuickAffordances.AffordanceTable.Columns
|
Contract.LockScreenQuickAffordances.AffordanceTable.Columns
|
||||||
.ENABLEMENT_COMPONENT_NAME
|
.ENABLEMENT_COMPONENT_NAME
|
||||||
)
|
)
|
||||||
|
val configureIntentColumnIndex =
|
||||||
|
cursor.getColumnIndex(
|
||||||
|
Contract.LockScreenQuickAffordances.AffordanceTable.Columns
|
||||||
|
.CONFIGURE_INTENT
|
||||||
|
)
|
||||||
if (
|
if (
|
||||||
idColumnIndex == -1 ||
|
idColumnIndex == -1 ||
|
||||||
nameColumnIndex == -1 ||
|
nameColumnIndex == -1 ||
|
||||||
@@ -344,15 +354,17 @@ class CustomizationProviderClientImpl(
|
|||||||
isEnabledColumnIndex == -1 ||
|
isEnabledColumnIndex == -1 ||
|
||||||
enablementInstructionsColumnIndex == -1 ||
|
enablementInstructionsColumnIndex == -1 ||
|
||||||
enablementActionTextColumnIndex == -1 ||
|
enablementActionTextColumnIndex == -1 ||
|
||||||
enablementComponentNameColumnIndex == -1
|
enablementComponentNameColumnIndex == -1 ||
|
||||||
|
configureIntentColumnIndex == -1
|
||||||
) {
|
) {
|
||||||
return@buildList
|
return@buildList
|
||||||
}
|
}
|
||||||
|
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
|
val affordanceId = cursor.getString(idColumnIndex)
|
||||||
add(
|
add(
|
||||||
CustomizationProviderClient.Affordance(
|
CustomizationProviderClient.Affordance(
|
||||||
id = cursor.getString(idColumnIndex),
|
id = affordanceId,
|
||||||
name = cursor.getString(nameColumnIndex),
|
name = cursor.getString(nameColumnIndex),
|
||||||
iconResourceId = cursor.getInt(iconColumnIndex),
|
iconResourceId = cursor.getInt(iconColumnIndex),
|
||||||
isEnabled = cursor.getInt(isEnabledColumnIndex) == 1,
|
isEnabled = cursor.getInt(isEnabledColumnIndex) == 1,
|
||||||
@@ -367,6 +379,10 @@ class CustomizationProviderClientImpl(
|
|||||||
cursor.getString(enablementActionTextColumnIndex),
|
cursor.getString(enablementActionTextColumnIndex),
|
||||||
enablementActionComponentName =
|
enablementActionComponentName =
|
||||||
cursor.getString(enablementComponentNameColumnIndex),
|
cursor.getString(enablementComponentNameColumnIndex),
|
||||||
|
configureIntent =
|
||||||
|
cursor
|
||||||
|
.getString(configureIntentColumnIndex)
|
||||||
|
?.toIntent(affordanceId = affordanceId),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -504,7 +520,19 @@ class CustomizationProviderClientImpl(
|
|||||||
.onStart { emit(Unit) }
|
.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 {
|
companion object {
|
||||||
|
private const val TAG = "CustomizationProviderClient"
|
||||||
private const val SYSTEM_UI_PACKAGE_NAME = "com.android.systemui"
|
private const val SYSTEM_UI_PACKAGE_NAME = "com.android.systemui"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,6 +113,11 @@ object CustomizationProviderContract {
|
|||||||
* opens a destination where the user can re-enable the disabled affordance.
|
* opens a destination where the user can re-enable the disabled affordance.
|
||||||
*/
|
*/
|
||||||
const val ENABLEMENT_COMPONENT_NAME = "enablement_action_intent"
|
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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -282,6 +282,7 @@ class CustomizationProvider :
|
|||||||
.ENABLEMENT_ACTION_TEXT,
|
.ENABLEMENT_ACTION_TEXT,
|
||||||
Contract.LockScreenQuickAffordances.AffordanceTable.Columns
|
Contract.LockScreenQuickAffordances.AffordanceTable.Columns
|
||||||
.ENABLEMENT_COMPONENT_NAME,
|
.ENABLEMENT_COMPONENT_NAME,
|
||||||
|
Contract.LockScreenQuickAffordances.AffordanceTable.Columns.CONFIGURE_INTENT,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.apply {
|
.apply {
|
||||||
@@ -298,6 +299,7 @@ class CustomizationProvider :
|
|||||||
),
|
),
|
||||||
representation.actionText,
|
representation.actionText,
|
||||||
representation.actionComponentName,
|
representation.actionComponentName,
|
||||||
|
representation.configureIntent?.toUri(0),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package com.android.systemui.keyguard.data.quickaffordance
|
package com.android.systemui.keyguard.data.quickaffordance
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.provider.Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS
|
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.statusbar.policy.ZenModeController
|
||||||
import com.android.systemui.util.settings.SecureSettings
|
import com.android.systemui.util.settings.SecureSettings
|
||||||
import com.android.systemui.util.settings.SettingsProxyExt.observerFlow
|
import com.android.systemui.util.settings.SettingsProxyExt.observerFlow
|
||||||
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.channels.awaitClose
|
import kotlinx.coroutines.channels.awaitClose
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
@@ -48,10 +50,10 @@ import kotlinx.coroutines.flow.flowOn
|
|||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import kotlinx.coroutines.flow.onStart
|
import kotlinx.coroutines.flow.onStart
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
@SysUISingleton
|
@SysUISingleton
|
||||||
class DoNotDisturbQuickAffordanceConfig constructor(
|
class DoNotDisturbQuickAffordanceConfig
|
||||||
|
constructor(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val controller: ZenModeController,
|
private val controller: ZenModeController,
|
||||||
private val secureSettings: SecureSettings,
|
private val secureSettings: SecureSettings,
|
||||||
@@ -76,15 +78,18 @@ class DoNotDisturbQuickAffordanceConfig constructor(
|
|||||||
|
|
||||||
private val conditionUri: Uri
|
private val conditionUri: Uri
|
||||||
get() =
|
get() =
|
||||||
testConditionId ?: ZenModeConfig.toTimeCondition(
|
testConditionId
|
||||||
|
?: ZenModeConfig.toTimeCondition(
|
||||||
context,
|
context,
|
||||||
settingsValue,
|
settingsValue,
|
||||||
userTracker.userId,
|
userTracker.userId,
|
||||||
true, /* shortVersion */
|
true, /* shortVersion */
|
||||||
).id
|
)
|
||||||
|
.id
|
||||||
|
|
||||||
private val dialog: EnableZenModeDialog by lazy {
|
private val dialog: EnableZenModeDialog by lazy {
|
||||||
testDialog ?: EnableZenModeDialog(
|
testDialog
|
||||||
|
?: EnableZenModeDialog(
|
||||||
context,
|
context,
|
||||||
R.style.Theme_SystemUI_Dialog,
|
R.style.Theme_SystemUI_Dialog,
|
||||||
true, /* cancelIsNeutral */
|
true, /* cancelIsNeutral */
|
||||||
@@ -98,9 +103,11 @@ class DoNotDisturbQuickAffordanceConfig constructor(
|
|||||||
|
|
||||||
override val pickerIconResourceId: Int = R.drawable.ic_do_not_disturb
|
override val pickerIconResourceId: Int = R.drawable.ic_do_not_disturb
|
||||||
|
|
||||||
override val lockScreenState: Flow<KeyguardQuickAffordanceConfig.LockScreenState> = combine(
|
override val lockScreenState: Flow<KeyguardQuickAffordanceConfig.LockScreenState> =
|
||||||
|
combine(
|
||||||
conflatedCallbackFlow {
|
conflatedCallbackFlow {
|
||||||
val callback = object: ZenModeController.Callback {
|
val callback =
|
||||||
|
object : ZenModeController.Callback {
|
||||||
override fun onZenChanged(zen: Int) {
|
override fun onZenChanged(zen: Int) {
|
||||||
dndMode = zen
|
dndMode = zen
|
||||||
trySendWithFailureLogging(updateState(), TAG)
|
trySendWithFailureLogging(updateState(), TAG)
|
||||||
@@ -131,17 +138,19 @@ class DoNotDisturbQuickAffordanceConfig constructor(
|
|||||||
|
|
||||||
override suspend fun getPickerScreenState(): KeyguardQuickAffordanceConfig.PickerScreenState {
|
override suspend fun getPickerScreenState(): KeyguardQuickAffordanceConfig.PickerScreenState {
|
||||||
return if (controller.isZenAvailable) {
|
return if (controller.isZenAvailable) {
|
||||||
KeyguardQuickAffordanceConfig.PickerScreenState.Default
|
KeyguardQuickAffordanceConfig.PickerScreenState.Default(
|
||||||
|
configureIntent = Intent(Settings.ACTION_ZEN_MODE_SETTINGS)
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
KeyguardQuickAffordanceConfig.PickerScreenState.UnavailableOnDevice
|
KeyguardQuickAffordanceConfig.PickerScreenState.UnavailableOnDevice
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTriggered(expandable: Expandable?):
|
override fun onTriggered(
|
||||||
KeyguardQuickAffordanceConfig.OnTriggeredResult {
|
expandable: Expandable?
|
||||||
|
): KeyguardQuickAffordanceConfig.OnTriggeredResult {
|
||||||
return when {
|
return when {
|
||||||
!isAvailable ->
|
!isAvailable -> KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled
|
||||||
KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled
|
|
||||||
dndMode != ZEN_MODE_OFF -> {
|
dndMode != ZEN_MODE_OFF -> {
|
||||||
controller.setZen(ZEN_MODE_OFF, null, TAG)
|
controller.setZen(ZEN_MODE_OFF, null, TAG)
|
||||||
KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled
|
KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ constructor(
|
|||||||
|
|
||||||
override suspend fun getPickerScreenState(): KeyguardQuickAffordanceConfig.PickerScreenState =
|
override suspend fun getPickerScreenState(): KeyguardQuickAffordanceConfig.PickerScreenState =
|
||||||
if (flashlightController.isAvailable) {
|
if (flashlightController.isAvailable) {
|
||||||
KeyguardQuickAffordanceConfig.PickerScreenState.Default
|
KeyguardQuickAffordanceConfig.PickerScreenState.Default()
|
||||||
} else {
|
} else {
|
||||||
KeyguardQuickAffordanceConfig.PickerScreenState.UnavailableOnDevice
|
KeyguardQuickAffordanceConfig.PickerScreenState.UnavailableOnDevice
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return KeyguardQuickAffordanceConfig.PickerScreenState.Default
|
return KeyguardQuickAffordanceConfig.PickerScreenState.Default()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTriggered(
|
override fun onTriggered(
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ interface KeyguardQuickAffordanceConfig {
|
|||||||
* Returns the [PickerScreenState] representing the affordance in the settings or selector
|
* Returns the [PickerScreenState] representing the affordance in the settings or selector
|
||||||
* experience.
|
* experience.
|
||||||
*/
|
*/
|
||||||
suspend fun getPickerScreenState(): PickerScreenState = PickerScreenState.Default
|
suspend fun getPickerScreenState(): PickerScreenState = PickerScreenState.Default()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notifies that the affordance was clicked by the user.
|
* Notifies that the affordance was clicked by the user.
|
||||||
@@ -63,7 +63,10 @@ interface KeyguardQuickAffordanceConfig {
|
|||||||
sealed class PickerScreenState {
|
sealed class PickerScreenState {
|
||||||
|
|
||||||
/** The picker shows the item for selecting this affordance as it normally would. */
|
/** 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
|
* The picker does not show an item for selecting this affordance as it is not supported on
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ constructor(
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
else -> KeyguardQuickAffordanceConfig.PickerScreenState.Default
|
else -> KeyguardQuickAffordanceConfig.PickerScreenState.Default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ constructor(
|
|||||||
actionComponentName = componentName,
|
actionComponentName = componentName,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
else -> KeyguardQuickAffordanceConfig.PickerScreenState.Default
|
else -> KeyguardQuickAffordanceConfig.PickerScreenState.Default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -187,6 +187,8 @@ constructor(
|
|||||||
pickerState is KeyguardQuickAffordanceConfig.PickerScreenState.UnavailableOnDevice
|
pickerState is KeyguardQuickAffordanceConfig.PickerScreenState.UnavailableOnDevice
|
||||||
}
|
}
|
||||||
.map { (config, pickerState) ->
|
.map { (config, pickerState) ->
|
||||||
|
val defaultPickerState =
|
||||||
|
pickerState as? KeyguardQuickAffordanceConfig.PickerScreenState.Default
|
||||||
val disabledPickerState =
|
val disabledPickerState =
|
||||||
pickerState as? KeyguardQuickAffordanceConfig.PickerScreenState.Disabled
|
pickerState as? KeyguardQuickAffordanceConfig.PickerScreenState.Disabled
|
||||||
KeyguardQuickAffordancePickerRepresentation(
|
KeyguardQuickAffordancePickerRepresentation(
|
||||||
@@ -198,6 +200,7 @@ constructor(
|
|||||||
instructions = disabledPickerState?.instructions,
|
instructions = disabledPickerState?.instructions,
|
||||||
actionText = disabledPickerState?.actionText,
|
actionText = disabledPickerState?.actionText,
|
||||||
actionComponentName = disabledPickerState?.actionComponentName,
|
actionComponentName = disabledPickerState?.actionComponentName,
|
||||||
|
configureIntent = defaultPickerState?.configureIntent,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package com.android.systemui.keyguard.shared.model
|
package com.android.systemui.keyguard.shared.model
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
import androidx.annotation.DrawableRes
|
import androidx.annotation.DrawableRes
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,4 +46,7 @@ data class KeyguardQuickAffordancePickerRepresentation(
|
|||||||
* user to a destination where they can re-enable it.
|
* user to a destination where they can re-enable it.
|
||||||
*/
|
*/
|
||||||
val actionComponentName: String? = null,
|
val actionComponentName: String? = null,
|
||||||
|
|
||||||
|
/** Optional [Intent] to use to start an activity to configure this affordance. */
|
||||||
|
val configureIntent: Intent? = null,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import com.android.systemui.util.mockito.eq
|
|||||||
import com.android.systemui.util.mockito.mock
|
import com.android.systemui.util.mockito.mock
|
||||||
import com.android.systemui.util.mockito.whenever
|
import com.android.systemui.util.mockito.whenever
|
||||||
import com.android.systemui.util.settings.FakeSettings
|
import com.android.systemui.util.settings.FakeSettings
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.test.StandardTestDispatcher
|
import kotlinx.coroutines.test.StandardTestDispatcher
|
||||||
import kotlinx.coroutines.test.TestDispatcher
|
import kotlinx.coroutines.test.TestDispatcher
|
||||||
@@ -83,7 +84,8 @@ class DoNotDisturbQuickAffordanceConfigTest : SysuiTestCase() {
|
|||||||
|
|
||||||
settings = FakeSettings()
|
settings = FakeSettings()
|
||||||
|
|
||||||
underTest = DoNotDisturbQuickAffordanceConfig(
|
underTest =
|
||||||
|
DoNotDisturbQuickAffordanceConfig(
|
||||||
context,
|
context,
|
||||||
zenModeController,
|
zenModeController,
|
||||||
settings,
|
settings,
|
||||||
@@ -95,7 +97,8 @@ class DoNotDisturbQuickAffordanceConfigTest : SysuiTestCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `dnd not available - picker state hidden`() = testScope.runTest {
|
fun `dnd not available - picker state hidden`() =
|
||||||
|
testScope.runTest {
|
||||||
// given
|
// given
|
||||||
whenever(zenModeController.isZenAvailable).thenReturn(false)
|
whenever(zenModeController.isZenAvailable).thenReturn(false)
|
||||||
|
|
||||||
@@ -103,11 +106,15 @@ class DoNotDisturbQuickAffordanceConfigTest : SysuiTestCase() {
|
|||||||
val result = underTest.getPickerScreenState()
|
val result = underTest.getPickerScreenState()
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(KeyguardQuickAffordanceConfig.PickerScreenState.UnavailableOnDevice, result)
|
assertEquals(
|
||||||
|
KeyguardQuickAffordanceConfig.PickerScreenState.UnavailableOnDevice,
|
||||||
|
result
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `dnd available - picker state visible`() = testScope.runTest {
|
fun `dnd available - picker state visible`() =
|
||||||
|
testScope.runTest {
|
||||||
// given
|
// given
|
||||||
whenever(zenModeController.isZenAvailable).thenReturn(true)
|
whenever(zenModeController.isZenAvailable).thenReturn(true)
|
||||||
|
|
||||||
@@ -115,11 +122,18 @@ class DoNotDisturbQuickAffordanceConfigTest : SysuiTestCase() {
|
|||||||
val result = underTest.getPickerScreenState()
|
val result = underTest.getPickerScreenState()
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(KeyguardQuickAffordanceConfig.PickerScreenState.Default, result)
|
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
|
@Test
|
||||||
fun `onTriggered - dnd mode is not ZEN_MODE_OFF - set to ZEN_MODE_OFF`() = testScope.runTest {
|
fun `onTriggered - dnd mode is not ZEN_MODE_OFF - set to ZEN_MODE_OFF`() =
|
||||||
|
testScope.runTest {
|
||||||
// given
|
// given
|
||||||
whenever(zenModeController.isZenAvailable).thenReturn(true)
|
whenever(zenModeController.isZenAvailable).thenReturn(true)
|
||||||
whenever(zenModeController.zen).thenReturn(-1)
|
whenever(zenModeController.zen).thenReturn(-1)
|
||||||
@@ -129,7 +143,12 @@ class DoNotDisturbQuickAffordanceConfigTest : SysuiTestCase() {
|
|||||||
|
|
||||||
// when
|
// when
|
||||||
val result = underTest.onTriggered(null)
|
val result = underTest.onTriggered(null)
|
||||||
verify(zenModeController).setZen(spyZenMode.capture(), spyConditionId.capture(), eq(DoNotDisturbQuickAffordanceConfig.TAG))
|
verify(zenModeController)
|
||||||
|
.setZen(
|
||||||
|
spyZenMode.capture(),
|
||||||
|
spyConditionId.capture(),
|
||||||
|
eq(DoNotDisturbQuickAffordanceConfig.TAG)
|
||||||
|
)
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled, result)
|
assertEquals(KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled, result)
|
||||||
@@ -138,7 +157,8 @@ class DoNotDisturbQuickAffordanceConfigTest : SysuiTestCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `onTriggered - dnd mode is ZEN_MODE_OFF - setting is FOREVER - set zen with no condition`() = testScope.runTest {
|
fun `onTriggered - dnd mode is ZEN_MODE_OFF - setting FOREVER - set zen without condition`() =
|
||||||
|
testScope.runTest {
|
||||||
// given
|
// given
|
||||||
whenever(zenModeController.isZenAvailable).thenReturn(true)
|
whenever(zenModeController.isZenAvailable).thenReturn(true)
|
||||||
whenever(zenModeController.zen).thenReturn(ZEN_MODE_OFF)
|
whenever(zenModeController.zen).thenReturn(ZEN_MODE_OFF)
|
||||||
@@ -148,7 +168,12 @@ class DoNotDisturbQuickAffordanceConfigTest : SysuiTestCase() {
|
|||||||
|
|
||||||
// when
|
// when
|
||||||
val result = underTest.onTriggered(null)
|
val result = underTest.onTriggered(null)
|
||||||
verify(zenModeController).setZen(spyZenMode.capture(), spyConditionId.capture(), eq(DoNotDisturbQuickAffordanceConfig.TAG))
|
verify(zenModeController)
|
||||||
|
.setZen(
|
||||||
|
spyZenMode.capture(),
|
||||||
|
spyConditionId.capture(),
|
||||||
|
eq(DoNotDisturbQuickAffordanceConfig.TAG)
|
||||||
|
)
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled, result)
|
assertEquals(KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled, result)
|
||||||
@@ -157,7 +182,8 @@ class DoNotDisturbQuickAffordanceConfigTest : SysuiTestCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `onTriggered - dnd mode is ZEN_MODE_OFF - setting is not FOREVER or PROMPT - set zen with condition`() = testScope.runTest {
|
fun `onTriggered - dnd ZEN_MODE_OFF - setting not FOREVER or PROMPT - zen with condition`() =
|
||||||
|
testScope.runTest {
|
||||||
// given
|
// given
|
||||||
whenever(zenModeController.isZenAvailable).thenReturn(true)
|
whenever(zenModeController.isZenAvailable).thenReturn(true)
|
||||||
whenever(zenModeController.zen).thenReturn(ZEN_MODE_OFF)
|
whenever(zenModeController.zen).thenReturn(ZEN_MODE_OFF)
|
||||||
@@ -167,7 +193,12 @@ class DoNotDisturbQuickAffordanceConfigTest : SysuiTestCase() {
|
|||||||
|
|
||||||
// when
|
// when
|
||||||
val result = underTest.onTriggered(null)
|
val result = underTest.onTriggered(null)
|
||||||
verify(zenModeController).setZen(spyZenMode.capture(), spyConditionId.capture(), eq(DoNotDisturbQuickAffordanceConfig.TAG))
|
verify(zenModeController)
|
||||||
|
.setZen(
|
||||||
|
spyZenMode.capture(),
|
||||||
|
spyConditionId.capture(),
|
||||||
|
eq(DoNotDisturbQuickAffordanceConfig.TAG)
|
||||||
|
)
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled, result)
|
assertEquals(KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled, result)
|
||||||
@@ -176,7 +207,8 @@ class DoNotDisturbQuickAffordanceConfigTest : SysuiTestCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `onTriggered - dnd mode is ZEN_MODE_OFF - setting is PROMPT - show dialog`() = testScope.runTest {
|
fun `onTriggered - dnd mode is ZEN_MODE_OFF - setting is PROMPT - show dialog`() =
|
||||||
|
testScope.runTest {
|
||||||
// given
|
// given
|
||||||
val expandable: Expandable = mock()
|
val expandable: Expandable = mock()
|
||||||
whenever(zenModeController.isZenAvailable).thenReturn(true)
|
whenever(zenModeController.isZenAvailable).thenReturn(true)
|
||||||
@@ -191,11 +223,15 @@ class DoNotDisturbQuickAffordanceConfigTest : SysuiTestCase() {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
assertTrue(result is KeyguardQuickAffordanceConfig.OnTriggeredResult.ShowDialog)
|
assertTrue(result is KeyguardQuickAffordanceConfig.OnTriggeredResult.ShowDialog)
|
||||||
assertEquals(expandable, (result as KeyguardQuickAffordanceConfig.OnTriggeredResult.ShowDialog).expandable)
|
assertEquals(
|
||||||
|
expandable,
|
||||||
|
(result as KeyguardQuickAffordanceConfig.OnTriggeredResult.ShowDialog).expandable
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `lockScreenState - dndAvailable starts as true - changes to false - State moves to Hidden`() = testScope.runTest {
|
fun `lockScreenState - dndAvailable starts as true - change to false - State is Hidden`() =
|
||||||
|
testScope.runTest {
|
||||||
// given
|
// given
|
||||||
whenever(zenModeController.isZenAvailable).thenReturn(true)
|
whenever(zenModeController.isZenAvailable).thenReturn(true)
|
||||||
val callbackCaptor: ArgumentCaptor<ZenModeController.Callback> = argumentCaptor()
|
val callbackCaptor: ArgumentCaptor<ZenModeController.Callback> = argumentCaptor()
|
||||||
@@ -213,7 +249,8 @@ class DoNotDisturbQuickAffordanceConfigTest : SysuiTestCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `lockScreenState - dndMode starts as ZEN_MODE_OFF - changes to not OFF - State moves to Visible`() = testScope.runTest {
|
fun `lockScreenState - dndMode starts as ZEN_MODE_OFF - change to not OFF - State Visible`() =
|
||||||
|
testScope.runTest {
|
||||||
// given
|
// given
|
||||||
whenever(zenModeController.isZenAvailable).thenReturn(true)
|
whenever(zenModeController.isZenAvailable).thenReturn(true)
|
||||||
whenever(zenModeController.zen).thenReturn(ZEN_MODE_OFF)
|
whenever(zenModeController.zen).thenReturn(ZEN_MODE_OFF)
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ class QrCodeScannerKeyguardQuickAffordanceConfigTest : SysuiTestCase() {
|
|||||||
whenever(controller.isAbleToOpenCameraApp).thenReturn(true)
|
whenever(controller.isAbleToOpenCameraApp).thenReturn(true)
|
||||||
|
|
||||||
assertThat(underTest.getPickerScreenState())
|
assertThat(underTest.getPickerScreenState())
|
||||||
.isEqualTo(KeyguardQuickAffordanceConfig.PickerScreenState.Default)
|
.isEqualTo(KeyguardQuickAffordanceConfig.PickerScreenState.Default())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ class QuickAccessWalletKeyguardQuickAffordanceConfigTest : SysuiTestCase() {
|
|||||||
setUpState()
|
setUpState()
|
||||||
|
|
||||||
assertThat(underTest.getPickerScreenState())
|
assertThat(underTest.getPickerScreenState())
|
||||||
.isEqualTo(KeyguardQuickAffordanceConfig.PickerScreenState.Default)
|
.isEqualTo(KeyguardQuickAffordanceConfig.PickerScreenState.Default())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user