Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 615c06f3 authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Only act on event if something actually changed

Dock events were forcing the device into AOD mode, and overriding the
proximity sensor.

Test: manual
Test: atest DozeDockHandlerTest
Fixes: 152377547
Change-Id: I250a0952ac82bc0690676e1c27f839179d7fa4f7
parent 56f55b98
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -75,6 +75,12 @@ public class DozeDockHandler implements DozeMachine.Part {
        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;
+12 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.doze;
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;
@@ -82,8 +83,17 @@ public class DozeDockHandlerTest extends SysuiTestCase {
        verify(mMachine).requestState(eq(State.DOZE_AOD_DOCKED));
    }

    @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 @@ public class DozeDockHandlerTest extends SysuiTestCase {

    @Test
    public void onEvent_noneWhileDisabledAod_requestsDozeState() {
        mDockManagerFake.setDockEvent(DockManager.STATE_DOCKED);
        clearInvocations(mMachine);
        doReturn(false).when(mConfig).alwaysOnEnabled(anyInt());

        mDockManagerFake.setDockEvent(DockManager.STATE_NONE);