Merge "Only act on event if something actually changed" into rvc-dev
diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeDockHandler.java b/packages/SystemUI/src/com/android/systemui/doze/DozeDockHandler.java
index 3f88f25..554457b 100644
--- a/packages/SystemUI/src/com/android/systemui/doze/DozeDockHandler.java
+++ b/packages/SystemUI/src/com/android/systemui/doze/DozeDockHandler.java
@@ -75,6 +75,12 @@
public void onEvent(int dockState) {
if (DEBUG) Log.d(TAG, "dock event = " + dockState);
+ // Only act upon state changes, otherwise we might overwrite other transitions,
+ // like proximity sensor initialization.
+ if (mDockState == dockState) {
+ return;
+ }
+
mDockState = dockState;
if (isPulsing()) {
return;
diff --git a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeDockHandlerTest.java b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeDockHandlerTest.java
index 9985d21..dc02799 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeDockHandlerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeDockHandlerTest.java
@@ -19,6 +19,7 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
@@ -83,7 +84,16 @@
}
@Test
+ public void onEvent_noneWhileEnabledAod_ignoresIfAlreadyNone() {
+ mDockManagerFake.setDockEvent(DockManager.STATE_NONE);
+
+ verify(mMachine, never()).requestState(eq(State.DOZE_AOD));
+ }
+
+ @Test
public void onEvent_noneWhileEnabledAod_requestsAodState() {
+ mDockManagerFake.setDockEvent(DockManager.STATE_DOCKED);
+ clearInvocations(mMachine);
mDockManagerFake.setDockEvent(DockManager.STATE_NONE);
verify(mMachine).requestState(eq(State.DOZE_AOD));
@@ -91,6 +101,8 @@
@Test
public void onEvent_noneWhileDisabledAod_requestsDozeState() {
+ mDockManagerFake.setDockEvent(DockManager.STATE_DOCKED);
+ clearInvocations(mMachine);
doReturn(false).when(mConfig).alwaysOnEnabled(anyInt());
mDockManagerFake.setDockEvent(DockManager.STATE_NONE);