diff options
| author | 2019-10-11 15:07:47 -0700 | |
|---|---|---|
| committer | 2020-01-22 11:38:29 -0800 | |
| commit | f45dd9fc583bf3d67a3c906d46f7a933ea5741c0 (patch) | |
| tree | 85dc4daa6108923c07a6b3bc445feb2a86966b2c | |
| parent | 55a6d9a470815c5b859056433a3d0dec77c43321 (diff) | |
Always add the task to the recent task list when starting
- Currently, when creating a new task as a part of starting an
activity, we sometimes don't update the recent tasks list until
the next activity state is resumed. This can lead to issues
where the set of recent tasks is wrong if the task list is
fetched before the activity state changes (due to the app being
slow or another activity launched immediately afterwards causing
the first activity's state to skip resume and go to stop). For
consistency, we can just always add the task to the recent task
list in all cases.
Bug: 141580748
Test: atest ActivityStarterTests
Test: atest RecentTasksTest
Change-Id: I61b0c065caf3b775e64190f92f2c8a4471d12b08
| -rw-r--r-- | services/core/java/com/android/server/wm/ActivityStarter.java | 4 | ||||
| -rw-r--r-- | services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java | 14 |
2 files changed, 16 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 6587226b14d7..f0bf94593eff 100644 --- a/services/core/java/com/android/server/wm/ActivityStarter.java +++ b/services/core/java/com/android/server/wm/ActivityStarter.java @@ -1595,11 +1595,11 @@ class ActivityStarter { mRootWindowContainer.resumeFocusedStacksTopActivities( mTargetStack, mStartActivity, mOptions); } - } else if (mStartActivity != null) { - mSupervisor.mRecentTasks.add(mStartActivity.getTask()); } mRootWindowContainer.updateUserStack(mStartActivity.mUserId, mTargetStack); + // Update the recent tasks list immediately when the activity starts + mSupervisor.mRecentTasks.add(mStartActivity.getTask()); mSupervisor.handleNonResizableTaskIfNeeded(mStartActivity.getTask(), preferredWindowingMode, mPreferredDisplayId, mTargetStack); diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java index 9e54f4044e0a..60dece13e8b7 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java @@ -1006,4 +1006,18 @@ public class ActivityStarterTests extends ActivityTestsBase { .setOutActivity(outActivity).execute(); assertThat(outActivity[0].inSplitScreenSecondaryWindowingMode()).isTrue(); } + + @Test + public void testActivityStart_expectAddedToRecentTask() { + RecentTasks recentTasks = mock(RecentTasks.class); + mService.mStackSupervisor.setRecentTasks(recentTasks); + doReturn(true).when(recentTasks).isCallerRecents(anyInt()); + + final ActivityStarter starter = prepareStarter(0 /* flags */); + + starter.setReason("testAddToTaskListOnActivityStart") + .execute(); + + verify(recentTasks, times(1)).add(any()); + } } |