From 29a649da5f8097efdb28d6982edbe43091eda44f Mon Sep 17 00:00:00 2001 From: Bryce Lee Date: Fri, 18 Aug 2017 13:52:31 -0700 Subject: [PATCH] Remove activity from stopping activities once resumed. Previously we were waiting for the activity to become visible before removing from this list. This can lead to a race condition where the activity is resumed and the stopping activities are cleaned up. If the activity has not become visible, the resumed activity will be stopped. This CL addresses the issue by removing the activity from the stopping activities list once resume has completed. Change-Id: Ic33906327e538920961e60064a6ae976864509be Fixes: 63804822 Test: bit FrameworksServicesTests:com.android.server.am.ActivityStackSupervisorTests#testStoppingActivityRemovedWhenResumed --- .../com/android/server/am/ActivityStackSupervisor.java | 3 +++ .../server/am/ActivityStackSupervisorTests.java | 18 ++++++++++++++++++ .../src/com/android/server/am/ActivityTestsBase.java | 4 ++++ 3 files changed, 25 insertions(+) diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java index 1c1895449466..a985be5c3c87 100644 --- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java +++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java @@ -3297,6 +3297,9 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D } boolean reportResumedActivityLocked(ActivityRecord r) { + // A resumed activity cannot be stopping. remove from list + mStoppingActivities.remove(r); + final ActivityStack stack = r.getStack(); if (isFocusedStack(stack)) { mService.updateUsageStats(r, true); diff --git a/services/tests/servicestests/src/com/android/server/am/ActivityStackSupervisorTests.java b/services/tests/servicestests/src/com/android/server/am/ActivityStackSupervisorTests.java index fc9ab9635c57..661dd4fc828c 100644 --- a/services/tests/servicestests/src/com/android/server/am/ActivityStackSupervisorTests.java +++ b/services/tests/servicestests/src/com/android/server/am/ActivityStackSupervisorTests.java @@ -21,6 +21,7 @@ import static android.app.ActivityManager.StackId.PINNED_STACK_ID; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; import android.content.ComponentName; import android.graphics.Rect; @@ -117,4 +118,21 @@ public class ActivityStackSupervisorTests extends ActivityTestsBase { assertTrue(stackTasks.contains(task)); } } + + /** + * Ensures that an activity is removed from the stopping activities list once it is resumed. + */ + @Test + public void testStoppingActivityRemovedWhenResumed() throws Exception { + final ActivityManagerService service = createActivityManagerService(); + final TaskRecord firstTask = createTask(service, testActivityComponent, + FULLSCREEN_WORKSPACE_STACK_ID); + final ActivityRecord firstActivity = createActivity(service, testActivityComponent, + firstTask); + service.mStackSupervisor.mStoppingActivities.add(firstActivity); + + firstActivity.completeResumeLocked(); + + assertFalse(service.mStackSupervisor.mStoppingActivities.contains(firstActivity)); + } } diff --git a/services/tests/servicestests/src/com/android/server/am/ActivityTestsBase.java b/services/tests/servicestests/src/com/android/server/am/ActivityTestsBase.java index 4ad92c7ec14e..c03a95789be4 100644 --- a/services/tests/servicestests/src/com/android/server/am/ActivityTestsBase.java +++ b/services/tests/servicestests/src/com/android/server/am/ActivityTestsBase.java @@ -145,6 +145,10 @@ public class ActivityTestsBase { protected ActivityStackSupervisor createStackSupervisor() { return new TestActivityStackSupervisor(this, mHandlerThread.getLooper()); } + + @Override + void updateUsageStats(ActivityRecord component, boolean resumed) { + } } /** -- 2.11.0