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

Commit 57124ba2 authored by Ioana Alexandru's avatar Ioana Alexandru
Browse files

Open duration dialog from the main thread

Dialogs expect to be created from the main thread, so let's make sure we
switch to main when opening the duration dialog from the quick toggle on
the modes quick settings tile.

Fix: 391385776
Flag: android.app.modes_ui
Flag: com.android.systemui.qs_ui_refactor_compose_fragment
Test: turn on "Ask every time" and check that dialog works correctly
Change-Id: Ia0b086fd3e92f31a1ba9d5a75ae7a4d9ff7f6734
parent 53d05392
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import com.android.internal.logging.MetricsLogger
import com.android.systemui.SysuiTestCase
import com.android.systemui.classifier.FalsingManagerFake
import com.android.systemui.common.shared.model.asIcon
import com.android.systemui.kosmos.mainCoroutineContext
import com.android.systemui.kosmos.testDispatcher
import com.android.systemui.kosmos.testScope
import com.android.systemui.plugins.ActivityStarter
@@ -125,6 +126,7 @@ class ModesTileTest : SysuiTestCase() {

        userActionInteractor =
            ModesTileUserActionInteractor(
                kosmos.mainCoroutineContext,
                inputHandler,
                dialogDelegate,
                kosmos.zenModeInteractor,
+2 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import com.android.systemui.SysuiTestCase
import com.android.systemui.animation.Expandable
import com.android.systemui.common.shared.model.asIcon
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.mainCoroutineContext
import com.android.systemui.kosmos.testScope
import com.android.systemui.qs.tiles.base.actions.QSTileIntentUserInputHandlerSubject
import com.android.systemui.qs.tiles.base.actions.qsTileIntentUserInputHandler
@@ -62,6 +63,7 @@ class ModesTileUserActionInteractorTest : SysuiTestCase() {

    private val underTest =
        ModesTileUserActionInteractor(
            kosmos.mainCoroutineContext,
            inputHandler,
            mockDialogDelegate,
            zenModeInteractor,
+10 −4
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.provider.Settings
import android.util.Log
import com.android.systemui.animation.Expandable
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.qs.flags.QSComposeFragment
import com.android.systemui.qs.tiles.base.actions.QSTileIntentUserInputHandler
import com.android.systemui.qs.tiles.base.interactor.QSTileInput
@@ -31,11 +32,14 @@ import com.android.systemui.statusbar.policy.domain.interactor.ZenModeInteractor
import com.android.systemui.statusbar.policy.ui.dialog.ModesDialogDelegate
import com.android.systemui.statusbar.policy.ui.dialog.ModesDialogEventLogger
import javax.inject.Inject
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.withContext

@SysUISingleton
class ModesTileUserActionInteractor
@Inject
constructor(
    @Main private val mainContext: CoroutineContext,
    private val qsTileIntentUserInputHandler: QSTileIntentUserInputHandler,
    // TODO(b/353896370): The domain layer should not have to depend on the UI layer.
    private val dialogDelegate: ModesDialogDelegate,
@@ -65,7 +69,7 @@ constructor(
        dialogDelegate.showDialog(expandable)
    }

    fun handleToggleClick(modesTileModel: ModesTileModel) {
    suspend fun handleToggleClick(modesTileModel: ModesTileModel) {
        if (QSComposeFragment.isUnexpectedlyInLegacyMode()) {
            return
        }
@@ -83,9 +87,11 @@ constructor(

            if (zenModeInteractor.shouldAskForZenDuration(dnd)) {
                dialogEventLogger.logOpenDurationDialog(dnd)
                withContext(mainContext) {
                    // NOTE: The dialog handles turning on the mode itself.
                    val dialog = dialogDelegate.makeDndDurationDialog()
                    dialog.show()
                }
            } else {
                dialogEventLogger.logModeOn(dnd)
                zenModeInteractor.activateMode(dnd)
+2 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.statusbar.policy.ui.dialog

import android.annotation.UiThread;
import android.app.Dialog
import android.content.Context
import android.content.Intent
@@ -205,6 +206,7 @@ constructor(
     * Special dialog to ask the user for the duration of DND. Not to be confused with the modes
     * dialog itself.
     */
    @UiThread
    fun makeDndDurationDialog(): Dialog {
        val dialog =
            EnableDndDialogFactory(
+2 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.qs.tiles.impl.modes.domain.interactor

import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.mainCoroutineContext
import com.android.systemui.qs.tiles.base.actions.qsTileIntentUserInputHandler
import com.android.systemui.statusbar.policy.domain.interactor.zenModeInteractor
import com.android.systemui.statusbar.policy.ui.dialog.modesDialogDelegate
@@ -26,6 +27,7 @@ import javax.inject.Provider
val Kosmos.modesTileUserActionInteractor: ModesTileUserActionInteractor by
    Kosmos.Fixture {
        ModesTileUserActionInteractor(
            mainCoroutineContext,
            qsTileIntentUserInputHandler,
            Provider { modesDialogDelegate }.get(),
            zenModeInteractor,