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

Commit 1ce5e29f authored by Maryam Dehaini's avatar Maryam Dehaini
Browse files

Release the visual indicator before a new drag event if needed

DesktopModeVisualIndicator is currently throwing an
IllegalArgumentException due to an instance of the visual indicator that
is attempting to show a TO_DESKTOP indicator while the task is in
freeform.

The visual indicator decides to show the TO_DESKTOP indicator because
DesktopModeVisualIndicator#mStartDragState is not set to
DragStartState.FROM_FREEFORM (see
DesktopModeVisualIndicator#updateVisualIndicator). However, when
DesktopTaskCoordinator#onDragPositioningEnd is called, the task is in
freeform already which means the TO_DESKTOP indicator should not be
allowed to show.

This change clears the visual indicator saved in DesktopTasksCoordinator
id a new DragStartState is encountered (which means a new drag event has
started while the indicator has not yet been cleared). This may be
happening because clearing the indicator is tied to shell transitions.
So, if the transition does not finish by the time the new drag event
starts, the old indicator with the old DragStartState will be used which
might be causing this incorrect state.

Bug: 394021523
Test: drag task around and to/from fullscreen
Flag: com.android.window.flags.enable_desktop_windowing_mode
Change-Id: I90c376090978d28852fdab9969ff3644ebcfd7e6
parent 0a47004d
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -214,6 +214,13 @@ public class DesktopModeVisualIndicator {
        return result;
    }

    /**
     * Returns the [DragStartState] of the visual indicator.
     */
    DragStartState getDragStartState() {
        return mDragStartState;
    }

    @VisibleForTesting
    Region calculateFullscreenRegion(DisplayLayout layout, int captionHeight) {
        final Region region = new Region();
+7 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.os.Handler
import android.os.IBinder
import android.os.SystemProperties
import android.os.UserHandle
import android.util.Slog
import android.view.Display.DEFAULT_DISPLAY
import android.view.DragEvent
import android.view.MotionEvent
@@ -2743,6 +2744,12 @@ class DesktopTasksController(
        taskTop: Float,
        dragStartState: DragStartState,
    ): DesktopModeVisualIndicator.IndicatorType {
        // If the visual indicator has the wrong start state, it was never cleared from a previous
        // drag event and needs to be cleared
        if (visualIndicator != null && visualIndicator?.dragStartState != dragStartState) {
            Slog.e(TAG, "Visual indicator from previous motion event was never released")
            releaseVisualIndicator()
        }
        // If the visual indicator does not exist, create it.
        val indicator =
            visualIndicator