Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a96aac6c authored by wilsonshih's avatar wilsonshih
Browse files

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
parent 2a459678
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -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;
+15 −0
Original line number Diff line number Diff line
@@ -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)