From 963951144cbb3426590756a754fceb10d384f7ab Mon Sep 17 00:00:00 2001 From: Louis Chang Date: Tue, 15 Mar 2022 17:33:52 +0800 Subject: [PATCH] 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 --- .../core/java/com/android/server/wm/ActivityStarter.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityStarter.java b/services/core/java/com/android/server/wm/ActivityStarter.java index 7d2dfa0715979..bcf88279a7ded 100644 --- a/services/core/java/com/android/server/wm/ActivityStarter.java +++ b/services/core/java/com/android/server/wm/ActivityStarter.java @@ -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.