From 01dbaea047c81375e977dc7cdf987735fecc4d3f Mon Sep 17 00:00:00 2001 From: Louis Chang Date: Wed, 21 Jul 2021 16:10:12 +0800 Subject: [PATCH] Finishing root activity if having other running activities When split activity, the back event can be sent to the root activity while still having the embedded activity displaying on top of the task. In that case, the task shouldn't be moved to back. Bug: 189385926 Test: finish root activity while split activities in task Change-Id: If85a10928a40cd15f60e88f313c09d0481788ea8 --- .../android/server/wm/ActivityClientController.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityClientController.java b/services/core/java/com/android/server/wm/ActivityClientController.java index 1f5ff256f17ce..331b8dee48700 100644 --- a/services/core/java/com/android/server/wm/ActivityClientController.java +++ b/services/core/java/com/android/server/wm/ActivityClientController.java @@ -1183,7 +1183,7 @@ class ActivityClientController extends IActivityClientController.Stub { try { final Intent baseActivityIntent; final boolean launchedFromHome; - + final boolean isLastRunningActivity; synchronized (mGlobalLock) { final ActivityRecord r = ActivityRecord.isInRootTaskLocked(token); if (r == null) return; @@ -1195,7 +1195,9 @@ class ActivityClientController extends IActivityClientController.Stub { return; } - final Intent baseIntent = r.getTask().getBaseIntent(); + final Task task = r.getTask(); + isLastRunningActivity = task.topRunningActivity() == r; + final Intent baseIntent = task.getBaseIntent(); final boolean activityIsBaseActivity = baseIntent != null && r.mActivityComponent.equals(baseIntent.getComponent()); baseActivityIntent = activityIsBaseActivity ? r.intent : null; @@ -1205,12 +1207,13 @@ class ActivityClientController extends IActivityClientController.Stub { // If the activity is one of the main entry points for the application, then we should // refrain from finishing the activity and instead move it to the back to keep it in // memory. The requirements for this are: - // 1. The current activity is the base activity for the task. - // 2. a. If the activity was launched by the home process, we trust that its intent + // 1. The activity is the last running activity in the task. + // 2. The current activity is the base activity for the task. + // 3. a. If the activity was launched by the home process, we trust that its intent // was resolved, so we check if the it is a main intent for the application. // b. Otherwise, we query Package Manager to verify whether the activity is a // launcher activity for the application. - if (baseActivityIntent != null + if (baseActivityIntent != null && isLastRunningActivity && ((launchedFromHome && ActivityRecord.isMainIntent(baseActivityIntent)) || isLauncherActivity(baseActivityIntent.getComponent()))) { moveActivityTaskToBack(token, false /* nonRoot */);