From 382419b870c0422dc6163d4808557d8d4671d6c1 Mon Sep 17 00:00:00 2001 From: Louis Chang Date: Thu, 3 Oct 2019 21:43:38 +0800 Subject: [PATCH] Fix AppTaskTests#testStartActivityInTask_NewTask failure We shouldn't add new activity instance on top of the given task while brought the task to front. Bug: 140748518 Test: atest AppTaskTests Change-Id: I917c6549f6c0cf41a9e3ca2f8756a76592cc6742 --- .../android/server/wm/ActivityStarter.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityStarter.java b/services/core/java/com/android/server/wm/ActivityStarter.java index 1a8000636974c..bdaded4203f93 100644 --- a/services/core/java/com/android/server/wm/ActivityStarter.java +++ b/services/core/java/com/android/server/wm/ActivityStarter.java @@ -1907,14 +1907,17 @@ class ActivityStarter { mAddingToTask = true; } } else if (mStartActivity.mActivityComponent.equals(targetTask.realActivity)) { - // In this case the top activity on the task is the same as the one being launched, - // so we take that as a request to bring the task to the foreground. If the top - // activity in the task is the root activity, deliver this new intent to it if it - // desires. - if (((mLaunchFlags & FLAG_ACTIVITY_SINGLE_TOP) != 0 - || LAUNCH_SINGLE_TOP == mLaunchMode) - && targetTaskTop.mActivityComponent.equals( - mStartActivity.mActivityComponent) && mStartActivity.resultTo == null) { + if (targetTask == mInTask) { + // In this case we are bringing up an existing activity from a recent task. We + // don't need to add a new activity instance on top. + } else if (((mLaunchFlags & FLAG_ACTIVITY_SINGLE_TOP) != 0 + || LAUNCH_SINGLE_TOP == mLaunchMode) + && targetTaskTop.mActivityComponent.equals(mStartActivity.mActivityComponent) + && mStartActivity.resultTo == null) { + // In this case the top activity on the task is the same as the one being launched, + // so we take that as a request to bring the task to the foreground. If the top + // activity in the task is the root activity, deliver this new intent to it if it + // desires. if (targetTaskTop.isRootOfTask()) { targetTaskTop.getTaskRecord().setIntent(mStartActivity); }