Merge "AOD: Pass through pulse reason to DozeUi" into oc-dev
am: 838e5f04be
Change-Id: Ia14a5339053ac91ce4f08e1fde33fd6c2816ffe5
This commit is contained in:
@@ -37,6 +37,7 @@ public class DozeLog {
|
|||||||
|
|
||||||
private static final int PULSE_REASONS = 5;
|
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_INTENT = 0;
|
||||||
public static final int PULSE_REASON_NOTIFICATION = 1;
|
public static final int PULSE_REASON_NOTIFICATION = 1;
|
||||||
public static final int PULSE_REASON_SENSOR_SIGMOTION = 2;
|
public static final int PULSE_REASON_SENSOR_SIGMOTION = 2;
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ public class DozeMachine {
|
|||||||
|
|
||||||
private final ArrayList<State> mQueuedRequests = new ArrayList<>();
|
private final ArrayList<State> mQueuedRequests = new ArrayList<>();
|
||||||
private State mState = State.UNINITIALIZED;
|
private State mState = State.UNINITIALIZED;
|
||||||
|
private int mPulseReason;
|
||||||
private boolean mWakeLockHeldForCurrentState = false;
|
private boolean mWakeLockHeldForCurrentState = false;
|
||||||
|
|
||||||
public DozeMachine(Service service, AmbientDisplayConfiguration config,
|
public DozeMachine(Service service, AmbientDisplayConfiguration config,
|
||||||
@@ -133,6 +134,20 @@ public class DozeMachine {
|
|||||||
*/
|
*/
|
||||||
@MainThread
|
@MainThread
|
||||||
public void requestState(State requestedState) {
|
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();
|
Assert.isMainThread();
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.i(TAG, "request: current=" + mState + " req=" + requestedState,
|
Log.i(TAG, "request: current=" + mState + " req=" + requestedState,
|
||||||
@@ -146,7 +161,7 @@ public class DozeMachine {
|
|||||||
for (int i = 0; i < mQueuedRequests.size(); i++) {
|
for (int i = 0; i < mQueuedRequests.size(); i++) {
|
||||||
// Transitions in Parts can call back into requestState, which will
|
// Transitions in Parts can call back into requestState, which will
|
||||||
// cause mQueuedRequests to grow.
|
// cause mQueuedRequests to grow.
|
||||||
transitionTo(mQueuedRequests.get(i));
|
transitionTo(mQueuedRequests.get(i), pulseReason);
|
||||||
}
|
}
|
||||||
mQueuedRequests.clear();
|
mQueuedRequests.clear();
|
||||||
mWakeLock.release();
|
mWakeLock.release();
|
||||||
@@ -165,6 +180,20 @@ public class DozeMachine {
|
|||||||
return mState;
|
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. */
|
/** Requests the PowerManager to wake up now. */
|
||||||
public void wakeUp() {
|
public void wakeUp() {
|
||||||
mDozeService.requestWakeUp();
|
mDozeService.requestWakeUp();
|
||||||
@@ -174,7 +203,7 @@ public class DozeMachine {
|
|||||||
return !mQueuedRequests.isEmpty();
|
return !mQueuedRequests.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void transitionTo(State requestedState) {
|
private void transitionTo(State requestedState, int pulseReason) {
|
||||||
State newState = transitionPolicy(requestedState);
|
State newState = transitionPolicy(requestedState);
|
||||||
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
@@ -190,6 +219,7 @@ public class DozeMachine {
|
|||||||
State oldState = mState;
|
State oldState = mState;
|
||||||
mState = newState;
|
mState = newState;
|
||||||
|
|
||||||
|
updatePulseReason(newState, oldState, pulseReason);
|
||||||
performTransitionOnComponents(oldState, newState);
|
performTransitionOnComponents(oldState, newState);
|
||||||
updateScreenState(newState);
|
updateScreenState(newState);
|
||||||
updateWakeLockState(newState);
|
updateWakeLockState(newState);
|
||||||
@@ -197,6 +227,14 @@ public class DozeMachine {
|
|||||||
resolveIntermediateState(newState);
|
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) {
|
private void performTransitionOnComponents(State oldState, State newState) {
|
||||||
for (Part p : mParts) {
|
for (Part p : mParts) {
|
||||||
p.transitionTo(oldState, newState);
|
p.transitionTo(oldState, newState);
|
||||||
@@ -280,7 +318,8 @@ public class DozeMachine {
|
|||||||
case INITIALIZED:
|
case INITIALIZED:
|
||||||
case DOZE_PULSE_DONE:
|
case DOZE_PULSE_DONE:
|
||||||
transitionTo(mConfig.alwaysOnEnabled(UserHandle.USER_CURRENT)
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -227,7 +227,7 @@ public class DozeTriggers implements DozeMachine.Part {
|
|||||||
mDozeHost.isPulsingBlocked());
|
mDozeHost.isPulsingBlocked());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mMachine.requestState(DozeMachine.State.DOZE_REQUEST_PULSE);
|
mMachine.requestPulse(reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ public class DozeUi implements DozeMachine.Part {
|
|||||||
unscheduleTimeTick();
|
unscheduleTimeTick();
|
||||||
break;
|
break;
|
||||||
case DOZE_REQUEST_PULSE:
|
case DOZE_REQUEST_PULSE:
|
||||||
pulseWhileDozing(DozeLog.PULSE_REASON_NOTIFICATION /* TODO */);
|
pulseWhileDozing(mMachine.getPulseReason());
|
||||||
break;
|
break;
|
||||||
case DOZE_PULSE_DONE:
|
case DOZE_PULSE_DONE:
|
||||||
mHost.abortPulsing();
|
mHost.abortPulsing();
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ public class DozeMachineTest {
|
|||||||
public void testPulseDone_goesToDoze() {
|
public void testPulseDone_goesToDoze() {
|
||||||
when(mConfigMock.alwaysOnEnabled(anyInt())).thenReturn(false);
|
when(mConfigMock.alwaysOnEnabled(anyInt())).thenReturn(false);
|
||||||
mMachine.requestState(INITIALIZED);
|
mMachine.requestState(INITIALIZED);
|
||||||
mMachine.requestState(DOZE_REQUEST_PULSE);
|
mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION);
|
||||||
mMachine.requestState(DOZE_PULSING);
|
mMachine.requestState(DOZE_PULSING);
|
||||||
|
|
||||||
mMachine.requestState(DOZE_PULSE_DONE);
|
mMachine.requestState(DOZE_PULSE_DONE);
|
||||||
@@ -119,7 +119,7 @@ public class DozeMachineTest {
|
|||||||
public void testPulseDone_goesToAoD() {
|
public void testPulseDone_goesToAoD() {
|
||||||
when(mConfigMock.alwaysOnEnabled(anyInt())).thenReturn(true);
|
when(mConfigMock.alwaysOnEnabled(anyInt())).thenReturn(true);
|
||||||
mMachine.requestState(INITIALIZED);
|
mMachine.requestState(INITIALIZED);
|
||||||
mMachine.requestState(DOZE_REQUEST_PULSE);
|
mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION);
|
||||||
mMachine.requestState(DOZE_PULSING);
|
mMachine.requestState(DOZE_PULSING);
|
||||||
|
|
||||||
mMachine.requestState(DOZE_PULSE_DONE);
|
mMachine.requestState(DOZE_PULSE_DONE);
|
||||||
@@ -163,7 +163,7 @@ public class DozeMachineTest {
|
|||||||
public void testWakeLock_heldInPulseStates() {
|
public void testWakeLock_heldInPulseStates() {
|
||||||
mMachine.requestState(INITIALIZED);
|
mMachine.requestState(INITIALIZED);
|
||||||
|
|
||||||
mMachine.requestState(DOZE_REQUEST_PULSE);
|
mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION);
|
||||||
assertTrue(mWakeLockFake.isHeld());
|
assertTrue(mWakeLockFake.isHeld());
|
||||||
|
|
||||||
mMachine.requestState(DOZE_PULSING);
|
mMachine.requestState(DOZE_PULSING);
|
||||||
@@ -186,7 +186,7 @@ public class DozeMachineTest {
|
|||||||
mMachine.requestState(INITIALIZED);
|
mMachine.requestState(INITIALIZED);
|
||||||
|
|
||||||
mMachine.requestState(DOZE);
|
mMachine.requestState(DOZE);
|
||||||
mMachine.requestState(DOZE_REQUEST_PULSE);
|
mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION);
|
||||||
mMachine.requestState(DOZE_PULSING);
|
mMachine.requestState(DOZE_PULSING);
|
||||||
mMachine.requestState(DOZE_PULSE_DONE);
|
mMachine.requestState(DOZE_PULSE_DONE);
|
||||||
|
|
||||||
@@ -198,9 +198,9 @@ public class DozeMachineTest {
|
|||||||
mMachine.requestState(INITIALIZED);
|
mMachine.requestState(INITIALIZED);
|
||||||
|
|
||||||
mMachine.requestState(DOZE);
|
mMachine.requestState(DOZE);
|
||||||
mMachine.requestState(DOZE_REQUEST_PULSE);
|
mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION);
|
||||||
mMachine.requestState(DOZE_PULSING);
|
mMachine.requestState(DOZE_PULSING);
|
||||||
mMachine.requestState(DOZE_REQUEST_PULSE);
|
mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION);
|
||||||
mMachine.requestState(DOZE_PULSE_DONE);
|
mMachine.requestState(DOZE_PULSE_DONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,7 +209,7 @@ public class DozeMachineTest {
|
|||||||
mMachine.requestState(INITIALIZED);
|
mMachine.requestState(INITIALIZED);
|
||||||
|
|
||||||
mMachine.requestState(DOZE);
|
mMachine.requestState(DOZE);
|
||||||
mMachine.requestState(DOZE_REQUEST_PULSE);
|
mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION);
|
||||||
mMachine.requestState(DOZE_PULSE_DONE);
|
mMachine.requestState(DOZE_PULSE_DONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,7 +235,7 @@ public class DozeMachineTest {
|
|||||||
public void testScreen_onInPulse() {
|
public void testScreen_onInPulse() {
|
||||||
mMachine.requestState(INITIALIZED);
|
mMachine.requestState(INITIALIZED);
|
||||||
|
|
||||||
mMachine.requestState(DOZE_REQUEST_PULSE);
|
mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION);
|
||||||
mMachine.requestState(DOZE_PULSING);
|
mMachine.requestState(DOZE_PULSING);
|
||||||
|
|
||||||
assertEquals(Display.STATE_DOZE, mServiceFake.screenState);
|
assertEquals(Display.STATE_DOZE, mServiceFake.screenState);
|
||||||
@@ -246,7 +246,7 @@ public class DozeMachineTest {
|
|||||||
mMachine.requestState(INITIALIZED);
|
mMachine.requestState(INITIALIZED);
|
||||||
|
|
||||||
mMachine.requestState(DOZE);
|
mMachine.requestState(DOZE);
|
||||||
mMachine.requestState(DOZE_REQUEST_PULSE);
|
mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION);
|
||||||
|
|
||||||
assertEquals(Display.STATE_OFF, mServiceFake.screenState);
|
assertEquals(Display.STATE_OFF, mServiceFake.screenState);
|
||||||
}
|
}
|
||||||
@@ -256,7 +256,7 @@ public class DozeMachineTest {
|
|||||||
mMachine.requestState(INITIALIZED);
|
mMachine.requestState(INITIALIZED);
|
||||||
|
|
||||||
mMachine.requestState(DOZE_AOD);
|
mMachine.requestState(DOZE_AOD);
|
||||||
mMachine.requestState(DOZE_REQUEST_PULSE);
|
mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION);
|
||||||
|
|
||||||
assertEquals(Display.STATE_DOZE, mServiceFake.screenState);
|
assertEquals(Display.STATE_DOZE, mServiceFake.screenState);
|
||||||
}
|
}
|
||||||
@@ -270,11 +270,42 @@ public class DozeMachineTest {
|
|||||||
return null;
|
return null;
|
||||||
}).when(mPartMock).transitionTo(any(), eq(DOZE_REQUEST_PULSE));
|
}).when(mPartMock).transitionTo(any(), eq(DOZE_REQUEST_PULSE));
|
||||||
|
|
||||||
mMachine.requestState(DOZE_REQUEST_PULSE);
|
mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION);
|
||||||
|
|
||||||
assertEquals(DOZE_PULSING, mMachine.getState());
|
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
|
@Test
|
||||||
public void testWakeUp_wakesUp() {
|
public void testWakeUp_wakesUp() {
|
||||||
mMachine.wakeUp();
|
mMachine.wakeUp();
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import static org.mockito.Mockito.mock;
|
|||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
import static org.mockito.Mockito.withSettings;
|
|
||||||
|
|
||||||
import android.app.Instrumentation;
|
import android.app.Instrumentation;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -39,8 +38,6 @@ import org.junit.Before;
|
|||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Answers;
|
|
||||||
import org.mockito.MockSettings;
|
|
||||||
|
|
||||||
public class DozeTriggersTest {
|
public class DozeTriggersTest {
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
@@ -104,7 +101,7 @@ public class DozeTriggersTest {
|
|||||||
mSensors.PROXIMITY.sendProximityResult(true); /* Far */
|
mSensors.PROXIMITY.sendProximityResult(true); /* Far */
|
||||||
});
|
});
|
||||||
|
|
||||||
verify(mMachine).requestState(DozeMachine.State.DOZE_REQUEST_PULSE);
|
verify(mMachine).requestPulse(anyInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user