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

Commit 5fedc1b6 authored by Jeff Chang's avatar Jeff Chang
Browse files

Attempt to fix NPE when reparent to the original task.

7f64b144, Fix back stack for PiP from multi-activity Task. Trying to
reparent pinned activity back to its original task. The NPE is
introduced when the original task is removed.

This CL removes the pinned task when the original task is to be
removed and checks for the task is attached before doing the
re-parent.

Bug: 186374793
Test: atest PinnedStackTests
Test: atest RootWindowContainerTests
Change-Id: I6ea6100cb94b3982737c89f68de824a14415283a
parent 5c62d1f9
Loading
Loading
Loading
Loading
+13 −7
Original line number Original line Diff line number Diff line
@@ -1854,12 +1854,16 @@ class Task extends WindowContainer<WindowContainer> {
        return autoRemoveRecents || (!hasChild() && !getHasBeenVisible());
        return autoRemoveRecents || (!hasChild() && !getHasBeenVisible());
    }
    }


    /** Completely remove all activities associated with an existing task. */
    private void clearPinnedTaskIfNeed() {
    void performClearTask(String reason) {
        // The original task is to be removed, try remove also the pinned task.
        // The original task is to be removed, try remove also the pinned task.
        if (mChildPipActivity != null && mChildPipActivity.getTask() != null) {
        if (mChildPipActivity != null && mChildPipActivity.getTask() != null) {
            mTaskSupervisor.removeRootTask(mChildPipActivity.getTask());
            mTaskSupervisor.removeRootTask(mChildPipActivity.getTask());
        }
        }
    }

    /** Completely remove all activities associated with an existing task. */
    void performClearTask(String reason) {
        clearPinnedTaskIfNeed();
        // Broken down into to cases to avoid object create due to capturing mStack.
        // Broken down into to cases to avoid object create due to capturing mStack.
        if (getRootTask() == null) {
        if (getRootTask() == null) {
            forAllActivities((r) -> {
            forAllActivities((r) -> {
@@ -3246,7 +3250,7 @@ class Task extends WindowContainer<WindowContainer> {
        mRemoving = true;
        mRemoving = true;


        EventLogTags.writeWmTaskRemoved(mTaskId, reason);
        EventLogTags.writeWmTaskRemoved(mTaskId, reason);

        clearPinnedTaskIfNeed();
        // If applicable let the TaskOrganizer know the Task is vanishing.
        // If applicable let the TaskOrganizer know the Task is vanishing.
        setTaskOrganizer(null);
        setTaskOrganizer(null);


@@ -5449,6 +5453,7 @@ class Task extends WindowContainer<WindowContainer> {
                    // force hidden flag.
                    // force hidden flag.
                    if (!isForceHidden()) {
                    if (!isForceHidden()) {
                        final Task lastParentBeforePip = topActivity.getLastParentBeforePip();
                        final Task lastParentBeforePip = topActivity.getLastParentBeforePip();
                        if (lastParentBeforePip.isAttached()) {
                            topActivity.reparent(lastParentBeforePip,
                            topActivity.reparent(lastParentBeforePip,
                                    lastParentBeforePip.getChildCount() /* top */,
                                    lastParentBeforePip.getChildCount() /* top */,
                                    "movePinnedActivityToOriginalTask");
                                    "movePinnedActivityToOriginalTask");
@@ -5456,6 +5461,7 @@ class Task extends WindowContainer<WindowContainer> {
                        }
                        }
                    }
                    }
                }
                }
            }


            if (creating) {
            if (creating) {
                // Nothing else to do if we don't have a window container yet. E.g. call from ctor.
                // Nothing else to do if we don't have a window container yet. E.g. call from ctor.