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

Commit 8b5c186d authored by Robert Horvath's avatar Robert Horvath
Browse files

When asleep, dismiss inattentive sleep warning, don't reschedule

In the PowerManagerService power state update method the inattentive
sleep warning was dismissed when the device wasn't awake.
This incorrectly also happened when the device was dreaming, dismissing
the warning only to show it immediately again, causing some flicker.
Also, the message triggering the warning to be shown and the device to
go to sleep was still rescheduled when the device was already asleep,
which is unnecessary.

Bug: 243491344
Test: atest PowerManagerServiceTest#testInattentiveSleep_warningStaysWhenDreaming
Test: atest PowerManagerServiceTest#testInattentiveSleep_warningNotShownWhenSleeping
Change-Id: Iaddf84b107a231467653dd98b46839579444a56a
parent 0c867c02
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -2963,7 +2963,8 @@ public final class PowerManagerService extends SystemService

            mHandler.removeMessages(MSG_ATTENTIVE_TIMEOUT);

            if (isBeingKeptFromInattentiveSleepLocked()) {
            if (getGlobalWakefulnessLocked() == WAKEFULNESS_ASLEEP
                    || isBeingKeptFromInattentiveSleepLocked()) {
                return;
            }

@@ -2995,7 +2996,7 @@ public final class PowerManagerService extends SystemService
            return false;
        }

        if (getGlobalWakefulnessLocked() != WAKEFULNESS_AWAKE) {
        if (getGlobalWakefulnessLocked() == WAKEFULNESS_ASLEEP) {
            mInattentiveSleepWarningOverlayController.dismiss(false);
            return true;
        } else if (attentiveTimeout < 0 || isBeingKeptFromInattentiveSleepLocked()
+34 −0
Original line number Diff line number Diff line
@@ -991,6 +991,40 @@ public class PowerManagerServiceTest {
        verify(mInattentiveSleepWarningControllerMock, atLeastOnce()).dismiss(false);
    }

    @Test
    public void testInattentiveSleep_warningStaysWhenDreaming() {
        setMinimumScreenOffTimeoutConfig(5);
        setAttentiveWarningDuration(70);
        setAttentiveTimeout(100);
        createService();
        startSystem();
        advanceTime(50);
        verify(mInattentiveSleepWarningControllerMock, atLeastOnce()).show();
        when(mInattentiveSleepWarningControllerMock.isShown()).thenReturn(true);

        forceDream();
        when(mDreamManagerInternalMock.isDreaming()).thenReturn(true);

        advanceTime(10);
        assertThat(mService.getGlobalWakefulnessLocked()).isEqualTo(WAKEFULNESS_DREAMING);
        verify(mInattentiveSleepWarningControllerMock, never()).dismiss(anyBoolean());
    }

    @Test
    public void testInattentiveSleep_warningNotShownWhenSleeping() {
        setMinimumScreenOffTimeoutConfig(5);
        setAttentiveWarningDuration(70);
        setAttentiveTimeout(100);
        createService();
        startSystem();

        advanceTime(10);
        forceSleep();

        advanceTime(50);
        verify(mInattentiveSleepWarningControllerMock, never()).show();
    }

    @Test
    public void testInattentiveSleep_noWarningShownIfInattentiveSleepDisabled() {
        setAttentiveTimeout(-1);