Merge "Keep secondary prox registered when covered." into rvc-d1-dev

This commit is contained in:
TreeHugger Robot
2020-06-05 18:45:58 +00:00
committed by Android (Google) Code Review
4 changed files with 20 additions and 20 deletions

View File

@@ -83,20 +83,21 @@ public class ProximitySensor implements ThresholdSensor {
private ThresholdSensor.Listener mSecondaryEventListener = new ThresholdSensor.Listener() {
@Override
public void onThresholdCrossed(ThresholdSensorEvent event) {
// This sensor should only be used briefly. Turn it off as soon as we get a reading.
mSecondaryThresholdSensor.pause();
// Only check the secondary as long as the primary thinks we're near.
if (!mLastPrimaryEvent.getBelow()) {
mSecondaryThresholdSensor.pause();
mCancelSecondaryRunnable = null;
return;
}
logDebug("Secondary sensor event: " + event.getBelow() + ".");
// Check this sensor again in a moment.
mCancelSecondaryRunnable = mDelayableExecutor.executeDelayed(
mSecondaryThresholdSensor::resume, SECONDARY_PING_INTERVAL_MS);
// This sensor should only be used briefly when uncovered.
if (!event.getBelow()) {
mSecondaryThresholdSensor.pause();
// Check this sensor again in a moment.
mCancelSecondaryRunnable = mDelayableExecutor.executeDelayed(
mSecondaryThresholdSensor::resume, SECONDARY_PING_INTERVAL_MS);
}
onSensorEvent(event);
}
};

View File

@@ -51,7 +51,7 @@ class ThresholdSensorImpl implements ThresholdSensor {
@Override
public void onSensorChanged(SensorEvent event) {
boolean below = event.values[0] < mThreshold;
boolean above = event.values[0] > mThresholdLatch;
boolean above = event.values[0] >= mThresholdLatch;
logDebug("Sensor value: " + event.values[0]);
onSensorEvent(below, above, event.timestamp);
}

View File

@@ -86,10 +86,9 @@ public class ProximitySensorDualTest extends SysuiTestCase {
// Trigger second sensor.
mThresholdSensorSecondary.triggerEvent(true, 0);
assertFalse(mThresholdSensorPrimary.isPaused());
assertTrue(mThresholdSensorSecondary.isPaused());
assertFalse(mThresholdSensorSecondary.isPaused());
assertTrue(listener.mLastEvent.getBelow());
assertEquals(1, listener.mCallCount);
assertTrue(mThresholdSensorSecondary.isPaused());
mProximitySensor.unregister(listener);
}
@@ -109,10 +108,16 @@ public class ProximitySensorDualTest extends SysuiTestCase {
assertNull(listener.mLastEvent);
assertEquals(0, listener.mCallCount);
// Trigger second sensor.
// Trigger second sensor. Second sensor remains registered.
mThresholdSensorSecondary.triggerEvent(true, 0);
assertTrue(listener.mLastEvent.getBelow());
assertEquals(1, listener.mCallCount);
assertFalse(mThresholdSensorSecondary.isPaused());
// Triggering above should pause.
mThresholdSensorSecondary.triggerEvent(false, 0);
assertFalse(listener.mLastEvent.getBelow());
assertEquals(2, listener.mCallCount);
assertTrue(mThresholdSensorSecondary.isPaused());
// Advance time. Second sensor should resume.
@@ -120,12 +125,6 @@ public class ProximitySensorDualTest extends SysuiTestCase {
mFakeExecutor.runNextReady();
assertFalse(mThresholdSensorSecondary.isPaused());
// Triggering should pause again.
mThresholdSensorSecondary.triggerEvent(false, 0);
assertFalse(listener.mLastEvent.getBelow());
assertEquals(2, listener.mCallCount);
assertTrue(mThresholdSensorSecondary.isPaused());
mProximitySensor.unregister(listener);
}
@@ -143,7 +142,7 @@ public class ProximitySensorDualTest extends SysuiTestCase {
mThresholdSensorPrimary.triggerEvent(true, 0);
mThresholdSensorSecondary.triggerEvent(true, 0);
assertFalse(mThresholdSensorPrimary.isPaused());
assertTrue(mThresholdSensorSecondary.isPaused());
assertFalse(mThresholdSensorSecondary.isPaused());
assertTrue(listener.mLastEvent.getBelow());
assertEquals(1, listener.mCallCount);
@@ -165,7 +164,7 @@ public class ProximitySensorDualTest extends SysuiTestCase {
mThresholdSensorPrimary.triggerEvent(true, 0);
mThresholdSensorSecondary.triggerEvent(true, 0);
assertFalse(mThresholdSensorPrimary.isPaused());
assertTrue(mThresholdSensorSecondary.isPaused());
assertFalse(mThresholdSensorSecondary.isPaused());
assertTrue(listener.mLastEvent.getBelow());
assertEquals(1, listener.mCallCount);

View File

@@ -259,7 +259,7 @@ public class ThresholdSensorImplTest extends SysuiTestCase {
assertTrue(listener.mBelow);
assertEquals(1, listener.mCallCount);
sensor.sendSensorEvent(highValue + 1);
sensor.sendSensorEvent(highValue);
assertFalse(listener.mBelow);
assertEquals(2, listener.mCallCount);