Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 45a5dffb authored by Ioana Alexandru's avatar Ioana Alexandru
Browse files

Make dndMode not lazy

This was causing issues when pressing on the quick toggle in QS, because
the flow being lazy meant that the collection (although technically
SharingStarted.Eagerly) would only start on the first use of the flow -
but since the tile was already expecting a value to have been emitted
then, it was falling back on the initial null value and failing.

Fix: 382497909
Test: reboot device and press quick QS toggle for Modes (without opening
the dialog)
Flag: EXEMPT minor bug fix

Change-Id: Ifada0e05ea6955e23c7ba0acf42a9e489a539f07
parent 931fe7cc
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -58,7 +58,9 @@ class ModesTileDataInteractorTest : SysuiTestCase() {
    private val dispatcher = kosmos.testDispatcher
    private val zenModeRepository = kosmos.fakeZenModeRepository

    private val underTest = ModesTileDataInteractor(context, kosmos.zenModeInteractor, dispatcher)
    private val underTest by lazy {
        ModesTileDataInteractor(context, kosmos.zenModeInteractor, dispatcher)
    }

    @Before
    fun setUp() {
+1 −1
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ class EmptyShadeViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
    private val activeNotificationListRepository = kosmos.activeNotificationListRepository
    private val fakeSecureSettingsRepository = kosmos.fakeSecureSettingsRepository

    private val underTest = kosmos.emptyShadeViewModel
    private val underTest by lazy { kosmos.emptyShadeViewModel }

    companion object {
        @JvmStatic
+4 −4
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ class ZenModeInteractorTest : SysuiTestCase() {
    private val settingsRepository = kosmos.secureSettingsRepository
    private val deviceProvisioningRepository = kosmos.fakeDeviceProvisioningRepository

    private val underTest = kosmos.zenModeInteractor
    private val underTest by lazy { kosmos.zenModeInteractor }

    @Test
    fun isZenAvailable_off() =
@@ -176,13 +176,13 @@ class ZenModeInteractorTest : SysuiTestCase() {
    @Test
    fun shouldAskForZenDuration_changesWithSetting() =
        kosmos.runTest {
            val manualDnd = TestModeBuilder().makeManualDnd().setActive(true).build()
            val manualDnd by collectLastValue(underTest.dndMode)

            settingsRepository.setInt(ZEN_DURATION, ZEN_DURATION_FOREVER)
            assertThat(underTest.shouldAskForZenDuration(manualDnd)).isFalse()
            assertThat(underTest.shouldAskForZenDuration(manualDnd!!)).isFalse()

            settingsRepository.setInt(ZEN_DURATION, ZEN_DURATION_PROMPT)
            assertThat(underTest.shouldAskForZenDuration(manualDnd)).isTrue()
            assertThat(underTest.shouldAskForZenDuration(manualDnd!!)).isTrue()
        }

    @Test
+15 −6
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
@@ -123,11 +124,19 @@ constructor(
     * explicitly wants a shortcut to DND). Please prefer using [modes] or [activeModes] in all
     * other scenarios.
     */
    val dndMode: StateFlow<ZenMode?> by lazy {
        ModesUi.assertInNewMode()
    val dndMode: StateFlow<ZenMode?> =
        if (ModesUi.isEnabled)
            zenModeRepository.modes
                .map { modes -> modes.singleOrNull { it.isManualDnd } }
            .stateIn(scope = backgroundScope, started = SharingStarted.Eagerly, initialValue = null)
                .stateIn(
                    scope = backgroundScope,
                    started = SharingStarted.Eagerly,
                    initialValue = null,
                )
        else MutableStateFlow<ZenMode?>(null)
        get() {
            ModesUi.assertInNewMode()
            return field
        }

    /** Flow returning the currently active mode(s), if any. */