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

Commit 9421918c 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: 00f16a79

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

Change-Id: I97e5fcfa258e12857137d8daed648c7e8a50c665
parents c030e76e 00f16a79
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);