From a96aac6c2ab3a6fc0e452518d37d8ccd7ddcc6bc Mon Sep 17 00:00:00 2001 From: wilsonshih Date: Mon, 18 Nov 2019 14:53:34 +0800 Subject: [PATCH] Allow to resume activity when there are results. Relaunch with results should be allowed when target lifecycle is resumed. Add test for shouldResume/shouldPause when results existing. Bug: 144422233 Test: atest android.server.wm.lifecycle Test: atest WmTests:ActivityRecordTests Change-Id: I687b0a3488ca969302b22628449fc29c7fc34a9d --- .../com/android/server/wm/ActivityRecord.java | 12 +++++++----- .../android/server/wm/ActivityRecordTests.java | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index ba8212b5f8abe..ee7efe3625709 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -4531,8 +4531,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); } /** @@ -4602,9 +4606,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)