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

Commit 73e18a8c authored by Jeremy Sim's avatar Jeremy Sim Committed by Android (Google) Code Review
Browse files

Merge "Update task descriptions when reparenting or reordering children" into main

parents 9bd0c7f6 afed174b
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -1132,6 +1132,9 @@ class Task extends TaskFragment {
            final Task oldParentTask = oldParent.asTask();
            if (oldParentTask != null) {
                forAllActivities(oldParentTask::cleanUpActivityReferences);

                // Update the task description of the previous parent as well
                oldParentTask.updateTaskDescription();
            }

            if (newParent == null || !newParent.inPinnedWindowingMode()) {
@@ -1163,6 +1166,9 @@ class Task extends TaskFragment {
                } catch (RemoteException e) {
                }
            }

            // Update the ancestor tasks' task description after reparenting
            updateTaskDescription();
        }

        // First time we are adding the task to the system.
@@ -3353,7 +3359,7 @@ class Task extends TaskFragment {

        //TODO (AM refactor): Just use local once updateEffectiveIntent is run during all child
        //                    order changes.
        final Task topTask = top != null ? top.getTask() : this;
        final Task topTask = top != null && top.getTask() != null ? top.getTask() : this;
        info.resizeMode = topTask.mResizeMode;
        info.topActivityType = topTask.getActivityType();
        info.displayCutoutInsets = topTask.getDisplayCutoutInsets();
@@ -6138,9 +6144,8 @@ class Task extends TaskFragment {

    @Override
    void onChildPositionChanged(WindowContainer child) {
        dispatchTaskInfoChangedIfNeeded(false /* force */);

        if (!mChildren.contains(child)) {
            dispatchTaskInfoChangedIfNeeded(false /* force */);
            return;
        }
        if (child.asTask() != null) {
@@ -6152,6 +6157,10 @@ class Task extends TaskFragment {
            // Send for TaskFragmentParentInfo#hasDirectActivity change.
            sendTaskFragmentParentInfoChangedIfNeeded();
        }

        // Update the ancestor tasks' task description after any children have reparented
        updateTaskDescription();
        dispatchTaskInfoChangedIfNeeded(false /* force */);
    }

    void reparent(TaskDisplayArea newParent, boolean onTop) {
+43 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import static com.android.server.wm.ActivityRecord.State.RESUMED;
import static com.android.server.wm.Task.FLAG_FORCE_HIDDEN_FOR_TASK_ORG;
import static com.android.server.wm.TaskFragment.EMBEDDED_DIM_AREA_PARENT_TASK;
import static com.android.server.wm.TaskFragment.TASK_FRAGMENT_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT;
import static com.android.server.wm.WindowContainer.POSITION_TOP;

import static com.google.common.truth.Truth.assertThat;

@@ -78,6 +79,7 @@ import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.IBinder;
@@ -2031,6 +2033,47 @@ public class TaskTests extends WindowTestsBase {
                task.getTaskInfo().appCompatTaskInfo.cameraCompatTaskInfo.freeformCameraCompatMode);
    }

    @Test
    public void testUpdateTaskDescriptionOnReparent() {
        final Task rootTask1 = createTask(mDisplayContent);
        final Task rootTask2 = createTask(mDisplayContent);
        final Task childTask = createTaskInRootTask(rootTask1, 0 /* userId */);
        final ActivityRecord activity = createActivityRecord(mDisplayContent, childTask);
        final String testLabel = "test_task_description_label";
        final ActivityManager.TaskDescription td = new ActivityManager.TaskDescription(testLabel);
        activity.setTaskDescription(td);

        // Ensure the td is set for the original root task
        assertEquals(testLabel, rootTask1.getTaskDescription().getLabel());
        assertNull(rootTask2.getTaskDescription().getLabel());

        childTask.reparent(rootTask2, POSITION_TOP, false /* moveParents */, "reparent");

        // Ensure the td is set for the new root task
        assertEquals(testLabel, rootTask2.getTaskDescription().getLabel());
    }

    @Test
    public void testUpdateTaskDescriptionOnReorder() {
        final Task task = createTask(mDisplayContent);
        final ActivityRecord activity1 = createActivityRecord(mDisplayContent, task);
        final ActivityRecord activity2 = createActivityRecord(mDisplayContent, task);
        final ActivityManager.TaskDescription td1 = new ActivityManager.TaskDescription();
        td1.setBackgroundColor(Color.RED);
        activity1.setTaskDescription(td1);
        final ActivityManager.TaskDescription td2 = new ActivityManager.TaskDescription();
        td2.setBackgroundColor(Color.BLUE);
        activity2.setTaskDescription(td2);

        // Ensure the td is set for the original root task
        assertEquals(Color.BLUE, task.getTaskDescription().getBackgroundColor());

        task.positionChildAt(POSITION_TOP, activity1, false /* includeParents */);

        // Ensure the td is set for the original root task
        assertEquals(Color.RED, task.getTaskDescription().getBackgroundColor());
    }

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