Merge "Don't use Primary sensor when Secondary available." into sc-dev
This commit is contained in:
@@ -281,18 +281,24 @@ public class ProximitySensor implements ThresholdSensor {
|
|||||||
|
|
||||||
mLastPrimaryEvent = event;
|
mLastPrimaryEvent = event;
|
||||||
|
|
||||||
if (event.getBelow() && mSecondaryThresholdSensor.isLoaded()) {
|
if (mSecondarySafe && mSecondaryThresholdSensor.isLoaded()) {
|
||||||
logDebug("Primary sensor is near. Checking secondary.");
|
logDebug("Primary sensor reported " + (event.getBelow() ? "near" : "far")
|
||||||
|
+ ". Checking secondary.");
|
||||||
if (mCancelSecondaryRunnable == null) {
|
if (mCancelSecondaryRunnable == null) {
|
||||||
mSecondaryThresholdSensor.resume();
|
mSecondaryThresholdSensor.resume();
|
||||||
}
|
}
|
||||||
} else {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!mSecondaryThresholdSensor.isLoaded()) {
|
if (!mSecondaryThresholdSensor.isLoaded()) {
|
||||||
logDebug("Primary sensor event: " + event.getBelow() + ". No secondary.");
|
logDebug("Primary sensor event: " + event.getBelow() + ". No secondary.");
|
||||||
} else {
|
|
||||||
logDebug("Primary sensor event: " + event.getBelow() + ".");
|
|
||||||
}
|
|
||||||
onSensorEvent(event);
|
onSensorEvent(event);
|
||||||
|
} else if (event.getBelow()) {
|
||||||
|
logDebug("Primary sensor event: " + event.getBelow() + ". Checking secondary.");
|
||||||
|
if (mCancelSecondaryRunnable != null) {
|
||||||
|
mCancelSecondaryRunnable.run();
|
||||||
|
}
|
||||||
|
mSecondaryThresholdSensor.resume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,25 @@ public class ProximitySensorDualTest extends SysuiTestCase {
|
|||||||
new FakeExecution());
|
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
|
@Test
|
||||||
public void testSingleListener() {
|
public void testSingleListener() {
|
||||||
TestableListener listener = new TestableListener();
|
TestableListener listener = new TestableListener();
|
||||||
@@ -255,40 +274,6 @@ public class ProximitySensorDualTest extends SysuiTestCase {
|
|||||||
mProximitySensor.unregister(listener);
|
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
|
@Test
|
||||||
public void testSecondaryCancelsSecondary() {
|
public void testSecondaryCancelsSecondary() {
|
||||||
TestableListener listener = new TestableListener();
|
TestableListener listener = new TestableListener();
|
||||||
@@ -342,7 +327,7 @@ public class ProximitySensorDualTest extends SysuiTestCase {
|
|||||||
|
|
||||||
// The secondary sensor should now remain resumed indefinitely.
|
// The secondary sensor should now remain resumed indefinitely.
|
||||||
assertFalse(mThresholdSensorSecondary.isPaused());
|
assertFalse(mThresholdSensorSecondary.isPaused());
|
||||||
mThresholdSensorPrimary.triggerEvent(false, 1);
|
mThresholdSensorSecondary.triggerEvent(false, 1);
|
||||||
assertFalse(listener.mLastEvent.getBelow());
|
assertFalse(listener.mLastEvent.getBelow());
|
||||||
assertEquals(2, listener.mCallCount);
|
assertEquals(2, listener.mCallCount);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user