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

Commit 7f64b144 authored by Hongwei Wang's avatar Hongwei Wang
Browse files

Fix back stack for PiP from multi-activity Task

Details in design doc go/pip-and-back

Video: http://recall/-/aaaaaabFQoRHlzixHdtY/g8lbXnC8ln0t54ARxfPELo
Bug: 184758170
Test: ensure back stack works for Netflix, see video
Test: atest PinnedStackTests
Test: atest RootWindowContainerTests
Change-Id: I9e2f8d0d50dd107ff30fd7afe6273d8347aac803
parent e5bb44a8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -161,6 +161,7 @@ package android.app {
    method @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS) public void moveTaskToRootTask(int, int, boolean);
    method @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS) public void removeRootTasksInWindowingModes(@NonNull int[]);
    method @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS) public void removeRootTasksWithActivityTypes(@NonNull int[]);
    method @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS) public boolean removeTask(int);
    method @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS) public void resizeTask(int, android.graphics.Rect);
    method @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS) public void startSystemLockTaskMode(int);
    method @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS) public void stopSystemLockTaskMode();
+2 −1
Original line number Diff line number Diff line
@@ -469,7 +469,8 @@ public class ActivityTaskManager {
        }
    }

    /** @hide */
    /** Removes task by a given taskId */
    @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS)
    public boolean removeTask(int taskId) {
        try {
            return getService().removeTask(taskId);
+1 −0
Original line number Diff line number Diff line
@@ -308,6 +308,7 @@ message TaskProto {
    optional float minimize_amount = 27;
    optional bool created_by_organizer = 28;
    optional string affinity = 29;
    optional bool has_child_pip_activity = 30;
}

/* represents ActivityRecordProto */
+38 −3
Original line number Diff line number Diff line
@@ -587,7 +587,14 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A

    AnimatingActivityRegistry mAnimatingActivityRegistry;

    private Task mLastParent;
    // Set whenever the ActivityRecord gets reparented to a Task so we can know the last known
    // parent was when the ActivityRecord is detached from the hierarchy
    private Task mLastKnownParent;

    // Set to the previous Task parent of the ActivityRecord when it is reparented to a new Task
    // due to picture-in-picture. This gets cleared whenever this activity or the Task
    // it references to gets removed. This should also be cleared when we move out of pip.
    private Task mLastParentBeforePip;

    boolean firstWindowDrawn;
    /** Whether the visible window(s) of this activity is drawn. */
@@ -1096,6 +1103,9 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                pw.println(prefix + "configChanges=0x" + Integer.toHexString(info.configChanges));
            }
        }
        if (mLastParentBeforePip != null) {
            pw.println(prefix + "lastParentTaskIdBeforePip=" + mLastParentBeforePip.mTaskId);
        }

        dumpLetterboxInfo(pw, prefix);
    }
@@ -1349,7 +1359,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            if (getDisplayContent() != null) {
                getDisplayContent().mClosingApps.remove(this);
            }
        } else if (mLastParent != null && mLastParent.getRootTask() != null) {
        } else if (mLastKnownParent != null && mLastKnownParent.getRootTask() != null) {
            task.getRootTask().mExitingActivities.remove(this);
        }
        final Task rootTask = getRootTask();
@@ -1362,7 +1372,11 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                ? rootTask.getAnimatingActivityRegistry()
                : null;

        mLastParent = task;
        mLastKnownParent = task;
        if (mLastKnownParent == mLastParentBeforePip) {
            // Activity's reparented back from pip, clear the links once established
            clearLastParentBeforePip();
        }

        updateColorTransform();

@@ -1381,6 +1395,26 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        }
    }

    /**
     * Sets {@link #mLastParentBeforePip} to the current parent Task, it's caller's job to ensure
     * {@link #getTask()} is set before this is called.
     */
    void setLastParentBeforePip() {
        mLastParentBeforePip = getTask();
        mLastParentBeforePip.mChildPipActivity = this;
    }

    private void clearLastParentBeforePip() {
        if (mLastParentBeforePip != null) {
            mLastParentBeforePip.mChildPipActivity = null;
            mLastParentBeforePip = null;
        }
    }

    @Nullable Task getLastParentBeforePip() {
        return mLastParentBeforePip;
    }

    private void updateColorTransform() {
        if (mSurfaceControl != null && mLastAppSaturationInfo != null) {
            getPendingTransaction().setColorTransform(mSurfaceControl,
@@ -3434,6 +3468,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
     */
    void cleanUp(boolean cleanServices, boolean setState) {
        task.cleanUpActivityReferences(this);
        clearLastParentBeforePip();

        deferRelaunchUntilPaused = false;
        frozenBeforeDestroy = false;
+3 −0
Original line number Diff line number Diff line
@@ -1415,6 +1415,9 @@ class RecentTasks {
            return true;
        }

        // The given task if always treated as in visible range if it is the origin of pinned task.
        if (task.mChildPipActivity != null) return true;

        if (mMaxNumVisibleTasks >= 0) {
            // Always keep up to the max number of recent tasks, but return false afterwards
            return numVisibleTasks <= mMaxNumVisibleTasks;
Loading