diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index e16f3fc948ac2..0acab9cb74c56 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -4535,8 +4535,12 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A * @param activeActivity the activity that is active or just completed pause action. We won't * resume if this activity is active. */ - private boolean shouldPauseActivity(ActivityRecord activeActivity) { - return shouldMakeActive(activeActivity) && !isFocusable() && !isState(PAUSING, PAUSED); + @VisibleForTesting + boolean shouldPauseActivity(ActivityRecord activeActivity) { + return shouldMakeActive(activeActivity) && !isFocusable() && !isState(PAUSING, PAUSED) + // We will only allow pausing if results is null, otherwise it will cause this + // activity to resume before getting result + && (results == null); } /** @@ -4606,9 +4610,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } // Check if activity above is finishing now and this one becomes the topmost in task. final ActivityRecord activityAbove = task.getChildAt(positionInTask + 1); - if (activityAbove.finishing && results == null) { - // We will only allow making active if activity above wasn't launched for result. - // Otherwise it will cause this activity to resume before getting result. + if (activityAbove.finishing) { return true; } return false; diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java index a2e423369fcd6..b1b386b3f4899 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java @@ -66,6 +66,7 @@ import android.app.servertransaction.ActivityConfigurationChangeItem; import android.app.servertransaction.ClientTransaction; import android.app.servertransaction.PauseActivityItem; import android.content.ComponentName; +import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.content.res.Resources; @@ -400,6 +401,20 @@ public class ActivityRecordTests extends ActivityTestsBase { assertEquals(false, mActivity.shouldResumeActivity(null /* activeActivity */)); } + @Test + public void testShouldResumeOrPauseWithResults() { + mActivity.setState(ActivityStack.ActivityState.STOPPED, "Testing"); + spyOn(mStack); + + ActivityRecord topActivity = new ActivityBuilder(mService).setTask(mTask).build(); + mActivity.addResultLocked(topActivity, "resultWho", 0, 0, new Intent()); + topActivity.finishing = true; + + doReturn(STACK_VISIBILITY_VISIBLE).when(mStack).getVisibility(null); + assertEquals(true, mActivity.shouldResumeActivity(null /* activeActivity */)); + assertEquals(false, mActivity.shouldPauseActivity(null /*activeActivity */)); + } + @Test public void testPushConfigurationWhenLaunchTaskBehind() throws Exception { mActivity = new ActivityBuilder(mService)