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

Commit 1bc0e9be authored by Nicolo' Mazzucato's avatar Nicolo' Mazzucato
Browse files

Use the shade display instead of the focused one to open dialogs

When the focused display was different than the shade display, dialogs
were unexpectedly opening on the wrong display. This happened because
expanding the shade doesn't change the display id focus.

This is a workaround for the focused display not changing when the shade window is opened in a specific display.
While the behaviour is being clarified, this cl uses the shade display id to open all dialogs/launch activities related to the shade window.

Why was the focused display id used instead of the shade one? Because certain dialogs (e.g. internet dialog triggered from all apps QS tile after searching for "internet") are supposed to open in the focused display and are unrelated to the shade display. The choice was between providing 2 different contexes, or just using the focused display. The focused display ended up being used with the assumption it changed when the shade was expanded, but it currently doesn't. If it does, we should partially revert this to use the focused display id.

Fortunately an e2e caught this early in postsubmits.

The logic of `context` has been simplified as well.

Bug: 428281768
Bug: 428694180
Bug: 423929154
Flag: com.android.systemui.shade_window_goes_around
Test: OpenSettingsFromQuickSettings
Change-Id: I3485987d6a7bc31a5576637e758cb72114f25198
parent 3ce3461d
Loading
Loading
Loading
Loading
+7 −16
Original line number Diff line number Diff line
@@ -27,10 +27,8 @@ import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.display.data.repository.DisplayWindowPropertiesRepository
import com.android.systemui.display.data.repository.FocusedDisplayRepository
import com.android.systemui.shade.data.repository.ShadeDisplaysRepository
import com.android.systemui.shade.shared.flag.ShadeWindowGoesAround
import com.android.window.flags.Flags
import javax.inject.Inject
import javax.inject.Provider
import kotlinx.coroutines.CoroutineScope
@@ -51,7 +49,6 @@ constructor(
    private val displayWindowPropertyRepository: Provider<DisplayWindowPropertiesRepository>,
    private val shadeDisplaysRepository: Provider<ShadeDisplaysRepository>,
    @Background private val bgScope: CoroutineScope,
    private val focusedDisplayRepository: FocusedDisplayRepository,
) : CoreStartable, ShadeDialogContextInteractor {

    override fun start() {
@@ -71,22 +68,16 @@ constructor(
    }

    override val context: Context
        get() {
            if (Flags.enableWindowContextOverrideType()) {
                return focusedDisplayContext
            } else {
        get() = getContextOrDefault(shadeDisplayId)

    private val shadeDisplayId: Int
        get() =
            if (!ShadeWindowGoesAround.isEnabled) {
                    return defaultContext
                }
                val displayId = shadeDisplaysRepository.get().displayId.value
                return getContextOrDefault(displayId)
            }
                Display.DEFAULT_DISPLAY
            } else {
                shadeDisplaysRepository.get().displayId.value
            }

    /** Context that can be used to open a dialog on the focused display. */
    private val focusedDisplayContext: Context
        get() = getContextOrDefault(focusedDisplayRepository.focusedDisplayId.value)

    private fun getContextOrDefault(displayId: Int): Context {
        return try {
            traceSection({ "Getting dialog context for displayId=$displayId" }) {