Merge "AOD: Pass through pulse reason to DozeUi" into oc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
838e5f04be
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
@@ -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,
|
||||
@@ -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();
|
||||
@@ -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();
|
||||
@@ -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) {
|
||||
@@ -190,6 +219,7 @@ public class DozeMachine {
|
||||
State oldState = mState;
|
||||
mState = newState;
|
||||
|
||||
updatePulseReason(newState, oldState, pulseReason);
|
||||
performTransitionOnComponents(oldState, newState);
|
||||
updateScreenState(newState);
|
||||
updateWakeLockState(newState);
|
||||
@@ -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);
|
||||
@@ -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;
|
||||
|
||||
@@ -227,7 +227,7 @@ public class DozeTriggers implements DozeMachine.Part {
|
||||
mDozeHost.isPulsingBlocked());
|
||||
return;
|
||||
}
|
||||
mMachine.requestState(DozeMachine.State.DOZE_REQUEST_PULSE);
|
||||
mMachine.requestPulse(reason);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -22,7 +22,6 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.withSettings;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.content.Context;
|
||||
@@ -39,8 +38,6 @@ import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.MockSettings;
|
||||
|
||||
public class DozeTriggersTest {
|
||||
private Context mContext;
|
||||
@@ -104,7 +101,7 @@ public class DozeTriggersTest {
|
||||
mSensors.PROXIMITY.sendProximityResult(true); /* Far */
|
||||
});
|
||||
|
||||
verify(mMachine).requestState(DozeMachine.State.DOZE_REQUEST_PULSE);
|
||||
verify(mMachine).requestPulse(anyInt());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user