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

Commit f7468497 authored by Eghosa Ewansiha-Vlachavas's avatar Eghosa Ewansiha-Vlachavas Committed by Android (Google) Code Review
Browse files

Merge "[1/n]Don't respect task requested override bounds if larger than display" into main

parents c8fe6f64 03ab15b3
Loading
Loading
Loading
Loading
+24 −8
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.app.ActivityOptions;
import android.app.WindowConfiguration;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.graphics.Rect;
import android.window.DesktopExperienceFlags;
import android.window.DesktopModeFlags;

@@ -245,17 +246,22 @@ class DesktopModeLaunchParamsModifier implements LaunchParamsModifier {

        if ((options == null || options.getLaunchBounds() == null) && task.hasOverrideBounds()) {
            if (DesktopModeFlags.DISABLE_DESKTOP_LAUNCH_PARAMS_OUTSIDE_DESKTOP_BUG_FIX.isTrue()) {
                // We are in desktop, return result done to prevent other modifiers from modifying
                // exiting task bounds or resolved windowing mode.
                final Rect overrideTaskBounds = task.getRequestedOverrideBounds();
                if (DesktopExperienceFlags.IGNORE_OVERRIDE_TASK_BOUNDS_IF_INCOMPATIBLE_WITH_DISPLAY
                        .isTrue() && areTaskBoundsValidForDisplay(overrideTaskBounds, display)) {
                    // We are in desktop, return result done to prevent other modifiers from
                    // modifying exiting task bounds or resolved windowing mode.
                    if (ENABLE_FREEFORM_DISPLAY_LAUNCH_PARAMS.isTrue()) {
                    outParams.mBounds.set(task.getRequestedOverrideBounds());
                        outParams.mBounds.set(overrideTaskBounds);
                    }
                appendLog("task-has-override-bounds=%s", task.getRequestedOverrideBounds());
                    appendLog("task-has-override-bounds=%s", overrideTaskBounds);
                    return RESULT_DONE;
                }
            } else {
                appendLog("current task has bounds set, not overriding");
                return RESULT_SKIP;
            }
        }

        if (DesktopModeFlags.INHERIT_TASK_BOUNDS_FOR_TRAMPOLINE_TASK_LAUNCHES.isTrue()) {
            ActivityRecord topVisibleFreeformActivity =
@@ -344,6 +350,16 @@ class DesktopModeLaunchParamsModifier implements LaunchParamsModifier {
        };
    }

    /**
     * Returns true if the given bounds are within the stables bounds of a given display.
     */
    private boolean areTaskBoundsValidForDisplay(@NonNull Rect taskBounds,
            @NonNull DisplayContent displayContent) {
        final Rect displayStableBounds = new Rect();
        displayContent.getStableRect(displayStableBounds);
        return displayStableBounds.contains(taskBounds);
    }

    /**
     * Whether the launching task should inherit the task bounds of an existing closing instance.
     */
+41 −0
Original line number Diff line number Diff line
@@ -603,6 +603,47 @@ public class DesktopModeLaunchParamsModifierTests extends
        assertNotEquals(existingFreeformTask.getBounds(), mResult.mBounds);
    }

    @Test
    @EnableFlags({Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE,
            Flags.FLAG_ENABLE_FREEFORM_DISPLAY_LAUNCH_PARAMS,
            Flags.FLAG_DISABLE_DESKTOP_LAUNCH_PARAMS_OUTSIDE_DESKTOP_BUG_FIX,
            Flags.FLAG_IGNORE_OVERRIDE_TASK_BOUNDS_IF_INCOMPATIBLE_WITH_DISPLAY})
    public void testRespectOverrideTaskBoundsIfValid() {
        setupDesktopModeLaunchParamsModifier();

        final TestDisplayContent display = createNewDisplayContent(WINDOWING_MODE_FREEFORM);
        final Task task = new TaskBuilder(mSupervisor).setActivityType(
                ACTIVITY_TYPE_STANDARD).setDisplay(display).build();
        // Override task bounds within display.
        final Rect displayStableBounds = new Rect();
        display.getStableRect(displayStableBounds);
        task.setBounds(displayStableBounds);

        // Task bounds should be respect.
        new CalculateRequestBuilder().setTask(task).calculate();
        assertEquals(displayStableBounds, mResult.mBounds);
    }

    @Test
    @EnableFlags({Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE,
            Flags.FLAG_ENABLE_FREEFORM_DISPLAY_LAUNCH_PARAMS,
            Flags.FLAG_DISABLE_DESKTOP_LAUNCH_PARAMS_OUTSIDE_DESKTOP_BUG_FIX,
            Flags.FLAG_IGNORE_OVERRIDE_TASK_BOUNDS_IF_INCOMPATIBLE_WITH_DISPLAY})
    public void testDontRespectOverrideTaskBoundsIfNotValid() {
        setupDesktopModeLaunchParamsModifier();

        final TestDisplayContent display = createNewDisplayContent(WINDOWING_MODE_FREEFORM);
        final Task task = new TaskBuilder(mSupervisor).setActivityType(
                ACTIVITY_TYPE_STANDARD).setDisplay(display).build();
        // Override task bounds with bounds larger than display in at least on dimension.
        final Rect overrideTaskBounds = new Rect(0, 0, 100, 10000);
        task.setBounds(overrideTaskBounds);

        // Task bounds should not be respected.
        new CalculateRequestBuilder().setTask(task).calculate();
        assertNotEquals(overrideTaskBounds, mResult.mBounds);
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE)
    @DisableFlags(Flags.FLAG_ENABLE_WINDOWING_DYNAMIC_INITIAL_BOUNDS)