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

Commit 37ff5d90 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Wake up dream after resuming the moving to front task

Otherwise an activity with turn-screen-on flag cannot take effect
and receive new intent when launching it under dreaming. It will
become normal after the second try.

Because currentLaunchCanTurnScreenOn will be false after relayout
(WS#prepareWindowToDisplayDuringRelayout), then canTurnScreenOn()
will be false before calling resumeTargetRootTaskIfNeeded(), then
wakeUp is not called so the screen doesn't turn on and the dream
activity is still on top.

Fixes: 257533814
Test: ActivityStarterTests#testRecycleTaskWakeUpWhenDreaming
Change-Id: I457a7104068a57b010507a776094b2f354b6450a
parent 8d6647d4
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -2247,12 +2247,6 @@ class ActivityStarter {
                ? targetTask.getTopNonFinishingActivity()
                : targetTaskTop;

        // At this point we are certain we want the task moved to the front. If we need to dismiss
        // any other always-on-top root tasks, now is the time to do it.
        if (targetTaskTop.canTurnScreenOn() && mService.isDreaming()) {
            targetTaskTop.mTaskSupervisor.wakeUp("recycleTask#turnScreenOnFlag");
        }

        if (mMovedToFront) {
            // We moved the task to front, use starting window to hide initial drawn delay.
            targetTaskTop.showStartingWindow(true /* taskSwitch */);
@@ -2264,6 +2258,12 @@ class ActivityStarter {
        // And for paranoia, make sure we have correctly resumed the top activity.
        resumeTargetRootTaskIfNeeded();

        // This is moving an existing task to front. But since dream activity has a higher z-order
        // to cover normal activities, it needs the awakening event to be dismissed.
        if (mService.isDreaming() && targetTaskTop.canTurnScreenOn()) {
            targetTaskTop.mTaskSupervisor.wakeUp("recycleTask#turnScreenOnFlag");
        }

        mLastStartActivityRecord = targetTaskTop;
        return mMovedToFront ? START_TASK_TO_FRONT : START_DELIVERED_TO_TOP;
    }
+20 −0
Original line number Diff line number Diff line
@@ -1130,6 +1130,26 @@ public class ActivityStarterTests extends WindowTestsBase {
        assertThat(starter.mAddingToTask).isTrue();
    }

    @Test
    public void testRecycleTaskWakeUpWhenDreaming() {
        doNothing().when(mWm.mAtmService.mTaskSupervisor).wakeUp(anyString());
        doReturn(true).when(mWm.mAtmService).isDreaming();
        final ActivityStarter starter = prepareStarter(0 /* flags */);
        final ActivityRecord target = new ActivityBuilder(mAtm).setCreateTask(true).build();
        starter.mStartActivity = target;
        target.mVisibleRequested = false;
        target.setTurnScreenOn(true);
        // Assume the flag was consumed by relayout.
        target.setCurrentLaunchCanTurnScreenOn(false);
        startActivityInner(starter, target, null /* source */, null /* options */,
                null /* inTask */, null /* inTaskFragment */);
        // The flag should be set again when resuming (from recycleTask) the target as top.
        assertTrue(target.currentLaunchCanTurnScreenOn());
        // In real case, dream activity has a higher priority (TaskDisplayArea#getPriority) that
        // will be put at a higher z-order. So it relies on wakeUp() to be dismissed.
        verify(mWm.mAtmService.mTaskSupervisor).wakeUp(anyString());
    }

    @Test
    public void testTargetTaskInSplitScreen() {
        final ActivityStarter starter =