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

Commit 4cf15e8f authored by Chris Li's avatar Chris Li
Browse files

Update Task minWidth/Height when base Intent is changed

Similar to Task#mResizeMode, update minWidth/Height when the root
activity is changed.

Bug: 416987720
Test: atest WmTests:TaskTests
Flag: com.android.window.flags.update_task_min_dimensions_with_root_activity
Change-Id: I8d05369a439d6102241c50a9f42dfb5262672538
parent c018324a
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -564,7 +564,9 @@ public class TaskInfo {
                    == that.topActivityRequestOpenInBrowserEducationTimestamp
                && appCompatTaskInfo.equalsForTaskOrganizer(that.appCompatTaskInfo)
                && Objects.equals(topActivityMainWindowFrame, that.topActivityMainWindowFrame)
                && isAppBubble == that.isAppBubble;
                && isAppBubble == that.isAppBubble
                && (!com.android.window.flags.Flags.updateTaskMinDimensionsWithRootActivity()
                || (minWidth == that.minWidth && minHeight == that.minHeight));
    }

    /**
+10 −0
Original line number Diff line number Diff line
@@ -227,3 +227,13 @@ flag {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    namespace: "windowing_sdk"
    name: "update_task_min_dimensions_with_root_activity"
    description: "Update minWidth/Height when the root activity is changed."
    bug: "416987720"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}
 No newline at end of file
+39 −8
Original line number Diff line number Diff line
@@ -694,7 +694,9 @@ class Task extends TaskFragment {
        mResizeMode = resizeMode;
        if (info != null) {
            setIntent(_intent, info);
            if (!Flags.updateTaskMinDimensionsWithRootActivity()) {
                setMinDimensions(info);
            }
        } else {
            intent = _intent;
            mMinWidth = minWidth;
@@ -721,7 +723,9 @@ class Task extends TaskFragment {
        voiceSession = _voiceSession;
        voiceInteractor = _voiceInteractor;
        setIntent(activity, intent, info);
        if (!Flags.updateTaskMinDimensionsWithRootActivity()) {
            setMinDimensions(info);
        }
        // Before we began to reuse a root task as the leaf task, we used to
        // create a leaf task in this case. Therefore now we won't send out the task created
        // notification when we decide to reuse it here, so we send out the notification below.
@@ -1050,8 +1054,17 @@ class Task extends TaskFragment {
        } else {
            autoRemoveRecents = false;
        }
        boolean shouldUpdateTaskDescription = false;
        if (mResizeMode != info.resizeMode) {
            mResizeMode = info.resizeMode;
            shouldUpdateTaskDescription = true;
        }
        if (Flags.updateTaskMinDimensionsWithRootActivity()) {
            if (setMinDimensions(info)) {
                shouldUpdateTaskDescription = true;
            }
        }
        if (shouldUpdateTaskDescription) {
            updateTaskDescription();
        }
        mSupportsPictureInPicture = info.supportsPictureInPicture();
@@ -1064,15 +1077,33 @@ class Task extends TaskFragment {
        }
    }

    /** Sets the original minimal width and height. */
    void setMinDimensions(ActivityInfo info) {
    /** Sets the original minimal width and height. Returns true if changed. */
    @VisibleForTesting
    boolean setMinDimensions(ActivityInfo info) {
        final int minWidth;
        final int minHeight;
        if (info != null && info.windowLayout != null) {
            mMinWidth = info.windowLayout.minWidth;
            mMinHeight = info.windowLayout.minHeight;
            minWidth = info.windowLayout.minWidth;
            minHeight = info.windowLayout.minHeight;
        } else {
            mMinWidth = INVALID_MIN_SIZE;
            mMinHeight = INVALID_MIN_SIZE;
            minWidth = INVALID_MIN_SIZE;
            minHeight = INVALID_MIN_SIZE;
        }

        if (mMinWidth == minWidth && mMinHeight == minHeight) {
            return false;
        }
        mMinWidth = minWidth;
        mMinHeight = minHeight;
        if (Flags.updateTaskMinDimensionsWithRootActivity()) {
            // Only update for pure TaskFragment.
            forAllTaskFragments(tf -> {
                if (tf.asTask() == null) {
                    tf.setMinDimensions(minWidth, minHeight);
                }
            });
        }
        return true;
    }

    /**
+49 −0
Original line number Diff line number Diff line
@@ -2193,6 +2193,55 @@ public class TaskTests extends WindowTestsBase {
        assertFalse(task.isForceExcludedFromRecents());
    }

    @EnableFlags(Flags.FLAG_UPDATE_TASK_MIN_DIMENSIONS_WITH_ROOT_ACTIVITY)
    @Test
    public void testAllowRelingquish_updateMinDimensions() {
        // r0 allows relingquish
        final ActivityRecord r0 = new ActivityBuilder(mAtm)
                .setCreateTask(true)
                .setWindowLayout(new ActivityInfo.WindowLayout(
                        0, 0, 0, 0, 0, 500 /* minWidth */, 1000 /* minHeight*/))
                .setActivityFlags(FLAG_RELINQUISH_TASK_IDENTITY)
                .build();
        final Task task = r0.getTask();

        assertEquals(500, task.mMinWidth);
        assertEquals(1000, task.mMinHeight);

        final ActivityRecord r1 = new ActivityBuilder(mAtm)
                .setTask(task)
                .setWindowLayout(new ActivityInfo.WindowLayout(
                        0, 0, 0, 0, 0, 1000 /* minWidth */, 500 /* minHeight*/))
                .build();

        assertEquals(1000, task.mMinWidth);
        assertEquals(500, task.mMinHeight);
    }

    @EnableFlags(Flags.FLAG_UPDATE_TASK_MIN_DIMENSIONS_WITH_ROOT_ACTIVITY)
    @Test
    public void testDisallowRelingquish_notUpdateMinDimensions() {
        // r0 disallows relingquish
        final ActivityRecord r0 = new ActivityBuilder(mAtm)
                .setCreateTask(true)
                .setWindowLayout(new ActivityInfo.WindowLayout(
                        0, 0, 0, 0, 0, 500 /* minWidth */, 1000 /* minHeight*/))
                .build();
        final Task task = r0.getTask();

        assertEquals(500, task.mMinWidth);
        assertEquals(1000, task.mMinHeight);

        final ActivityRecord r1 = new ActivityBuilder(mAtm)
                .setTask(task)
                .setWindowLayout(new ActivityInfo.WindowLayout(
                        0, 0, 0, 0, 0, 1000 /* minWidth */, 500 /* minHeight*/))
                .build();

        assertEquals(500, task.mMinWidth);
        assertEquals(1000, task.mMinHeight);
    }

    private Task getTestTask() {
        return new TaskBuilder(mSupervisor).setCreateActivity(true).build();
    }