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

Commit 5590a336 authored by Nicolo' Mazzucato's avatar Nicolo' Mazzucato
Browse files

Fix issues when shade window is moved very fast between displays

If the shade window was moved too fast between displays the "wait for expansion to finish" was failing with a timeout, making the ShadeDisplayRepository information about where the shade was supposed to be wrong.

In this new version even if we hit the shade expansion timeout we ignore the error (as it can happen also because the user is half expanded manually)

Also cancellation has a better error message that also shows the display id move that failed.

Bug: 362719719
Test: Move the shade between displays quickly and verify the expansion on a new display always triggers the shade to move
Flag: com.android.systemui.shade_window_goes_around
Change-Id: I5b036e8747a523a2ce404dceb175bb42d874f62e
parent cc32b4c1
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ constructor(
     */
    @Synchronized
    fun onShadeDisplayChanging(displayId: Int) {
        previousJob?.cancel(CancellationException("New shade move in progress"))
        previousJob?.cancel(CancellationException("New shade move in progress to $displayId"))
        previousJob = bgScope.launch { onShadeDisplayChangingAsync(displayId) }
    }

@@ -109,8 +109,8 @@ constructor(
            val reason =
                when (e) {
                    is CancellationException ->
                        "Shade move cancelled as a new move is being done " +
                            "before the previous one finished."
                        "Shade move to $displayId cancelled as a new move is being done " +
                            "before the previous one finished. Message: ${e.message}"

                    else -> "Shade move cancelled."
                }
+13 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.shade.domain.interactor

import android.util.Log
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.scene.shared.flag.SceneContainerFlag
@@ -25,6 +26,7 @@ import com.android.systemui.shade.shared.flag.DualShade
import com.android.systemui.util.kotlin.Utils.Companion.combineState
import javax.inject.Inject
import kotlin.coroutines.CoroutineContext
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
@@ -32,7 +34,7 @@ import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.withContext
import kotlinx.coroutines.withTimeout
import kotlinx.coroutines.withTimeoutOrNull

/**
 * Wrapper around [ShadeInteractor] to facilitate expansion and collapse of Notifications and quick
@@ -57,6 +59,8 @@ interface ShadeExpandedStateInteractor {
    }
}

private val EXPAND_COLLAPSE_TIMEOUT: Duration = 1.seconds

@SysUISingleton
class ShadeExpandedStateInteractorImpl
@Inject
@@ -89,7 +93,14 @@ constructor(
private suspend fun StateFlow<Float>.waitUntil(f: Float, coroutineContext: CoroutineContext) {
    // it's important to not do this in the main thread otherwise it will block any rendering.
    withContext(coroutineContext) {
        withTimeout(1.seconds) { traceWaitForExpansion(expansion = f) { first { it == f } } }
        withTimeoutOrNull(EXPAND_COLLAPSE_TIMEOUT) {
            traceWaitForExpansion(expansion = f) { first { it == f } }
        }
            ?: Log.e(
                "ShadeExpStateInteractor",
                "Timed out after ${EXPAND_COLLAPSE_TIMEOUT.inWholeMilliseconds}ms while waiting " +
                        "for expansion to match $f. Current one: $value",
            )
    }
}