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

Commit 8c5cce63 authored by Dave Mankoff's avatar Dave Mankoff
Browse files

Prevent paused ThresholdSensorImpl event delivery.

With this change, a paused ThresholdSensorImpl will no longer deliver
events. This can otherwise happen if a ThresholdSensorImpl attempts
to unregister itself, but an event comes before the de-registration
actually occurs.

This can occur because ThresholdSensorImpl relies on an
AsyncSensorManager.

Fixes: 155135632
Test: atest SystemUITests
Change-Id: I26f743016cba2383e853436ac41463a7677692a9
parent 5f991c61
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -167,7 +167,7 @@ class ThresholdSensorImpl implements ThresholdSensor {

    private void onSensorEvent(boolean below, long timestampNs) {
        Assert.isMainThread();
        if (mLastBelow != null && mLastBelow == below) {
        if (!mRegistered || mLastBelow != null && mLastBelow == below) {
            return;
        }
        mLastBelow = below;
+17 −0
Original line number Diff line number Diff line
@@ -226,6 +226,23 @@ public class ThresholdSensorImplTest extends SysuiTestCase {
        waitForSensorManager();
    }

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

        mThresholdSensor.register(listener);
        waitForSensorManager();
        mFakeProximitySensor.sendProximityResult(false);
        assertTrue(listener.mBelow);
        assertEquals(1, listener.mCallCount);

        mThresholdSensor.pause();

        mFakeProximitySensor.sendProximityResult(false);
        assertTrue(listener.mBelow);
        assertEquals(1, listener.mCallCount);
    }

    static class TestableListener implements ThresholdSensor.Listener {
        boolean mBelow;
        long mTimestampNs;