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

Commit b5e2ecda authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Simplify activity sleeping condition

It was confusing to check from root task. Since individual TaskFragment
can have resume-able activity, it should check the container visibility
rather than isFocusedRootTaskOnDisplay. So it won't miss the cases of
multiple-window mode.

Also reorder the cheaper conditions to front, so the methods can reduce
extra unnecessary execution.

Bug: 163976519
Flag: EXEMPT clean up legacy logic
Test: atest RootTaskTests#testShouldSleepActivities
Change-Id: Ib79aae0f445b6e7ecbb547a69f0eaa60357fe937
parent 03a6f8bf
Loading
Loading
Loading
Loading
+6 −7
Original line number Diff line number Diff line
@@ -4942,9 +4942,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        newIntents.add(intent);
    }

    final boolean isSleeping() {
        final Task rootTask = getRootTask();
        return rootTask != null ? rootTask.shouldSleepActivities() : mAtmService.isSleepingLocked();
    boolean isSleeping() {
        return task != null ? task.shouldSleepActivities() : mAtmService.isSleepingLocked();
    }

    /**
@@ -4968,7 +4967,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        final ReferrerIntent rintent = new ReferrerIntent(intent, getFilteredReferrer(referrer),
                callerToken);
        boolean unsent = true;
        final boolean isTopActivityWhileSleeping = isTopRunningActivity() && isSleeping();
        final boolean isTopActivityWhileSleeping = isSleeping() && isTopRunningActivity();

        // We want to immediately deliver the intent to the activity if:
        // - It is currently resumed or paused. i.e. it is currently visible to the user and we want
@@ -5835,7 +5834,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A

    void setState(State state, String reason) {
        ProtoLog.v(WM_DEBUG_STATES, "State movement: %s from:%s to:%s reason:%s",
                this, getState(), state, reason);
                this, mState, state, reason);

        if (state == mState) {
            // No need to do anything if state doesn't change.
@@ -6160,7 +6159,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        // Now for any activities that aren't visible to the user, make sure they no longer are
        // keeping the screen frozen.
        if (DEBUG_VISIBILITY) {
            Slog.v(TAG_VISIBILITY, "Making invisible: " + this + ", state=" + getState());
            Slog.v(TAG_VISIBILITY, "Making invisible: " + this + ", state=" + mState);
        }
        try {
            final boolean canEnterPictureInPicture = checkEnterPictureInPictureState(
@@ -6176,7 +6175,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            }
            setVisibility(false);

            switch (getState()) {
            switch (mState) {
                case STOPPING:
                case STOPPED:
                    // Reset the flag indicating that an app can enter picture-in-picture once the
+0 −20
Original line number Diff line number Diff line
@@ -6196,26 +6196,6 @@ class Task extends TaskFragment {
        ActivityOptions.abort(options);
    }

    boolean shouldSleepActivities() {
        final DisplayContent display = mDisplayContent;
        final boolean isKeyguardGoingAway = (mDisplayContent != null)
                ? mDisplayContent.isKeyguardGoingAway()
                : mRootWindowContainer.getDefaultDisplay().isKeyguardGoingAway();

        // Do not sleep activities in this root task if we're marked as focused and the keyguard
        // is in the process of going away.
        if (isKeyguardGoingAway && isFocusedRootTaskOnDisplay()
                // Avoid resuming activities on secondary displays since we don't want bubble
                // activities to be resumed while bubble is still collapsed.
                // TODO(b/113840485): Having keyguard going away state for secondary displays.
                && display != null
                && display.isDefaultDisplay) {
            return false;
        }

        return display != null ? display.isSleeping() : mAtmService.isSleepingLocked();
    }

    private Rect getRawBounds() {
        return super.getBounds();
    }
+16 −2
Original line number Diff line number Diff line
@@ -2145,8 +2145,22 @@ class TaskFragment extends WindowContainer<WindowContainer> {
    }

    boolean shouldSleepActivities() {
        final Task task = getRootTask();
        return task != null && task.shouldSleepActivities();
        final DisplayContent dc = mDisplayContent;
        if (dc == null) {
            return mAtmService.isSleepingLocked();
        }
        if (!dc.isSleeping()) {
            return false;
        }
        // In case the unlocking order is keyguard-going-away -> screen-turning-on (display is
        // sleeping by screen-off-token which may be notified to release from power manager's
        // thread), keep the activities resume-able to avoid extra activity lifecycle when
        // performing keyguard-going-away. This only applies to default display because currently
        // the per-display keyguard-going-away state is assigned from a global signal.
        if (!dc.isDefaultDisplay || !dc.isKeyguardGoingAway()) {
            return true;
        }
        return !shouldBeVisible(null /* starting */);
    }

    @Override
+21 −6
Original line number Diff line number Diff line
@@ -1260,25 +1260,40 @@ public class RootTaskTests extends WindowTestsBase {

    @Test
    public void testShouldSleepActivities() {
        final Task task = new TaskBuilder(mSupervisor).build();
        task.mDisplayContent = mock(DisplayContent.class);
        // When focused activity and keyguard is going away, we should not sleep regardless
        // of the display state, but keyguard-going-away should only take effects on default
        // display since there is no keyguard on secondary displays (yet).
        verifyShouldSleepActivities(true /* focusedRootTask */, true /*keyguardGoingAway*/,
        // display because the keyguard-going-away state of secondary displays are already the
        // same as default display.
        verifyShouldSleepActivities(task, true /* isVisibleTask */, true /* keyguardGoingAway */,
                true /* displaySleeping */, true /* isDefaultDisplay */, false /* expected */);
        verifyShouldSleepActivities(true /* focusedRootTask */, true /*keyguardGoingAway*/,
        verifyShouldSleepActivities(task, true /* isVisibleTask */, true /* keyguardGoingAway */,
                true /* displaySleeping */, false /* isDefaultDisplay */, true /* expected */);

        // When not the focused root task, defer to display sleeping state.
        verifyShouldSleepActivities(false /* focusedRootTask */, true /*keyguardGoingAway*/,
        verifyShouldSleepActivities(task, false /* isVisibleTask */, true /* keyguardGoingAway */,
                true /* displaySleeping */, true /* isDefaultDisplay */, true /* expected */);

        // If keyguard is going away, defer to the display sleeping state.
        verifyShouldSleepActivities(true /* focusedRootTask */, false /*keyguardGoingAway*/,
        verifyShouldSleepActivities(task, true /* isVisibleTask */, false /* keyguardGoingAway */,
                true /* displaySleeping */, true /* isDefaultDisplay */, true /* expected */);
        verifyShouldSleepActivities(true /* focusedRootTask */, false /*keyguardGoingAway*/,
        verifyShouldSleepActivities(task, true /* isVisibleTask */, false /* keyguardGoingAway */,
                false /* displaySleeping */, true /* isDefaultDisplay */, false /* expected */);
    }

    private static void verifyShouldSleepActivities(Task task, boolean isVisibleTask,
            boolean keyguardGoingAway, boolean displaySleeping, boolean isDefaultDisplay,
            boolean expected) {
        final DisplayContent display = task.mDisplayContent;
        display.isDefaultDisplay = isDefaultDisplay;
        doReturn(keyguardGoingAway).when(display).isKeyguardGoingAway();
        doReturn(displaySleeping).when(display).isSleeping();
        doReturn(isVisibleTask).when(task).shouldBeVisible(null /* starting */);

        assertEquals(expected, task.shouldSleepActivities());
    }

    @Test
    public void testNavigateUpTo() {
        final ActivityStartController controller = mock(ActivityStartController.class);