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

Commit 2eb4c1e8 authored by Eghosa Ewansiha-Vlachavas's avatar Eghosa Ewansiha-Vlachavas
Browse files

[2/n] Ignore current params in desktop launch params

Current params can be restored/ presisted from previous states and thus
might not accurately represent the destination state of the task /
applicaton (i.e just because current params have freeform mode doen't
necessarily mean the task wants to enter freeform). Due to this
uncertainty as well as the current params not acutally being necessary
to resolve desktop mode specific launch param, we will ignore them
during the calculation.

Flag: com.android.window.flags.ignore_override_task_bounds_if_incompatible_with_display
Bug: 419222219
Bug: 432273227
Test: atest WmTests:DesktopModeLaunchParamsModifierTests

Change-Id: I612a4cf66e12bc646e18760fd9daf5ed0f0d3676
parent 32631090
Loading
Loading
Loading
Loading
+27 −10
Original line number Original line Diff line number Diff line
@@ -195,10 +195,11 @@ class DesktopModeLaunchParamsModifier implements LaunchParamsModifier {
            return RESULT_SKIP;
            return RESULT_SKIP;
        }
        }


        // TODO(b/419222219): Remove inheritance on currentParams.
        if (!DesktopExperienceFlags.IGNORE_CURRENT_PARAMS_IN_DESKTOP_LAUNCH_PARAMS.isTrue()) {
            // Copy over any values.
            // Copy over any values.
            outParams.set(currentParams);
            outParams.set(currentParams);
            outParams.mPreferredTaskDisplayArea = suggestedDisplayArea;
            outParams.mPreferredTaskDisplayArea = suggestedDisplayArea;
        }


        boolean isFullscreenInDeskTask = inDesktopFirstContainer && requestFullscreen;
        boolean isFullscreenInDeskTask = inDesktopFirstContainer && requestFullscreen;
        if (source != null && source.getTask() != null) {
        if (source != null && source.getTask() != null) {
@@ -240,7 +241,9 @@ class DesktopModeLaunchParamsModifier implements LaunchParamsModifier {
            return RESULT_CONTINUE;
            return RESULT_CONTINUE;
        }
        }


        if (!currentParams.mBounds.isEmpty() && !inDesktopMode) {
        if (!currentParams.mBounds.isEmpty() && !inDesktopMode
                && !DesktopExperienceFlags.IGNORE_CURRENT_PARAMS_IN_DESKTOP_LAUNCH_PARAMS.isTrue()
        ) {
            appendLog("currentParams has bounds set, not overriding");
            appendLog("currentParams has bounds set, not overriding");
            return RESULT_SKIP;
            return RESULT_SKIP;
        }
        }
@@ -321,7 +324,8 @@ class DesktopModeLaunchParamsModifier implements LaunchParamsModifier {
            @NonNull LaunchParamsController.LaunchParams currentParams) {
            @NonNull LaunchParamsController.LaunchParams currentParams) {
        return (task != null && task.inFreeformWindowingMode())
        return (task != null && task.inFreeformWindowingMode())
                || (options != null && options.getLaunchWindowingMode() == WINDOWING_MODE_FREEFORM)
                || (options != null && options.getLaunchWindowingMode() == WINDOWING_MODE_FREEFORM)
                || currentParams.mWindowingMode == WINDOWING_MODE_FREEFORM;
                || (currentParams.mWindowingMode == WINDOWING_MODE_FREEFORM
                && !DesktopExperienceFlags.IGNORE_CURRENT_PARAMS_IN_DESKTOP_LAUNCH_PARAMS.isTrue());
    }
    }


    /**
    /**
@@ -331,10 +335,23 @@ class DesktopModeLaunchParamsModifier implements LaunchParamsModifier {
            @NonNull Task task,
            @NonNull Task task,
            @Nullable ActivityOptions options,
            @Nullable ActivityOptions options,
            @NonNull LaunchParamsController.LaunchParams currentParams) {
            @NonNull LaunchParamsController.LaunchParams currentParams) {
        return isCompatibleDesktopWindowingMode(task.getWindowingMode())
        // 1. Check the task's own windowing mode.
                && (options == null
        final boolean isTaskWindowModeCompatible =
                    || isCompatibleDesktopWindowingMode(options.getLaunchWindowingMode()))
                isCompatibleDesktopWindowingMode(task.getWindowingMode());
                && isCompatibleDesktopWindowingMode(currentParams.mWindowingMode);
        // 2. Check the windowing mode from ActivityOptions, if they exist.
        // If options are null, we consider it compatible.
        final boolean isOptionsWindowModeCompatible = options == null
                || isCompatibleDesktopWindowingMode(options.getLaunchWindowingMode());
        // 3. Check the windowing mode from the current launch parameters.
        // This check can be skipped if the IGNORE_CURRENT_PARAMS_IN_DESKTOP_LAUNCH_PARAMS flag is
        // true.
        final boolean isCurrentParamsWindowModeCompatible =
                isCompatibleDesktopWindowingMode(currentParams.mWindowingMode)
                        || DesktopExperienceFlags.IGNORE_CURRENT_PARAMS_IN_DESKTOP_LAUNCH_PARAMS
                        .isTrue();
        // All checks must pass for the source window modes to be considered compatible.
        return isTaskWindowModeCompatible && isOptionsWindowModeCompatible
                && isCurrentParamsWindowModeCompatible;
    }
    }


    /**
    /**
+36 −0
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_INSTANCE;
import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_INSTANCE;
import static android.content.pm.ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_LARGE_VALUE;
import static android.content.pm.ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_LARGE_VALUE;
import static android.content.pm.ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_MEDIUM_VALUE;
import static android.content.pm.ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_MEDIUM_VALUE;
@@ -40,6 +41,7 @@ import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
import static android.util.DisplayMetrics.DENSITY_DEFAULT;
import static android.util.DisplayMetrics.DENSITY_DEFAULT;
import static android.view.Surface.ROTATION_90;
import static android.view.Surface.ROTATION_90;


import static com.android.dx.mockito.inline.extended.ExtendedMockito.doCallRealMethod;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
import static com.android.internal.policy.SystemBarUtils.getDesktopViewAppHeaderHeightPx;
import static com.android.internal.policy.SystemBarUtils.getDesktopViewAppHeaderHeightPx;
@@ -452,6 +454,7 @@ public class DesktopModeLaunchParamsModifierTests extends


    @Test
    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE)
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE)
    @DisableFlags(Flags.FLAG_IGNORE_CURRENT_PARAMS_IN_DESKTOP_LAUNCH_PARAMS)
    public void testReturnsSkipIfCurrentParamsHasBounds() {
    public void testReturnsSkipIfCurrentParamsHasBounds() {
        setupDesktopModeLaunchParamsModifier();
        setupDesktopModeLaunchParamsModifier();


@@ -461,6 +464,19 @@ public class DesktopModeLaunchParamsModifierTests extends
        assertEquals(RESULT_SKIP, new CalculateRequestBuilder().setTask(task).calculate());
        assertEquals(RESULT_SKIP, new CalculateRequestBuilder().setTask(task).calculate());
    }
    }


    @Test
    @EnableFlags({Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE,
            Flags.FLAG_IGNORE_CURRENT_PARAMS_IN_DESKTOP_LAUNCH_PARAMS})
    public void testIgnoreCurrentParamsBounds() {
        setupDesktopModeLaunchParamsModifier();

        final Task task = new TaskBuilder(mSupervisor).setActivityType(
                ACTIVITY_TYPE_STANDARD).build();
        mCurrent.mBounds.set(/* left */ 0, /* top */ 0, /* right */ 100, /* bottom */ 100);
        new CalculateRequestBuilder().setTask(task).calculate();
        assertNotEquals(mCurrent.mBounds, mResult.mBounds);
    }

    @Test
    @Test
    @EnableFlags(Flags.FLAG_ENABLE_FREEFORM_DISPLAY_LAUNCH_PARAMS)
    @EnableFlags(Flags.FLAG_ENABLE_FREEFORM_DISPLAY_LAUNCH_PARAMS)
    public void testReturnsDoneIfTaskNullLaunchInFreeform() {
    public void testReturnsDoneIfTaskNullLaunchInFreeform() {
@@ -1880,6 +1896,7 @@ public class DesktopModeLaunchParamsModifierTests extends


    @Test
    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE)
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE)
    @DisableFlags(Flags.FLAG_IGNORE_CURRENT_PARAMS_IN_DESKTOP_LAUNCH_PARAMS)
    public void testInheritWindowingModeFromCurrentParams() {
    public void testInheritWindowingModeFromCurrentParams() {
        setupDesktopModeLaunchParamsModifier();
        setupDesktopModeLaunchParamsModifier();


@@ -1895,6 +1912,25 @@ public class DesktopModeLaunchParamsModifierTests extends
        assertEquals(WINDOWING_MODE_FREEFORM, mResult.mWindowingMode);
        assertEquals(WINDOWING_MODE_FREEFORM, mResult.mWindowingMode);
    }
    }


    @Test
    @EnableFlags({Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE,
            Flags.FLAG_IGNORE_CURRENT_PARAMS_IN_DESKTOP_LAUNCH_PARAMS})
    public void testDoesntInheritWindowingModeFromCurrentParams() {
        setupDesktopModeLaunchParamsModifier();
        doCallRealMethod().when(mTarget).isEnteringDesktopMode(any(), any(), any());

        final Task task = new TaskBuilder(mSupervisor).setActivityType(
                ACTIVITY_TYPE_STANDARD).build();
        final TaskDisplayArea currTaskDisplayArea = mock(TaskDisplayArea.class);
        mCurrent.mPreferredTaskDisplayArea = currTaskDisplayArea;
        mCurrent.mWindowingMode = WINDOWING_MODE_FREEFORM;

        assertEquals(RESULT_SKIP, new CalculateRequestBuilder().setTask(task).calculate());
        assertEquals(task.getRootTask().getDisplayArea(), mResult.mPreferredTaskDisplayArea);
        assertNotEquals(currTaskDisplayArea, mResult.mPreferredTaskDisplayArea);
        assertEquals(WINDOWING_MODE_UNDEFINED, mResult.mWindowingMode);
    }

    @Test
    @Test
    @EnableFlags({Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE,
    @EnableFlags({Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE,
            Flags.FLAG_DISABLE_DESKTOP_LAUNCH_PARAMS_OUTSIDE_DESKTOP_BUG_FIX,
            Flags.FLAG_DISABLE_DESKTOP_LAUNCH_PARAMS_OUTSIDE_DESKTOP_BUG_FIX,