diff options
| author | 2023-01-13 04:20:47 +0000 | |
|---|---|---|
| committer | 2023-01-13 04:20:47 +0000 | |
| commit | 7eb00fa99487e2d09676d1cadab6fbd98d8c2f4a (patch) | |
| tree | 5dbcc1c548bc5998477d94749272870191b168f7 | |
| parent | e32bce64d964e75221fee52aa0c8a6bab77016f7 (diff) | |
| parent | c26282edc4779927336cca180550e84705ba168f (diff) | |
Merge "Long-press to configure quick affordances (1/2)." into tm-qpr-dev
14 files changed, 299 insertions, 208 deletions
diff --git a/packages/SystemUI/customization/src/com/android/systemui/shared/customization/data/content/CustomizationProviderClient.kt b/packages/SystemUI/customization/src/com/android/systemui/shared/customization/data/content/CustomizationProviderClient.kt index 5bb37071b075..cd9fb886a4e6 100644 --- a/packages/SystemUI/customization/src/com/android/systemui/shared/customization/data/content/CustomizationProviderClient.kt +++ b/packages/SystemUI/customization/src/com/android/systemui/shared/customization/data/content/CustomizationProviderClient.kt @@ -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" } } diff --git a/packages/SystemUI/customization/src/com/android/systemui/shared/customization/data/content/CustomizationProviderContract.kt b/packages/SystemUI/customization/src/com/android/systemui/shared/customization/data/content/CustomizationProviderContract.kt index 1e2e7d2595ac..7f1c78fc47ff 100644 --- a/packages/SystemUI/customization/src/com/android/systemui/shared/customization/data/content/CustomizationProviderContract.kt +++ b/packages/SystemUI/customization/src/com/android/systemui/shared/customization/data/content/CustomizationProviderContract.kt @@ -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" } } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/CustomizationProvider.kt b/packages/SystemUI/src/com/android/systemui/keyguard/CustomizationProvider.kt index eaf1081a374a..482138e6c277 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/CustomizationProvider.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/CustomizationProvider.kt @@ -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), ) ) } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/DoNotDisturbQuickAffordanceConfig.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/DoNotDisturbQuickAffordanceConfig.kt index 8efb36624831..ed1ff329004a 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/DoNotDisturbQuickAffordanceConfig.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/DoNotDisturbQuickAffordanceConfig.kt @@ -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 fun onZenAvailableChanged(available: Boolean) { - isAvailable = available - trySendWithFailureLogging(updateState(), TAG) - } - } - - dndMode = controller.zen - isAvailable = controller.isZenAvailable - trySendWithFailureLogging(updateState(), TAG) - - 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 } + 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) + } + } + + dndMode = controller.zen + isAvailable = controller.isZenAvailable + trySendWithFailureLogging(updateState(), TAG) + + 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 } 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" } -}
\ No newline at end of file +} diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/FlashlightQuickAffordanceConfig.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/FlashlightQuickAffordanceConfig.kt index 62fe80a82908..3412f35669e3 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/FlashlightQuickAffordanceConfig.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/FlashlightQuickAffordanceConfig.kt @@ -135,7 +135,7 @@ constructor( override suspend fun getPickerScreenState(): KeyguardQuickAffordanceConfig.PickerScreenState = if (flashlightController.isAvailable) { - KeyguardQuickAffordanceConfig.PickerScreenState.Default + KeyguardQuickAffordanceConfig.PickerScreenState.Default() } else { KeyguardQuickAffordanceConfig.PickerScreenState.UnavailableOnDevice } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/HomeControlsKeyguardQuickAffordanceConfig.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/HomeControlsKeyguardQuickAffordanceConfig.kt index 09e5ec0065f8..a1e9137d1764 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/HomeControlsKeyguardQuickAffordanceConfig.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/HomeControlsKeyguardQuickAffordanceConfig.kt @@ -90,7 +90,7 @@ constructor( ) } - return KeyguardQuickAffordanceConfig.PickerScreenState.Default + return KeyguardQuickAffordanceConfig.PickerScreenState.Default() } override fun onTriggered( diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/KeyguardQuickAffordanceConfig.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/KeyguardQuickAffordanceConfig.kt index 20588e9ccdc1..e32edcb010e8 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/KeyguardQuickAffordanceConfig.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/KeyguardQuickAffordanceConfig.kt @@ -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 diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/QrCodeScannerKeyguardQuickAffordanceConfig.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/QrCodeScannerKeyguardQuickAffordanceConfig.kt index 4f7990ff0deb..ea6c107cd161 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/QrCodeScannerKeyguardQuickAffordanceConfig.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/QrCodeScannerKeyguardQuickAffordanceConfig.kt @@ -89,7 +89,7 @@ constructor( ), ), ) - else -> KeyguardQuickAffordanceConfig.PickerScreenState.Default + else -> KeyguardQuickAffordanceConfig.PickerScreenState.Default() } } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/QuickAccessWalletKeyguardQuickAffordanceConfig.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/QuickAccessWalletKeyguardQuickAffordanceConfig.kt index 1928f40fa059..680c06bf2c64 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/QuickAccessWalletKeyguardQuickAffordanceConfig.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/QuickAccessWalletKeyguardQuickAffordanceConfig.kt @@ -128,7 +128,7 @@ constructor( actionComponentName = componentName, ) } - else -> KeyguardQuickAffordanceConfig.PickerScreenState.Default + else -> KeyguardQuickAffordanceConfig.PickerScreenState.Default() } } 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 index e3f5e90b2300..2b2b9d0703fa 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardQuickAffordanceRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardQuickAffordanceRepository.kt @@ -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, ) } } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/shared/model/KeyguardQuickAffordancePickerRepresentation.kt b/packages/SystemUI/src/com/android/systemui/keyguard/shared/model/KeyguardQuickAffordancePickerRepresentation.kt index 7d133598e105..e7e915940290 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/shared/model/KeyguardQuickAffordancePickerRepresentation.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/shared/model/KeyguardQuickAffordancePickerRepresentation.kt @@ -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, ) diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/DoNotDisturbQuickAffordanceConfigTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/DoNotDisturbQuickAffordanceConfigTest.kt index 7c10108d5b45..15b85ded5fd1 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/DoNotDisturbQuickAffordanceConfigTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/DoNotDisturbQuickAffordanceConfigTest.kt @@ -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) - - //when - val result = underTest.getPickerScreenState() - - //then - assertEquals(KeyguardQuickAffordanceConfig.PickerScreenState.Default, result) - } + fun `dnd available - picker state visible`() = + testScope.runTest { + // given + whenever(zenModeController.isZenAvailable).thenReturn(true) + + // when + val result = underTest.getPickerScreenState() + + // 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() - - //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) - } + 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) + ) + + // 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() - - //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) - } + 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) + ) + + // 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() - - //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) - } + 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) + ) + + // 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() - - //when - val result = underTest.onTriggered(expandable) - - //then - assertTrue(result is KeyguardQuickAffordanceConfig.OnTriggeredResult.ShowDialog) - assertEquals(expandable, (result as KeyguardQuickAffordanceConfig.OnTriggeredResult.ShowDialog).expandable) - } + 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) + + // 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()) - - //when - callbackCaptor.value.onZenAvailableChanged(false) - val lastValue = valueSnapshot() - - //then - assertTrue(secondLastValue is KeyguardQuickAffordanceConfig.LockScreenState.Visible) - assertTrue(lastValue is KeyguardQuickAffordanceConfig.LockScreenState.Hidden) - } + 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() + + // 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()) - - //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) + 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() + + // 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, - ) - } -}
\ No newline at end of file + lastValue, + ) + } +} diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/QrCodeScannerKeyguardQuickAffordanceConfigTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/QrCodeScannerKeyguardQuickAffordanceConfigTest.kt index 6255980601ac..9d2ddffddb5d 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/QrCodeScannerKeyguardQuickAffordanceConfigTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/QrCodeScannerKeyguardQuickAffordanceConfigTest.kt @@ -141,7 +141,7 @@ class QrCodeScannerKeyguardQuickAffordanceConfigTest : SysuiTestCase() { whenever(controller.isAbleToOpenCameraApp).thenReturn(true) assertThat(underTest.getPickerScreenState()) - .isEqualTo(KeyguardQuickAffordanceConfig.PickerScreenState.Default) + .isEqualTo(KeyguardQuickAffordanceConfig.PickerScreenState.Default()) } @Test diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/QuickAccessWalletKeyguardQuickAffordanceConfigTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/QuickAccessWalletKeyguardQuickAffordanceConfigTest.kt index d875dd94da3e..ca44fa18f6c4 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/QuickAccessWalletKeyguardQuickAffordanceConfigTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/QuickAccessWalletKeyguardQuickAffordanceConfigTest.kt @@ -159,7 +159,7 @@ class QuickAccessWalletKeyguardQuickAffordanceConfigTest : SysuiTestCase() { setUpState() assertThat(underTest.getPickerScreenState()) - .isEqualTo(KeyguardQuickAffordanceConfig.PickerScreenState.Default) + .isEqualTo(KeyguardQuickAffordanceConfig.PickerScreenState.Default()) } @Test |