Loading packages/SystemUI/src/com/android/systemui/doze/DozeScreenBrightness.java +5 −2 Original line number Diff line number Diff line Loading @@ -89,6 +89,7 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi private boolean mPaused = false; private boolean mScreenOff = false; private int mLastSensorValue = -1; private DozeMachine.State mState = DozeMachine.State.UNINITIALIZED; /** * Debug value used for emulating various display brightness buckets: Loading Loading @@ -135,6 +136,7 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi @Override public void transitionTo(DozeMachine.State oldState, DozeMachine.State newState) { mState = newState; switch (newState) { case INITIALIZED: resetBrightnessToDefault(); Loading Loading @@ -262,8 +264,9 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi */ private int clampToDimBrightnessForScreenOff(int brightness) { final boolean screenTurningOff = mDozeParameters.shouldClampToDimBrightness() || mWakefulnessLifecycle.getWakefulness() == WAKEFULNESS_GOING_TO_SLEEP; (mDozeParameters.shouldClampToDimBrightness() || mWakefulnessLifecycle.getWakefulness() == WAKEFULNESS_GOING_TO_SLEEP) && mState == DozeMachine.State.INITIALIZED; if (screenTurningOff && mWakefulnessLifecycle.getLastSleepReason() == GO_TO_SLEEP_REASON_TIMEOUT) { return Math.max( Loading packages/SystemUI/tests/src/com/android/systemui/doze/DozeScreenBrightnessTest.java +8 −8 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import static com.android.systemui.doze.DozeMachine.State.DOZE_REQUEST_PULSE; import static com.android.systemui.doze.DozeMachine.State.FINISH; import static com.android.systemui.doze.DozeMachine.State.INITIALIZED; import static com.android.systemui.doze.DozeMachine.State.UNINITIALIZED; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotSame; Loading Loading @@ -468,37 +469,39 @@ public class DozeScreenBrightnessTest extends SysuiTestCase { public void transitionToDoze_shouldClampBrightness_afterTimeout_clampsToDim() { when(mWakefulnessLifecycle.getLastSleepReason()).thenReturn( PowerManager.GO_TO_SLEEP_REASON_TIMEOUT); when(mDozeParameters.shouldControlUnlockedScreenOff()).thenReturn(true); when(mDozeParameters.shouldClampToDimBrightness()).thenReturn(true); mScreen.transitionTo(UNINITIALIZED, INITIALIZED); mScreen.transitionTo(INITIALIZED, DOZE); // If we're dozing after a timeout, and playing the unlocked screen animation, we should // stay at or below dim brightness, because the screen dims just before timeout. assertTrue(mServiceFake.screenBrightness <= DIM_BRIGHTNESS); // Once we transition to Doze, use the doze brightness mScreen.transitionTo(INITIALIZED, DOZE); assertEquals(mServiceFake.screenBrightness, DEFAULT_BRIGHTNESS); } @Test public void transitionToDoze_shouldClampBrightness_notAfterTimeout_doesNotClampToDim() { when(mWakefulnessLifecycle.getLastSleepReason()).thenReturn( PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON); when(mDozeParameters.shouldControlUnlockedScreenOff()).thenReturn(true); when(mDozeParameters.shouldClampToDimBrightness()).thenReturn(true); mScreen.transitionTo(UNINITIALIZED, INITIALIZED); mScreen.transitionTo(INITIALIZED, DOZE); // If we're playing the unlocked screen off animation after a power button press, we should // leave the brightness alone. assertEquals(mServiceFake.screenBrightness, DEFAULT_BRIGHTNESS); mScreen.transitionTo(INITIALIZED, DOZE); assertEquals(mServiceFake.screenBrightness, DEFAULT_BRIGHTNESS); } @Test public void transitionToDoze_noClampBrightness_afterTimeout_noScreenOff_doesNotClampToDim() { when(mWakefulnessLifecycle.getLastSleepReason()).thenReturn( PowerManager.GO_TO_SLEEP_REASON_TIMEOUT); when(mDozeParameters.shouldControlUnlockedScreenOff()).thenReturn(false); when(mDozeParameters.shouldClampToDimBrightness()).thenReturn(false); mScreen.transitionTo(UNINITIALIZED, INITIALIZED); Loading @@ -514,11 +517,9 @@ public class DozeScreenBrightnessTest extends SysuiTestCase { PowerManager.GO_TO_SLEEP_REASON_TIMEOUT); when(mWakefulnessLifecycle.getWakefulness()).thenReturn( WakefulnessLifecycle.WAKEFULNESS_GOING_TO_SLEEP); when(mDozeParameters.shouldControlUnlockedScreenOff()).thenReturn(false); when(mDozeParameters.shouldClampToDimBrightness()).thenReturn(false); mScreen.transitionTo(UNINITIALIZED, INITIALIZED); mScreen.transitionTo(INITIALIZED, DOZE); assertTrue(mServiceFake.screenBrightness <= DIM_BRIGHTNESS); } Loading @@ -529,7 +530,6 @@ public class DozeScreenBrightnessTest extends SysuiTestCase { PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON); when(mWakefulnessLifecycle.getWakefulness()).thenReturn( WakefulnessLifecycle.WAKEFULNESS_GOING_TO_SLEEP); when(mDozeParameters.shouldControlUnlockedScreenOff()).thenReturn(false); when(mDozeParameters.shouldClampToDimBrightness()).thenReturn(false); mScreen.transitionTo(UNINITIALIZED, INITIALIZED); Loading Loading
packages/SystemUI/src/com/android/systemui/doze/DozeScreenBrightness.java +5 −2 Original line number Diff line number Diff line Loading @@ -89,6 +89,7 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi private boolean mPaused = false; private boolean mScreenOff = false; private int mLastSensorValue = -1; private DozeMachine.State mState = DozeMachine.State.UNINITIALIZED; /** * Debug value used for emulating various display brightness buckets: Loading Loading @@ -135,6 +136,7 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi @Override public void transitionTo(DozeMachine.State oldState, DozeMachine.State newState) { mState = newState; switch (newState) { case INITIALIZED: resetBrightnessToDefault(); Loading Loading @@ -262,8 +264,9 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi */ private int clampToDimBrightnessForScreenOff(int brightness) { final boolean screenTurningOff = mDozeParameters.shouldClampToDimBrightness() || mWakefulnessLifecycle.getWakefulness() == WAKEFULNESS_GOING_TO_SLEEP; (mDozeParameters.shouldClampToDimBrightness() || mWakefulnessLifecycle.getWakefulness() == WAKEFULNESS_GOING_TO_SLEEP) && mState == DozeMachine.State.INITIALIZED; if (screenTurningOff && mWakefulnessLifecycle.getLastSleepReason() == GO_TO_SLEEP_REASON_TIMEOUT) { return Math.max( Loading
packages/SystemUI/tests/src/com/android/systemui/doze/DozeScreenBrightnessTest.java +8 −8 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import static com.android.systemui.doze.DozeMachine.State.DOZE_REQUEST_PULSE; import static com.android.systemui.doze.DozeMachine.State.FINISH; import static com.android.systemui.doze.DozeMachine.State.INITIALIZED; import static com.android.systemui.doze.DozeMachine.State.UNINITIALIZED; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotSame; Loading Loading @@ -468,37 +469,39 @@ public class DozeScreenBrightnessTest extends SysuiTestCase { public void transitionToDoze_shouldClampBrightness_afterTimeout_clampsToDim() { when(mWakefulnessLifecycle.getLastSleepReason()).thenReturn( PowerManager.GO_TO_SLEEP_REASON_TIMEOUT); when(mDozeParameters.shouldControlUnlockedScreenOff()).thenReturn(true); when(mDozeParameters.shouldClampToDimBrightness()).thenReturn(true); mScreen.transitionTo(UNINITIALIZED, INITIALIZED); mScreen.transitionTo(INITIALIZED, DOZE); // If we're dozing after a timeout, and playing the unlocked screen animation, we should // stay at or below dim brightness, because the screen dims just before timeout. assertTrue(mServiceFake.screenBrightness <= DIM_BRIGHTNESS); // Once we transition to Doze, use the doze brightness mScreen.transitionTo(INITIALIZED, DOZE); assertEquals(mServiceFake.screenBrightness, DEFAULT_BRIGHTNESS); } @Test public void transitionToDoze_shouldClampBrightness_notAfterTimeout_doesNotClampToDim() { when(mWakefulnessLifecycle.getLastSleepReason()).thenReturn( PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON); when(mDozeParameters.shouldControlUnlockedScreenOff()).thenReturn(true); when(mDozeParameters.shouldClampToDimBrightness()).thenReturn(true); mScreen.transitionTo(UNINITIALIZED, INITIALIZED); mScreen.transitionTo(INITIALIZED, DOZE); // If we're playing the unlocked screen off animation after a power button press, we should // leave the brightness alone. assertEquals(mServiceFake.screenBrightness, DEFAULT_BRIGHTNESS); mScreen.transitionTo(INITIALIZED, DOZE); assertEquals(mServiceFake.screenBrightness, DEFAULT_BRIGHTNESS); } @Test public void transitionToDoze_noClampBrightness_afterTimeout_noScreenOff_doesNotClampToDim() { when(mWakefulnessLifecycle.getLastSleepReason()).thenReturn( PowerManager.GO_TO_SLEEP_REASON_TIMEOUT); when(mDozeParameters.shouldControlUnlockedScreenOff()).thenReturn(false); when(mDozeParameters.shouldClampToDimBrightness()).thenReturn(false); mScreen.transitionTo(UNINITIALIZED, INITIALIZED); Loading @@ -514,11 +517,9 @@ public class DozeScreenBrightnessTest extends SysuiTestCase { PowerManager.GO_TO_SLEEP_REASON_TIMEOUT); when(mWakefulnessLifecycle.getWakefulness()).thenReturn( WakefulnessLifecycle.WAKEFULNESS_GOING_TO_SLEEP); when(mDozeParameters.shouldControlUnlockedScreenOff()).thenReturn(false); when(mDozeParameters.shouldClampToDimBrightness()).thenReturn(false); mScreen.transitionTo(UNINITIALIZED, INITIALIZED); mScreen.transitionTo(INITIALIZED, DOZE); assertTrue(mServiceFake.screenBrightness <= DIM_BRIGHTNESS); } Loading @@ -529,7 +530,6 @@ public class DozeScreenBrightnessTest extends SysuiTestCase { PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON); when(mWakefulnessLifecycle.getWakefulness()).thenReturn( WakefulnessLifecycle.WAKEFULNESS_GOING_TO_SLEEP); when(mDozeParameters.shouldControlUnlockedScreenOff()).thenReturn(false); when(mDozeParameters.shouldClampToDimBrightness()).thenReturn(false); mScreen.transitionTo(UNINITIALIZED, INITIALIZED); Loading