Merge "Prevent paused ThresholdSensorImpl event delivery." into rvc-d1-dev

This commit is contained in:
TreeHugger Robot
2020-04-28 21:38:48 +00:00
committed by Android (Google) Code Review
2 changed files with 18 additions and 1 deletions

View File

@@ -167,7 +167,7 @@ class ThresholdSensorImpl implements ThresholdSensor {
private void onSensorEvent(boolean below, long timestampNs) { private void onSensorEvent(boolean below, long timestampNs) {
Assert.isMainThread(); Assert.isMainThread();
if (mLastBelow != null && mLastBelow == below) { if (!mRegistered || mLastBelow != null && mLastBelow == below) {
return; return;
} }
mLastBelow = below; mLastBelow = below;

View File

@@ -226,6 +226,23 @@ public class ThresholdSensorImplTest extends SysuiTestCase {
waitForSensorManager(); 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 { static class TestableListener implements ThresholdSensor.Listener {
boolean mBelow; boolean mBelow;
long mTimestampNs; long mTimestampNs;