Merge "Prevent requesting invalid state after docked" into rvc-dev am: cf7b637860 am: ad84f54329 am: e02a62f291
Change-Id: Icffdcbc23aaff08b36f37d008bae5f34536005be
This commit is contained in:
@@ -40,7 +40,7 @@ public class DozeDockHandler implements DozeMachine.Part {
|
||||
|
||||
private int mDockState = DockManager.STATE_NONE;
|
||||
|
||||
public DozeDockHandler(AmbientDisplayConfiguration config, DozeMachine machine,
|
||||
DozeDockHandler(AmbientDisplayConfiguration config, DozeMachine machine,
|
||||
DockManager dockManager) {
|
||||
mMachine = machine;
|
||||
mConfig = config;
|
||||
@@ -74,8 +74,13 @@ public class DozeDockHandler implements DozeMachine.Part {
|
||||
@Override
|
||||
public void onEvent(int dockState) {
|
||||
if (DEBUG) Log.d(TAG, "dock event = " + dockState);
|
||||
final DozeMachine.State nextState;
|
||||
|
||||
mDockState = dockState;
|
||||
if (isPulsing()) {
|
||||
return;
|
||||
}
|
||||
|
||||
DozeMachine.State nextState;
|
||||
switch (mDockState) {
|
||||
case DockManager.STATE_DOCKED:
|
||||
nextState = State.DOZE_AOD_DOCKED;
|
||||
@@ -90,10 +95,15 @@ public class DozeDockHandler implements DozeMachine.Part {
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
mMachine.requestState(nextState);
|
||||
}
|
||||
|
||||
private boolean isPulsing() {
|
||||
DozeMachine.State state = mMachine.getState();
|
||||
return state == State.DOZE_REQUEST_PULSE || state == State.DOZE_PULSING
|
||||
|| state == State.DOZE_PULSING_BRIGHT;
|
||||
}
|
||||
|
||||
void register() {
|
||||
if (mRegistered) {
|
||||
return;
|
||||
|
||||
@@ -339,8 +339,8 @@ public class DozeMachine {
|
||||
return State.DOZE;
|
||||
}
|
||||
if ((mState == State.DOZE_AOD_PAUSED || mState == State.DOZE_AOD_PAUSING
|
||||
|| mState == State.DOZE_AOD || mState == State.DOZE)
|
||||
&& requestedState == State.DOZE_PULSE_DONE) {
|
||||
|| mState == State.DOZE_AOD || mState == State.DOZE
|
||||
|| mState == State.DOZE_AOD_DOCKED) && requestedState == State.DOZE_PULSE_DONE) {
|
||||
Log.i(TAG, "Dropping pulse done because current state is already done: " + mState);
|
||||
return mState;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,10 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.hardware.display.AmbientDisplayConfiguration;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
@@ -56,6 +58,7 @@ public class DozeDockHandlerTest extends SysuiTestCase {
|
||||
mDockManagerFake = spy(new DockManagerFake());
|
||||
mDockHandler = new DozeDockHandler(mConfig, mMachine, mDockManagerFake);
|
||||
|
||||
when(mMachine.getState()).thenReturn(State.DOZE_AOD);
|
||||
doReturn(true).when(mConfig).alwaysOnEnabled(anyInt());
|
||||
mDockHandler.transitionTo(DozeMachine.State.UNINITIALIZED, DozeMachine.State.INITIALIZED);
|
||||
}
|
||||
@@ -101,4 +104,31 @@ public class DozeDockHandlerTest extends SysuiTestCase {
|
||||
|
||||
verify(mMachine).requestState(eq(State.DOZE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onEvent_dockedWhilePulsing_wontRequestStateChange() {
|
||||
when(mMachine.getState()).thenReturn(State.DOZE_PULSING);
|
||||
|
||||
mDockManagerFake.setDockEvent(DockManager.STATE_DOCKED);
|
||||
|
||||
verify(mMachine, never()).requestState(any(State.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onEvent_noneWhilePulsing_wontRequestStateChange() {
|
||||
when(mMachine.getState()).thenReturn(State.DOZE_PULSING);
|
||||
|
||||
mDockManagerFake.setDockEvent(DockManager.STATE_NONE);
|
||||
|
||||
verify(mMachine, never()).requestState(any(State.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onEvent_hideWhilePulsing_wontRequestStateChange() {
|
||||
when(mMachine.getState()).thenReturn(State.DOZE_PULSING);
|
||||
|
||||
mDockManagerFake.setDockEvent(DockManager.STATE_DOCKED_HIDE);
|
||||
|
||||
verify(mMachine, never()).requestState(any(State.class));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,6 +253,17 @@ public class DozeMachineTest extends SysuiTestCase {
|
||||
assertEquals(DOZE_AOD_DOCKED, mMachine.getState());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPulseDone_whileDockedAoD_staysDockedAod() {
|
||||
when(mDockManager.isDocked()).thenReturn(true);
|
||||
mMachine.requestState(INITIALIZED);
|
||||
mMachine.requestState(DOZE_AOD_DOCKED);
|
||||
|
||||
mMachine.requestState(DOZE_PULSE_DONE);
|
||||
|
||||
verify(mPartMock, never()).transitionTo(DOZE_AOD_DOCKED, DOZE_PULSE_DONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPulseDone_dozeSuppressed_afterDocked_goesToDoze() {
|
||||
when(mHost.isDozeSuppressed()).thenReturn(true);
|
||||
|
||||
Reference in New Issue
Block a user