From 6d42df6d176a8defb3e1f1dedc128763a8b91677 Mon Sep 17 00:00:00 2001 From: Wale Ogunwale Date: Thu, 5 Nov 2015 09:50:55 -0800 Subject: [PATCH] Set correct focus activity when using FLAG_ACTIVITY_REORDER_TO_FRONT When FLAG_ACTIVITY_REORDER_TO_FRONT is used to launch an activity we move the activity to the front of the task, but the ActivityRecord.frontOfTask isn't set because the activity isn't in the resumed set yet. This causes issues later on when we try to detemine the focus activity in ActivityStack.adjustFocusedActivityLocked. We now set ActivityRecord.frontOfTask for the activity we are moving due to FLAG_ACTIVITY_REORDER_TO_FRONT Bug: 25487874 Change-Id: I4a20e6fb11e04ae16361da27c59aec2641b82bfb --- .../java/com/android/server/am/TaskRecord.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/am/TaskRecord.java b/services/core/java/com/android/server/am/TaskRecord.java index 5fd213f96c661..c35b91ffb4f0f 100644 --- a/services/core/java/com/android/server/am/TaskRecord.java +++ b/services/core/java/com/android/server/am/TaskRecord.java @@ -572,9 +572,18 @@ final class TaskRecord { return null; } + void setFrontOfTask() { + setFrontOfTask(null); + } + /** Call after activity movement or finish to make sure that frontOfTask is set correctly */ - final void setFrontOfTask() { - boolean foundFront = false; + void setFrontOfTask(ActivityRecord newTop) { + // If a top candidate is suggested by the caller, go ahead and use it and mark all others + // as not front. This is needed in situations where the current front activity in the + // task isn't finished yet and we want to set the front to the activity moved to the front + // of the task. + boolean foundFront = newTop != null ? true : false; + final int numActivities = mActivities.size(); for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { final ActivityRecord r = mActivities.get(activityNdx); @@ -591,6 +600,9 @@ final class TaskRecord { // activity, make the bottom activity front. mActivities.get(0).frontOfTask = true; } + if (newTop != null) { + newTop.frontOfTask = true; + } } /** @@ -605,7 +617,7 @@ final class TaskRecord { mActivities.add(newTop); updateEffectiveIntent(); - setFrontOfTask(); + setFrontOfTask(newTop); } void addActivityAtBottom(ActivityRecord r) {