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

Commit 0745b328 authored by Dave Mankoff's avatar Dave Mankoff
Browse files

Don't use Primary sensor when Secondary available.

In our proximity sensor, ignore events coming from the Primary sensor
when the Secondary sensor can be used instead.

Fixes: 193412708
Test: atest SystemUITests
Change-Id: I763b5541a92956c96445d2d9b3144956cbdccc9a
parent 850bb03e
Loading
Loading
Loading
Loading
+14 −8
Original line number Diff line number Diff line
@@ -281,18 +281,24 @@ public class ProximitySensor implements ThresholdSensor {

        mLastPrimaryEvent = event;

        if (event.getBelow() && mSecondaryThresholdSensor.isLoaded()) {
            logDebug("Primary sensor is near. Checking secondary.");
        if (mSecondarySafe && mSecondaryThresholdSensor.isLoaded()) {
            logDebug("Primary sensor reported " + (event.getBelow() ? "near" : "far")
                    + ". Checking secondary.");
            if (mCancelSecondaryRunnable == null) {
                mSecondaryThresholdSensor.resume();
            }
        } else {
            return;
        }

        if (!mSecondaryThresholdSensor.isLoaded()) {
            logDebug("Primary sensor event: " + event.getBelow() + ". No secondary.");
            } else {
                logDebug("Primary sensor event: " + event.getBelow() + ".");
            }
            onSensorEvent(event);
        } else if (event.getBelow()) {
            logDebug("Primary sensor event: " + event.getBelow() + ". Checking secondary.");
            if (mCancelSecondaryRunnable != null) {
                mCancelSecondaryRunnable.run();
            }
            mSecondaryThresholdSensor.resume();
        }
    }

+20 −35
Original line number Diff line number Diff line
@@ -59,6 +59,25 @@ public class ProximitySensorDualTest extends SysuiTestCase {
                new FakeExecution());
    }

    @Test
    public void testPrimaryBelowDoesNotInvokeSecondary() {
        TestableListener listener = new TestableListener();

        mProximitySensor.register(listener);
        assertTrue(mProximitySensor.isRegistered());
        assertFalse(mThresholdSensorPrimary.isPaused());
        assertTrue(mThresholdSensorSecondary.isPaused());
        assertNull(listener.mLastEvent);
        assertEquals(0, listener.mCallCount);

        // Trigger primary sensor. Our secondary sensor is not registered.
        mThresholdSensorPrimary.triggerEvent(false, 0);
        assertFalse(mThresholdSensorPrimary.isPaused());
        assertTrue(mThresholdSensorSecondary.isPaused());
        assertNull(listener.mLastEvent);
        assertEquals(0, listener.mCallCount);
    }

    @Test
    public void testSingleListener() {
        TestableListener listener = new TestableListener();
@@ -255,40 +274,6 @@ public class ProximitySensorDualTest extends SysuiTestCase {
        mProximitySensor.unregister(listener);
    }

    @Test
    public void testPrimaryCancelsSecondary() {
        TestableListener listener = new TestableListener();

        mProximitySensor.register(listener);
        assertFalse(mThresholdSensorPrimary.isPaused());
        assertTrue(mThresholdSensorSecondary.isPaused());
        assertNull(listener.mLastEvent);
        assertEquals(0, listener.mCallCount);

        mThresholdSensorPrimary.triggerEvent(true, 0);
        assertNull(listener.mLastEvent);
        assertEquals(0, listener.mCallCount);
        mThresholdSensorSecondary.triggerEvent(true, 0);
        assertTrue(listener.mLastEvent.getBelow());
        assertEquals(1, listener.mCallCount);

        // When the primary reports false, the secondary is no longer needed. We get an immediate
        // report.
        mThresholdSensorPrimary.triggerEvent(false, 1);
        assertFalse(listener.mLastEvent.getBelow());
        assertEquals(2, listener.mCallCount);

        // The secondary is now ignored. No more work is scheduled.
        mFakeExecutor.advanceClockToNext();
        mFakeExecutor.runNextReady();
        mThresholdSensorSecondary.triggerEvent(true, 0);
        assertFalse(listener.mLastEvent.getBelow());
        assertEquals(2, listener.mCallCount);
        assertEquals(0, mFakeExecutor.numPending());

        mProximitySensor.unregister(listener);
    }

    @Test
    public void testSecondaryCancelsSecondary() {
        TestableListener listener = new TestableListener();
@@ -342,7 +327,7 @@ public class ProximitySensorDualTest extends SysuiTestCase {

        // The secondary sensor should now remain resumed indefinitely.
        assertFalse(mThresholdSensorSecondary.isPaused());
        mThresholdSensorPrimary.triggerEvent(false, 1);
        mThresholdSensorSecondary.triggerEvent(false, 1);
        assertFalse(listener.mLastEvent.getBelow());
        assertEquals(2, listener.mCallCount);