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

Commit afed174b authored by Jeremy Sim's avatar Jeremy Sim
Browse files

Update task descriptions when reparenting or reordering children

- The task description coalesces information from the descriptions
  provided by the child task's activities, so when the children or
  their ordering changes, we also need to update ancestor task's
  task descriptions as well.

Bug: 339274381
Test: atest TaskTests
Test: Revert ag/27365753 and try the steps in the bug
Flag: EXEMPT bugfix

Change-Id: I3d859cad9b036c823306bd7122988e7b23ac07f7
parent 2cb43006
Loading
Loading
Loading
Loading
+12 −3
Original line number Original line Diff line number Diff line
@@ -1132,6 +1132,9 @@ class Task extends TaskFragment {
            final Task oldParentTask = oldParent.asTask();
            final Task oldParentTask = oldParent.asTask();
            if (oldParentTask != null) {
            if (oldParentTask != null) {
                forAllActivities(oldParentTask::cleanUpActivityReferences);
                forAllActivities(oldParentTask::cleanUpActivityReferences);

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


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

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


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


        //TODO (AM refactor): Just use local once updateEffectiveIntent is run during all child
        //TODO (AM refactor): Just use local once updateEffectiveIntent is run during all child
        //                    order changes.
        //                    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.resizeMode = topTask.mResizeMode;
        info.topActivityType = topTask.getActivityType();
        info.topActivityType = topTask.getActivityType();
        info.displayCutoutInsets = topTask.getDisplayCutoutInsets();
        info.displayCutoutInsets = topTask.getDisplayCutoutInsets();
@@ -6135,9 +6141,8 @@ class Task extends TaskFragment {


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

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

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


    void reparent(TaskDisplayArea newParent, boolean onTop) {
    void reparent(TaskDisplayArea newParent, boolean onTop) {
+43 −0
Original line number Original line 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.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.EMBEDDED_DIM_AREA_PARENT_TASK;
import static com.android.server.wm.TaskFragment.TASK_FRAGMENT_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT;
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;
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.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.ApplicationInfo;
import android.content.res.Configuration;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.Rect;
import android.os.IBinder;
import android.os.IBinder;
@@ -2022,6 +2024,47 @@ public class TaskTests extends WindowTestsBase {
                task.getTaskInfo().appCompatTaskInfo.cameraCompatTaskInfo.freeformCameraCompatMode);
                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() {
    private Task getTestTask() {
        return new TaskBuilder(mSupervisor).setCreateActivity(true).build();
        return new TaskBuilder(mSupervisor).setCreateActivity(true).build();
    }
    }