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

Commit fe3c9c80 authored by Dave Mankoff's avatar Dave Mankoff Committed by Automerger Merge Worker
Browse files

Merge "Don't use Primary sensor when Secondary available." into sc-dev am:...

Merge "Don't use Primary sensor when Secondary available." into sc-dev am: 00f16a79 am: 409551df

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15377083

Change-Id: I52d0633e96a784a7f11446e6d54c034aa8f4ef61
parents 406226fd 409551df
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);