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

Commit ae4b9339 authored by Louis Chang's avatar Louis Chang
Browse files

Layout the existing Task to ensure the bounds are updated

An existing Task was started with requested bounds via
ActivityOptions#setLaunchBounds, but the Task bounds was
not the same as the requested bounds.

Bug: 390291971
Test: StartActivityTests#testStartActivityWithLaunchBounds
Flag: com.android.window.flags.fix_layout_existing_task
Change-Id: I3bfc195c89e19c72d1d3f73ac4e00a1f65444e4e
parent d9efeb47
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -3035,6 +3035,12 @@ class ActivityStarter {
            }
        }

        if (com.android.window.flags.Flags.fixLayoutExistingTask()) {
            // Layout the task to ensure the Task is in correct bounds.
            mSupervisor.getLaunchParamsController().layoutTask(intentTask,
                    mStartActivity.info.windowLayout, mStartActivity, mSourceRecord, mOptions);
        }

        // If the target task is not in the front, then we need to bring it to the front.
        final boolean differentTopTask;
        if (mTargetRootTask.getDisplayArea() == mPreferredTaskDisplayArea) {
+6 −0
Original line number Diff line number Diff line
@@ -74,6 +74,12 @@ class DesktopModeLaunchParamsModifier implements LaunchParamsModifier {
            appendLog("task null, skipping");
            return RESULT_SKIP;
        }
        if (com.android.window.flags.Flags.fixLayoutExistingTask()
                && task.getOrganizedTask() != null) {
            appendLog("task is organized, skipping");
            return RESULT_SKIP;
        }

        if (!task.isActivityTypeStandardOrUndefined()) {
            appendLog("not standard or undefined activity type, skipping");
            return RESULT_SKIP;
+2 −14
Original line number Diff line number Diff line
@@ -124,31 +124,19 @@ class LaunchParamsController {
        }
    }

    /**
     * A convenience method for laying out a task.
     * @return {@code true} if bounds were set on the task. {@code false} otherwise.
     */
    boolean layoutTask(Task task, WindowLayout layout) {
        return layoutTask(task, layout, null /*activity*/, null /*source*/, null /*options*/);
    }

    /** @return {@code true} if bounds were set on the task. {@code false} otherwise. */
    boolean layoutTask(Task task, WindowLayout layout, ActivityRecord activity,
            ActivityRecord source, ActivityOptions options) {
        calculate(task, layout, activity, source, options, null /* request */, PHASE_BOUNDS,
                mTmpParams);

        // No changes, return.
        if (mTmpParams.isEmpty()) {
        if (mTmpParams.isEmpty() || mTmpParams.mBounds.isEmpty()) {
            return false;
        }

        mService.deferWindowLayout();

        try {
            if (mTmpParams.mBounds.isEmpty()) {
                return false;
            }

            if (task.getRootTask().inMultiWindowMode()) {
                task.setBounds(mTmpParams.mBounds);
                return true;
+15 −13
Original line number Diff line number Diff line
@@ -75,7 +75,6 @@ import static com.android.server.wm.ActivityRecord.TRANSFER_SPLASH_SCREEN_COPYIN
import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_RECENTS;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_SWITCH;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_TRANSITION;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_USER_LEAVING;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_CLEANUP;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_RECENTS;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_SWITCH;
@@ -6058,7 +6057,7 @@ class Task extends TaskFragment {
            IVoiceInteractor voiceInteractor, boolean toTop, ActivityRecord activity,
            ActivityRecord source, ActivityOptions options) {

        Task task;
        final Task task;
        if (canReuseAsLeafTask()) {
            // This root task will only contain one task, so just return itself since all root
            // tasks ara now tasks and all tasks are now root tasks.
@@ -6068,7 +6067,6 @@ class Task extends TaskFragment {
            final int taskId = activity != null
                    ? mTaskSupervisor.getNextTaskIdForUser(activity.mUserId)
                    : mTaskSupervisor.getNextTaskIdForUser();
            final int activityType = getActivityType();
            task = new Task.Builder(mAtmService)
                    .setTaskId(taskId)
                    .setActivityInfo(info)
@@ -6081,17 +6079,21 @@ class Task extends TaskFragment {
                    .build();
        }

        if (com.android.window.flags.Flags.fixLayoutExistingTask()) {
            mTaskSupervisor.getLaunchParamsController()
                    .layoutTask(task, info.windowLayout, activity, source, options);
        } else {
            int displayId = getDisplayId();
            if (displayId == INVALID_DISPLAY) displayId = DEFAULT_DISPLAY;
        final boolean isLockscreenShown = mAtmService.mTaskSupervisor.getKeyguardController()
                .isKeyguardOrAodShowing(displayId);
            final boolean isLockscreenShown =
                    mAtmService.mKeyguardController.isKeyguardOrAodShowing(displayId);
            if (!mTaskSupervisor.getLaunchParamsController()
                    .layoutTask(task, info.windowLayout, activity, source, options)
                    && !getRequestedOverrideBounds().isEmpty()
                    && task.isResizeable() && !isLockscreenShown) {
                task.setBounds(getRequestedOverrideBounds());
            }

        }
        return task;
    }

+10 −4
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import static com.android.server.wm.LaunchParamsController.LaunchParamsModifier.
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;

import android.annotation.NonNull;
import android.app.ActivityOptions;
import android.content.ComponentName;
import android.content.pm.ActivityInfo.WindowLayout;
@@ -293,7 +294,7 @@ public class LaunchParamsControllerTests extends WindowTestsBase {
        final int beforeWindowMode = task.getWindowingMode();
        assertNotEquals(windowingMode, beforeWindowMode);

        mController.layoutTask(task, null /* windowLayout */);
        layoutTask(task);

        final int afterWindowMode = task.getWindowingMode();
        assertEquals(afterWindowMode, beforeWindowMode);
@@ -317,7 +318,7 @@ public class LaunchParamsControllerTests extends WindowTestsBase {

        assertNotEquals(expected, task.getBounds());

        mController.layoutTask(task, null /* windowLayout */);
        layoutTask(task);

        // Task will make adjustments to requested bounds. We only need to guarantee that the
        // reuqested bounds are expected.
@@ -342,7 +343,7 @@ public class LaunchParamsControllerTests extends WindowTestsBase {

        assertNotEquals(expected, task.getBounds());

        mController.layoutTask(task, null /* windowLayout */);
        layoutTask(task);

        assertEquals(expected, task.getRequestedOverrideBounds());
    }
@@ -365,7 +366,7 @@ public class LaunchParamsControllerTests extends WindowTestsBase {

        assertNotEquals(expected, task.getBounds());

        mController.layoutTask(task, null /* windowLayout */);
        layoutTask(task);

        assertNotEquals(expected, task.getBounds());
        assertEquals(expected, task.mLastNonFullscreenBounds);
@@ -467,4 +468,9 @@ public class LaunchParamsControllerTests extends WindowTestsBase {
    private TestDisplayContent createNewDisplayContent() {
        return addNewDisplayContentAt(DisplayContent.POSITION_TOP);
    }

    private void layoutTask(@NonNull Task task) {
        mController.layoutTask(task, null /* layout */, null /* activity */, null /* source */,
                null /* options */);
    }
}