Loading packages/SystemUI/src/com/android/systemui/doze/DozeLog.java +1 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ public class DozeLog { private static final int PULSE_REASONS = 5; public static final int PULSE_REASON_NONE = -1; public static final int PULSE_REASON_INTENT = 0; public static final int PULSE_REASON_NOTIFICATION = 1; public static final int PULSE_REASON_SENSOR_SIGMOTION = 2; Loading packages/SystemUI/src/com/android/systemui/doze/DozeMachine.java +42 −3 Original line number Diff line number Diff line Loading @@ -106,6 +106,7 @@ public class DozeMachine { private final ArrayList<State> mQueuedRequests = new ArrayList<>(); private State mState = State.UNINITIALIZED; private int mPulseReason; private boolean mWakeLockHeldForCurrentState = false; public DozeMachine(Service service, AmbientDisplayConfiguration config, Loading Loading @@ -133,6 +134,20 @@ public class DozeMachine { */ @MainThread public void requestState(State requestedState) { Preconditions.checkArgument(requestedState != State.DOZE_REQUEST_PULSE); requestState(requestedState, DozeLog.PULSE_REASON_NONE); } @MainThread public void requestPulse(int pulseReason) { // Must not be called during a transition. There's no inherent problem with that, // but there's currently no need to execute from a transition and it simplifies the // code to not have to worry about keeping the pulseReason in mQueuedRequests. Preconditions.checkState(!isExecutingTransition()); requestState(State.DOZE_REQUEST_PULSE, pulseReason); } private void requestState(State requestedState, int pulseReason) { Assert.isMainThread(); if (DEBUG) { Log.i(TAG, "request: current=" + mState + " req=" + requestedState, Loading @@ -146,7 +161,7 @@ public class DozeMachine { for (int i = 0; i < mQueuedRequests.size(); i++) { // Transitions in Parts can call back into requestState, which will // cause mQueuedRequests to grow. transitionTo(mQueuedRequests.get(i)); transitionTo(mQueuedRequests.get(i), pulseReason); } mQueuedRequests.clear(); mWakeLock.release(); Loading @@ -165,6 +180,20 @@ public class DozeMachine { return mState; } /** * @return the current pulse reason. * * This is only valid if the machine is currently in one of the pulse states. */ @MainThread public int getPulseReason() { Assert.isMainThread(); Preconditions.checkState(mState == State.DOZE_REQUEST_PULSE || mState == State.DOZE_PULSING || mState == State.DOZE_PULSE_DONE, "must be in pulsing state, but is " + mState); return mPulseReason; } /** Requests the PowerManager to wake up now. */ public void wakeUp() { mDozeService.requestWakeUp(); Loading @@ -174,7 +203,7 @@ public class DozeMachine { return !mQueuedRequests.isEmpty(); } private void transitionTo(State requestedState) { private void transitionTo(State requestedState, int pulseReason) { State newState = transitionPolicy(requestedState); if (DEBUG) { Loading @@ -190,6 +219,7 @@ public class DozeMachine { State oldState = mState; mState = newState; updatePulseReason(newState, oldState, pulseReason); performTransitionOnComponents(oldState, newState); updateScreenState(newState); updateWakeLockState(newState); Loading @@ -197,6 +227,14 @@ public class DozeMachine { resolveIntermediateState(newState); } private void updatePulseReason(State newState, State oldState, int pulseReason) { if (newState == State.DOZE_REQUEST_PULSE) { mPulseReason = pulseReason; } else if (oldState == State.DOZE_PULSE_DONE) { mPulseReason = DozeLog.PULSE_REASON_NONE; } } private void performTransitionOnComponents(State oldState, State newState) { for (Part p : mParts) { p.transitionTo(oldState, newState); Loading Loading @@ -280,7 +318,8 @@ public class DozeMachine { case INITIALIZED: case DOZE_PULSE_DONE: transitionTo(mConfig.alwaysOnEnabled(UserHandle.USER_CURRENT) ? DozeMachine.State.DOZE_AOD : DozeMachine.State.DOZE); ? DozeMachine.State.DOZE_AOD : DozeMachine.State.DOZE, DozeLog.PULSE_REASON_NONE); break; default: break; Loading packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java +1 −1 Original line number Diff line number Diff line Loading @@ -227,7 +227,7 @@ public class DozeTriggers implements DozeMachine.Part { mDozeHost.isPulsingBlocked()); return; } mMachine.requestState(DozeMachine.State.DOZE_REQUEST_PULSE); mMachine.requestPulse(reason); } @Override Loading packages/SystemUI/src/com/android/systemui/doze/DozeUi.java +1 −1 Original line number Diff line number Diff line Loading @@ -83,7 +83,7 @@ public class DozeUi implements DozeMachine.Part { unscheduleTimeTick(); break; case DOZE_REQUEST_PULSE: pulseWhileDozing(DozeLog.PULSE_REASON_NOTIFICATION /* TODO */); pulseWhileDozing(mMachine.getPulseReason()); break; case DOZE_PULSE_DONE: mHost.abortPulsing(); Loading packages/SystemUI/tests/src/com/android/systemui/doze/DozeMachineTest.java +42 −11 Original line number Diff line number Diff line Loading @@ -106,7 +106,7 @@ public class DozeMachineTest { public void testPulseDone_goesToDoze() { when(mConfigMock.alwaysOnEnabled(anyInt())).thenReturn(false); mMachine.requestState(INITIALIZED); mMachine.requestState(DOZE_REQUEST_PULSE); mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); mMachine.requestState(DOZE_PULSING); mMachine.requestState(DOZE_PULSE_DONE); Loading @@ -119,7 +119,7 @@ public class DozeMachineTest { public void testPulseDone_goesToAoD() { when(mConfigMock.alwaysOnEnabled(anyInt())).thenReturn(true); mMachine.requestState(INITIALIZED); mMachine.requestState(DOZE_REQUEST_PULSE); mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); mMachine.requestState(DOZE_PULSING); mMachine.requestState(DOZE_PULSE_DONE); Loading Loading @@ -163,7 +163,7 @@ public class DozeMachineTest { public void testWakeLock_heldInPulseStates() { mMachine.requestState(INITIALIZED); mMachine.requestState(DOZE_REQUEST_PULSE); mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); assertTrue(mWakeLockFake.isHeld()); mMachine.requestState(DOZE_PULSING); Loading @@ -186,7 +186,7 @@ public class DozeMachineTest { mMachine.requestState(INITIALIZED); mMachine.requestState(DOZE); mMachine.requestState(DOZE_REQUEST_PULSE); mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); mMachine.requestState(DOZE_PULSING); mMachine.requestState(DOZE_PULSE_DONE); Loading @@ -198,9 +198,9 @@ public class DozeMachineTest { mMachine.requestState(INITIALIZED); mMachine.requestState(DOZE); mMachine.requestState(DOZE_REQUEST_PULSE); mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); mMachine.requestState(DOZE_PULSING); mMachine.requestState(DOZE_REQUEST_PULSE); mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); mMachine.requestState(DOZE_PULSE_DONE); } Loading @@ -209,7 +209,7 @@ public class DozeMachineTest { mMachine.requestState(INITIALIZED); mMachine.requestState(DOZE); mMachine.requestState(DOZE_REQUEST_PULSE); mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); mMachine.requestState(DOZE_PULSE_DONE); } Loading @@ -235,7 +235,7 @@ public class DozeMachineTest { public void testScreen_onInPulse() { mMachine.requestState(INITIALIZED); mMachine.requestState(DOZE_REQUEST_PULSE); mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); mMachine.requestState(DOZE_PULSING); assertEquals(Display.STATE_DOZE, mServiceFake.screenState); Loading @@ -246,7 +246,7 @@ public class DozeMachineTest { mMachine.requestState(INITIALIZED); mMachine.requestState(DOZE); mMachine.requestState(DOZE_REQUEST_PULSE); mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); assertEquals(Display.STATE_OFF, mServiceFake.screenState); } Loading @@ -256,7 +256,7 @@ public class DozeMachineTest { mMachine.requestState(INITIALIZED); mMachine.requestState(DOZE_AOD); mMachine.requestState(DOZE_REQUEST_PULSE); mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); assertEquals(Display.STATE_DOZE, mServiceFake.screenState); } Loading @@ -270,11 +270,42 @@ public class DozeMachineTest { return null; }).when(mPartMock).transitionTo(any(), eq(DOZE_REQUEST_PULSE)); mMachine.requestState(DOZE_REQUEST_PULSE); mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); assertEquals(DOZE_PULSING, mMachine.getState()); } @Test public void testPulseReason_getMatchesRequest() { mMachine.requestState(INITIALIZED); mMachine.requestState(DOZE); mMachine.requestPulse(DozeLog.PULSE_REASON_SENSOR_DOUBLE_TAP); assertEquals(DozeLog.PULSE_REASON_SENSOR_DOUBLE_TAP, mMachine.getPulseReason()); } @Test public void testPulseReason_getFromTransition() { mMachine.requestState(INITIALIZED); mMachine.requestState(DOZE); doAnswer(inv -> { DozeMachine.State newState = inv.getArgument(1); if (newState == DOZE_REQUEST_PULSE || newState == DOZE_PULSING || newState == DOZE_PULSE_DONE) { assertEquals(DozeLog.PULSE_REASON_NOTIFICATION, mMachine.getPulseReason()); } else { assertTrue("unexpected state " + newState, newState == DOZE || newState == DOZE_AOD); } return null; }).when(mPartMock).transitionTo(any(), any()); mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); mMachine.requestState(DOZE_PULSING); mMachine.requestState(DOZE_PULSE_DONE); } @Test public void testWakeUp_wakesUp() { mMachine.wakeUp(); Loading Loading
packages/SystemUI/src/com/android/systemui/doze/DozeLog.java +1 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ public class DozeLog { private static final int PULSE_REASONS = 5; public static final int PULSE_REASON_NONE = -1; public static final int PULSE_REASON_INTENT = 0; public static final int PULSE_REASON_NOTIFICATION = 1; public static final int PULSE_REASON_SENSOR_SIGMOTION = 2; Loading
packages/SystemUI/src/com/android/systemui/doze/DozeMachine.java +42 −3 Original line number Diff line number Diff line Loading @@ -106,6 +106,7 @@ public class DozeMachine { private final ArrayList<State> mQueuedRequests = new ArrayList<>(); private State mState = State.UNINITIALIZED; private int mPulseReason; private boolean mWakeLockHeldForCurrentState = false; public DozeMachine(Service service, AmbientDisplayConfiguration config, Loading Loading @@ -133,6 +134,20 @@ public class DozeMachine { */ @MainThread public void requestState(State requestedState) { Preconditions.checkArgument(requestedState != State.DOZE_REQUEST_PULSE); requestState(requestedState, DozeLog.PULSE_REASON_NONE); } @MainThread public void requestPulse(int pulseReason) { // Must not be called during a transition. There's no inherent problem with that, // but there's currently no need to execute from a transition and it simplifies the // code to not have to worry about keeping the pulseReason in mQueuedRequests. Preconditions.checkState(!isExecutingTransition()); requestState(State.DOZE_REQUEST_PULSE, pulseReason); } private void requestState(State requestedState, int pulseReason) { Assert.isMainThread(); if (DEBUG) { Log.i(TAG, "request: current=" + mState + " req=" + requestedState, Loading @@ -146,7 +161,7 @@ public class DozeMachine { for (int i = 0; i < mQueuedRequests.size(); i++) { // Transitions in Parts can call back into requestState, which will // cause mQueuedRequests to grow. transitionTo(mQueuedRequests.get(i)); transitionTo(mQueuedRequests.get(i), pulseReason); } mQueuedRequests.clear(); mWakeLock.release(); Loading @@ -165,6 +180,20 @@ public class DozeMachine { return mState; } /** * @return the current pulse reason. * * This is only valid if the machine is currently in one of the pulse states. */ @MainThread public int getPulseReason() { Assert.isMainThread(); Preconditions.checkState(mState == State.DOZE_REQUEST_PULSE || mState == State.DOZE_PULSING || mState == State.DOZE_PULSE_DONE, "must be in pulsing state, but is " + mState); return mPulseReason; } /** Requests the PowerManager to wake up now. */ public void wakeUp() { mDozeService.requestWakeUp(); Loading @@ -174,7 +203,7 @@ public class DozeMachine { return !mQueuedRequests.isEmpty(); } private void transitionTo(State requestedState) { private void transitionTo(State requestedState, int pulseReason) { State newState = transitionPolicy(requestedState); if (DEBUG) { Loading @@ -190,6 +219,7 @@ public class DozeMachine { State oldState = mState; mState = newState; updatePulseReason(newState, oldState, pulseReason); performTransitionOnComponents(oldState, newState); updateScreenState(newState); updateWakeLockState(newState); Loading @@ -197,6 +227,14 @@ public class DozeMachine { resolveIntermediateState(newState); } private void updatePulseReason(State newState, State oldState, int pulseReason) { if (newState == State.DOZE_REQUEST_PULSE) { mPulseReason = pulseReason; } else if (oldState == State.DOZE_PULSE_DONE) { mPulseReason = DozeLog.PULSE_REASON_NONE; } } private void performTransitionOnComponents(State oldState, State newState) { for (Part p : mParts) { p.transitionTo(oldState, newState); Loading Loading @@ -280,7 +318,8 @@ public class DozeMachine { case INITIALIZED: case DOZE_PULSE_DONE: transitionTo(mConfig.alwaysOnEnabled(UserHandle.USER_CURRENT) ? DozeMachine.State.DOZE_AOD : DozeMachine.State.DOZE); ? DozeMachine.State.DOZE_AOD : DozeMachine.State.DOZE, DozeLog.PULSE_REASON_NONE); break; default: break; Loading
packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java +1 −1 Original line number Diff line number Diff line Loading @@ -227,7 +227,7 @@ public class DozeTriggers implements DozeMachine.Part { mDozeHost.isPulsingBlocked()); return; } mMachine.requestState(DozeMachine.State.DOZE_REQUEST_PULSE); mMachine.requestPulse(reason); } @Override Loading
packages/SystemUI/src/com/android/systemui/doze/DozeUi.java +1 −1 Original line number Diff line number Diff line Loading @@ -83,7 +83,7 @@ public class DozeUi implements DozeMachine.Part { unscheduleTimeTick(); break; case DOZE_REQUEST_PULSE: pulseWhileDozing(DozeLog.PULSE_REASON_NOTIFICATION /* TODO */); pulseWhileDozing(mMachine.getPulseReason()); break; case DOZE_PULSE_DONE: mHost.abortPulsing(); Loading
packages/SystemUI/tests/src/com/android/systemui/doze/DozeMachineTest.java +42 −11 Original line number Diff line number Diff line Loading @@ -106,7 +106,7 @@ public class DozeMachineTest { public void testPulseDone_goesToDoze() { when(mConfigMock.alwaysOnEnabled(anyInt())).thenReturn(false); mMachine.requestState(INITIALIZED); mMachine.requestState(DOZE_REQUEST_PULSE); mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); mMachine.requestState(DOZE_PULSING); mMachine.requestState(DOZE_PULSE_DONE); Loading @@ -119,7 +119,7 @@ public class DozeMachineTest { public void testPulseDone_goesToAoD() { when(mConfigMock.alwaysOnEnabled(anyInt())).thenReturn(true); mMachine.requestState(INITIALIZED); mMachine.requestState(DOZE_REQUEST_PULSE); mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); mMachine.requestState(DOZE_PULSING); mMachine.requestState(DOZE_PULSE_DONE); Loading Loading @@ -163,7 +163,7 @@ public class DozeMachineTest { public void testWakeLock_heldInPulseStates() { mMachine.requestState(INITIALIZED); mMachine.requestState(DOZE_REQUEST_PULSE); mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); assertTrue(mWakeLockFake.isHeld()); mMachine.requestState(DOZE_PULSING); Loading @@ -186,7 +186,7 @@ public class DozeMachineTest { mMachine.requestState(INITIALIZED); mMachine.requestState(DOZE); mMachine.requestState(DOZE_REQUEST_PULSE); mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); mMachine.requestState(DOZE_PULSING); mMachine.requestState(DOZE_PULSE_DONE); Loading @@ -198,9 +198,9 @@ public class DozeMachineTest { mMachine.requestState(INITIALIZED); mMachine.requestState(DOZE); mMachine.requestState(DOZE_REQUEST_PULSE); mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); mMachine.requestState(DOZE_PULSING); mMachine.requestState(DOZE_REQUEST_PULSE); mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); mMachine.requestState(DOZE_PULSE_DONE); } Loading @@ -209,7 +209,7 @@ public class DozeMachineTest { mMachine.requestState(INITIALIZED); mMachine.requestState(DOZE); mMachine.requestState(DOZE_REQUEST_PULSE); mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); mMachine.requestState(DOZE_PULSE_DONE); } Loading @@ -235,7 +235,7 @@ public class DozeMachineTest { public void testScreen_onInPulse() { mMachine.requestState(INITIALIZED); mMachine.requestState(DOZE_REQUEST_PULSE); mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); mMachine.requestState(DOZE_PULSING); assertEquals(Display.STATE_DOZE, mServiceFake.screenState); Loading @@ -246,7 +246,7 @@ public class DozeMachineTest { mMachine.requestState(INITIALIZED); mMachine.requestState(DOZE); mMachine.requestState(DOZE_REQUEST_PULSE); mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); assertEquals(Display.STATE_OFF, mServiceFake.screenState); } Loading @@ -256,7 +256,7 @@ public class DozeMachineTest { mMachine.requestState(INITIALIZED); mMachine.requestState(DOZE_AOD); mMachine.requestState(DOZE_REQUEST_PULSE); mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); assertEquals(Display.STATE_DOZE, mServiceFake.screenState); } Loading @@ -270,11 +270,42 @@ public class DozeMachineTest { return null; }).when(mPartMock).transitionTo(any(), eq(DOZE_REQUEST_PULSE)); mMachine.requestState(DOZE_REQUEST_PULSE); mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); assertEquals(DOZE_PULSING, mMachine.getState()); } @Test public void testPulseReason_getMatchesRequest() { mMachine.requestState(INITIALIZED); mMachine.requestState(DOZE); mMachine.requestPulse(DozeLog.PULSE_REASON_SENSOR_DOUBLE_TAP); assertEquals(DozeLog.PULSE_REASON_SENSOR_DOUBLE_TAP, mMachine.getPulseReason()); } @Test public void testPulseReason_getFromTransition() { mMachine.requestState(INITIALIZED); mMachine.requestState(DOZE); doAnswer(inv -> { DozeMachine.State newState = inv.getArgument(1); if (newState == DOZE_REQUEST_PULSE || newState == DOZE_PULSING || newState == DOZE_PULSE_DONE) { assertEquals(DozeLog.PULSE_REASON_NOTIFICATION, mMachine.getPulseReason()); } else { assertTrue("unexpected state " + newState, newState == DOZE || newState == DOZE_AOD); } return null; }).when(mPartMock).transitionTo(any(), any()); mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); mMachine.requestState(DOZE_PULSING); mMachine.requestState(DOZE_PULSE_DONE); } @Test public void testWakeUp_wakesUp() { mMachine.wakeUp(); Loading