From d9cce2cadb791d4d8e913eabb3238268b7c9813f Mon Sep 17 00:00:00 2001 From: Bryce Lee Date: Mon, 4 Dec 2017 16:16:27 -0800 Subject: [PATCH] Ensure activity stacks have unique ids. Currently ActivityStackSupervisor will return the first id that it discovers that is not added to the display. However, stack addition logic is written in a way where multiple stacks can be created before being added. This leads to multiple stacks with the same id. This changelist corrects this collision by always incrementing the current stack after returning it to the caller. The check to see if the id is in use has been removed and the bookkeeping is now in ActivityDisplay. Change-Id: I2c1b86ef8d74b9aa2eac134ac546c0111fa5e22c Fixes: 68952156 Test: atest CtsActivityManagerDeviceTestCases:android.server.am.ActivityManagerAppConfigurationTests#testSameConfigurationSplitFullSplitNoRelaunch Test: atest CtsActivityManagerDeviceTestCases:android.server.am.ActivityManagerAppConfigurationTests#testSameConfigurationSplitFullSplitRelaunch --- .../java/com/android/server/am/ActivityDisplay.java | 12 +++++++++++- .../android/server/am/ActivityStackSupervisor.java | 13 ------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityDisplay.java b/services/core/java/com/android/server/am/ActivityDisplay.java index b11b16e12c3a3..2d2424fe7b590 100644 --- a/services/core/java/com/android/server/am/ActivityDisplay.java +++ b/services/core/java/com/android/server/am/ActivityDisplay.java @@ -65,6 +65,12 @@ class ActivityDisplay extends ConfigurationContainer { static final int POSITION_TOP = Integer.MAX_VALUE; static final int POSITION_BOTTOM = Integer.MIN_VALUE; + + /** + * Counter for next free stack ID to use for dynamic activity stacks. Unique across displays. + */ + private static int sNextFreeStackId = 0; + private ActivityStackSupervisor mSupervisor; /** Actual Display this object tracks. */ int mDisplayId; @@ -231,6 +237,10 @@ class ActivityDisplay extends ConfigurationContainer { return getOrCreateStack(windowingMode, activityType, onTop); } + private int getNextStackId() { + return sNextFreeStackId++; + } + /** * Creates a stack matching the input windowing mode and activity type on this display. * @param windowingMode The windowing mode the stack should be created in. If @@ -278,7 +288,7 @@ class ActivityDisplay extends ConfigurationContainer { } } - final int stackId = mSupervisor.getNextStackId(); + final int stackId = getNextStackId(); return createStackUnchecked(windowingMode, activityType, stackId, onTop); } diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java index 48c08a5718b9f..cd3b21c63ad64 100644 --- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java +++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java @@ -298,9 +298,6 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D private LaunchingBoundsController mLaunchingBoundsController; - /** Counter for next free stack ID to use for dynamic activity stacks. */ - private int mNextFreeStackId = 0; - /** * Maps the task identifier that activities are currently being started in to the userId of the * task. Each time a new task is created, the entry for the userId of the task is incremented @@ -2904,16 +2901,6 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D } } - int getNextStackId() { - while (true) { - if (getStack(mNextFreeStackId) == null) { - break; - } - mNextFreeStackId++; - } - return mNextFreeStackId; - } - /** * Called to restore the state of the task into the stack that it's supposed to go into. *