Remove the failed-to-launch activity if attached to a parent

An exception was unexpectedly thrown while adding a child
activity to a task. That resulted in a abnormal state that
the activity is a child of the task while the
ActivityRecord#task was still null (which is updated
until #onParentChanged being called).

The CL removes the activity from its parent if any.

Bug: 224555550
Test: wm presubmit
Test: start a standard-launch-mode activity and put
      it to background, kill its process and start the
      activity again with FLAG_ACTIVITY_CLEAR_TOP flag.
Change-Id: I30ff04d961f3ca23cef89b6a5b6977860e9792d0
This commit is contained in:
Louis Chang
2022-03-15 17:33:52 +08:00
parent 9675d3b877
commit 963951144c

View File

@@ -1716,9 +1716,10 @@ class ActivityStarter {
// If we are not able to proceed, disassociate the activity from the task. Leaving an
// activity in an incomplete state can lead to issues, such as performing operations
// without a window container.
final Task rootTask = mStartActivity.getRootTask();
if (rootTask != null) {
if (mStartActivity.getTask() != null) {
mStartActivity.finishIfPossible("startActivity", true /* oomAdj */);
} else if (mStartActivity.getParent() != null) {
mStartActivity.getParent().removeChild(mStartActivity);
}
// Root task should also be detached from display and be removed if it's empty.