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

Commit 5cf40467 authored by Eghosa Ewansiha-Vlachavas's avatar Eghosa Ewansiha-Vlachavas
Browse files

Handle null activity in DMLPM calcualtions

When a task is being restored (e.g after reboot) it already contains its
relevant activities and thus no activity may be passed to the launch
param modifiers. In the event the DesktopModeLaunchParamsModifier
receives a null activity during its bound calculations, use the task top
most actiivty top resolve bounds. If the task does not contain a top
activity, simply default to the desired initial bounds.

Flag: EXEMPT bug fix
Fixes: 418046700
Test: atest WmTests:DesktopModeLaunchParamsModifierTests
Change-Id: Icb847bbc2c2b385810bd39f71ae2ddea7e75a9d0
parent ef2ca3a1
Loading
Loading
Loading
Loading
+3 −2
Original line number Original line Diff line number Diff line
@@ -141,14 +141,15 @@ public final class DesktopModeBoundsCalculator {
     */
     */
    @NonNull
    @NonNull
    private static Rect calculateInitialBounds(@NonNull Task task,
    private static Rect calculateInitialBounds(@NonNull Task task,
            @NonNull ActivityRecord activity, @NonNull Rect stableBounds,
            @Nullable ActivityRecord activity, @NonNull Rect stableBounds,
            @Nullable ActivityOptions options, @NonNull DisplayContent displayContent,
            @Nullable ActivityOptions options, @NonNull DisplayContent displayContent,
            boolean shouldRespectOptionPosition, int captionHeight
            boolean shouldRespectOptionPosition, int captionHeight
    ) {
    ) {
        // Display bounds not taking into account insets.
        // Display bounds not taking into account insets.
        final Rect screenBounds = displayContent.getBounds();
        final Rect screenBounds = displayContent.getBounds();
        final Size idealSize = calculateIdealSize(screenBounds, DESKTOP_MODE_INITIAL_BOUNDS_SCALE);
        final Size idealSize = calculateIdealSize(screenBounds, DESKTOP_MODE_INITIAL_BOUNDS_SCALE);
        if (!DesktopModeFlags.ENABLE_WINDOWING_DYNAMIC_INITIAL_BOUNDS.isTrue()) {
        if (!DesktopModeFlags.ENABLE_WINDOWING_DYNAMIC_INITIAL_BOUNDS.isTrue()
                || activity == null) {
            return centerInScreen(idealSize, screenBounds);
            return centerInScreen(idealSize, screenBounds);
        }
        }
        if (activity.mAppCompatController.getAspectRatioOverrides()
        if (activity.mAppCompatController.getAspectRatioOverrides()
+12 −7
Original line number Original line Diff line number Diff line
@@ -152,17 +152,22 @@ class DesktopModeLaunchParamsModifier implements LaunchParamsModifier {
            return RESULT_SKIP;
            return RESULT_SKIP;
        }
        }


        // If activity is null attempt to use task top activity if available.
        final ActivityRecord targetActivity = activity != null ? activity
                : task.getTopMostActivity();

        if (DesktopExperienceFlags.HANDLE_INCOMPATIBLE_TASKS_IN_DESKTOP_LAUNCH_PARAMS.isTrue()
        if (DesktopExperienceFlags.HANDLE_INCOMPATIBLE_TASKS_IN_DESKTOP_LAUNCH_PARAMS.isTrue()
                && activity != null) {
                && targetActivity != null) {
            final boolean isActivityStackTransparent = !task.forAllActivities(r ->
            final boolean isActivityStackTransparent = !task.forAllActivities(r ->
                    (r.occludesParent())) && !activity.occludesParent();
                    (r.occludesParent())) && !targetActivity.occludesParent();
            final AtomicInteger numActivities = new AtomicInteger(1);
            final AtomicInteger numActivities = new AtomicInteger(1);
            task.forAllActivities((r) -> {
            task.forAllActivities((r) -> {
                numActivities.incrementAndGet();
                numActivities.incrementAndGet();
            });
            });
            if (mDesktopModeCompatPolicy.isTopActivityExemptFromDesktopWindowing(
            if (mDesktopModeCompatPolicy.isTopActivityExemptFromDesktopWindowing(
                    activity.mActivityComponent, activity.isNoDisplay(), isActivityStackTransparent,
                    targetActivity.mActivityComponent, targetActivity.isNoDisplay(),
                    numActivities.get(), task.getUserId(), activity.info)) {
                    isActivityStackTransparent, numActivities.get(), task.getUserId(),
                    targetActivity.info)) {
                appendLog("activity exempt from desktop, launching in fullscreen");
                appendLog("activity exempt from desktop, launching in fullscreen");
                outParams.mWindowingMode = WINDOWING_MODE_FULLSCREEN;
                outParams.mWindowingMode = WINDOWING_MODE_FULLSCREEN;
                return RESULT_DONE;
                return RESULT_DONE;
@@ -255,7 +260,7 @@ class DesktopModeLaunchParamsModifier implements LaunchParamsModifier {
        if (DesktopModeFlags.INHERIT_TASK_BOUNDS_FOR_TRAMPOLINE_TASK_LAUNCHES.isTrue()) {
        if (DesktopModeFlags.INHERIT_TASK_BOUNDS_FOR_TRAMPOLINE_TASK_LAUNCHES.isTrue()) {
            ActivityRecord topVisibleFreeformActivity =
            ActivityRecord topVisibleFreeformActivity =
                    task.getDisplayContent().getTopMostVisibleFreeformActivity();
                    task.getDisplayContent().getTopMostVisibleFreeformActivity();
            if (shouldInheritExistingTaskBounds(topVisibleFreeformActivity, activity, task)) {
            if (shouldInheritExistingTaskBounds(topVisibleFreeformActivity, targetActivity, task)) {
                appendLog("inheriting bounds from existing closing instance");
                appendLog("inheriting bounds from existing closing instance");
                outParams.mBounds.set(topVisibleFreeformActivity.getBounds());
                outParams.mBounds.set(topVisibleFreeformActivity.getBounds());
                appendLog("final desktop mode task bounds set to %s", outParams.mBounds);
                appendLog("final desktop mode task bounds set to %s", outParams.mBounds);
@@ -264,8 +269,8 @@ class DesktopModeLaunchParamsModifier implements LaunchParamsModifier {
            }
            }
        }
        }


        DesktopModeBoundsCalculator.updateInitialBounds(task, layout, activity, options, display,
        DesktopModeBoundsCalculator.updateInitialBounds(task, layout, targetActivity, options,
                outParams, this::appendLog);
                display, outParams, this::appendLog);
        appendLog("final desktop mode task bounds set to %s", outParams.mBounds);
        appendLog("final desktop mode task bounds set to %s", outParams.mBounds);
        if (options != null && options.getFlexibleLaunchSize()) {
        if (options != null && options.getFlexibleLaunchSize()) {
            // Return result done to prevent other modifiers from respecting option bounds and
            // Return result done to prevent other modifiers from respecting option bounds and
+20 −0
Original line number Original line Diff line number Diff line
@@ -1412,6 +1412,26 @@ public class DesktopModeLaunchParamsModifierTests extends
        assertEquals(desiredHeight, mResult.mBounds.height());
        assertEquals(desiredHeight, mResult.mBounds.height());
    }
    }


    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE)
    public void testNullActivity_defaultBoundsApplied() {
        setupDesktopModeLaunchParamsModifier();

        final TestDisplayContent display = createDisplayContent(ORIENTATION_LANDSCAPE,
                LANDSCAPE_DISPLAY_BOUNDS);
        final Task task = createTask(display, /* isResizeable */ true);

        final int desiredWidth =
                (int) (LANDSCAPE_DISPLAY_BOUNDS.width() * DESKTOP_MODE_INITIAL_BOUNDS_SCALE);
        final int desiredHeight =
                (int) (LANDSCAPE_DISPLAY_BOUNDS.height() * DESKTOP_MODE_INITIAL_BOUNDS_SCALE);

        assertEquals(RESULT_CONTINUE, new CalculateRequestBuilder().setTask(task)
                .setActivity(null).calculate());
        assertEquals(desiredWidth, mResult.mBounds.width());
        assertEquals(desiredHeight, mResult.mBounds.height());
    }

    @Test
    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE)
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE)
    public void testNonEmptyActivityOptionsBounds() {
    public void testNonEmptyActivityOptionsBounds() {