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
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user