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

Commit 1e5f889d authored by Robert Horvath's avatar Robert Horvath Committed by Android (Google) Code Review
Browse files

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

parents 9948c855 8b5c186d
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -2953,7 +2953,8 @@ public final class PowerManagerService extends SystemService

            mHandler.removeMessages(MSG_ATTENTIVE_TIMEOUT);

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

@@ -2985,7 +2986,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);