Merge "Attempt to fix NPE when reparent to the original task." into sc-dev am: fe4efedb7c

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14516704

Change-Id: If3f2b38c457c8e9179ea269886ecd603bafba9d2
This commit is contained in:
Jeff Chang
2021-05-21 03:25:24 +00:00
committed by Automerger Merge Worker

View File

@@ -1837,12 +1837,16 @@ class Task extends WindowContainer<WindowContainer> {
return autoRemoveRecents || (!hasChild() && !getHasBeenVisible());
}
/** Completely remove all activities associated with an existing task. */
void performClearTask(String reason) {
private void clearPinnedTaskIfNeed() {
// The original task is to be removed, try remove also the pinned task.
if (mChildPipActivity != null && mChildPipActivity.getTask() != null) {
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.
if (getRootTask() == null) {
forAllActivities((r) -> {
@@ -3220,7 +3224,7 @@ class Task extends WindowContainer<WindowContainer> {
mRemoving = true;
EventLogTags.writeWmTaskRemoved(mTaskId, reason);
clearPinnedTaskIfNeed();
// If applicable let the TaskOrganizer know the Task is vanishing.
setTaskOrganizer(null);
@@ -5439,10 +5443,12 @@ class Task extends WindowContainer<WindowContainer> {
// force hidden flag.
if (!isForceHidden()) {
final Task lastParentBeforePip = topActivity.getLastParentBeforePip();
topActivity.reparent(lastParentBeforePip,
lastParentBeforePip.getChildCount() /* top */,
"movePinnedActivityToOriginalTask");
lastParentBeforePip.moveToFront("movePinnedActivityToOriginalTask");
if (lastParentBeforePip.isAttached()) {
topActivity.reparent(lastParentBeforePip,
lastParentBeforePip.getChildCount() /* top */,
"movePinnedActivityToOriginalTask");
lastParentBeforePip.moveToFront("movePinnedActivityToOriginalTask");
}
}
}
}