diff options
3 files changed, 69 insertions, 4 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeSensors.java b/packages/SystemUI/src/com/android/systemui/doze/DozeSensors.java index 23c44131ab60..b2db86f16104 100644 --- a/packages/SystemUI/src/com/android/systemui/doze/DozeSensors.java +++ b/packages/SystemUI/src/com/android/systemui/doze/DozeSensors.java @@ -115,6 +115,7 @@ public class DozeSensors { mSecureSettings = secureSettings; mCallback = callback; mProximitySensor = proximitySensor; + mProximitySensor.setTag(TAG); mSelectivelyRegisterProxSensors = dozeParameters.getSelectivelyRegisterSensorsUsingProx(); mListeningProxSensors = !mSelectivelyRegisterProxSensors; mScreenOffUdfpsEnabled = diff --git a/packages/SystemUI/src/com/android/systemui/util/sensors/ProximitySensor.java b/packages/SystemUI/src/com/android/systemui/util/sensors/ProximitySensor.java index b38fc77fd131..90e022a52d7a 100644 --- a/packages/SystemUI/src/com/android/systemui/util/sensors/ProximitySensor.java +++ b/packages/SystemUI/src/com/android/systemui/util/sensors/ProximitySensor.java @@ -290,15 +290,18 @@ public class ProximitySensor implements ThresholdSensor { return; } - if (!mSecondaryThresholdSensor.isLoaded()) { + + if (!mSecondaryThresholdSensor.isLoaded()) { // No secondary logDebug("Primary sensor event: " + event.getBelow() + ". No secondary."); onSensorEvent(event); - } else if (event.getBelow()) { + } else if (event.getBelow()) { // Covered? Check secondary. logDebug("Primary sensor event: " + event.getBelow() + ". Checking secondary."); if (mCancelSecondaryRunnable != null) { mCancelSecondaryRunnable.run(); } mSecondaryThresholdSensor.resume(); + } else { // Uncovered. Report immediately. + onSensorEvent(event); } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/util/sensors/ProximitySensorDualTest.java b/packages/SystemUI/tests/src/com/android/systemui/util/sensors/ProximitySensorDualTest.java index cc2afe2f7b8a..a34c5986f36c 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/util/sensors/ProximitySensorDualTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/util/sensors/ProximitySensorDualTest.java @@ -18,6 +18,7 @@ package com.android.systemui.util.sensors; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -60,7 +61,8 @@ public class ProximitySensorDualTest extends SysuiTestCase { } @Test - public void testPrimaryBelowDoesNotInvokeSecondary() { + public void testInitiallyAbovePrimary() { + TestableListener listener = new TestableListener(); mProximitySensor.register(listener); @@ -70,12 +72,71 @@ public class ProximitySensorDualTest extends SysuiTestCase { assertNull(listener.mLastEvent); assertEquals(0, listener.mCallCount); - // Trigger primary sensor. Our secondary sensor is not registered. mThresholdSensorPrimary.triggerEvent(false, 0); + assertNotNull(listener.mLastEvent); + assertFalse(listener.mLastEvent.getBelow()); + assertEquals(1, listener.mCallCount); + } + + @Test + public void testInitiallyBelowPrimaryAboveSecondary() { + + TestableListener listener = new TestableListener(); + + mProximitySensor.register(listener); + assertTrue(mProximitySensor.isRegistered()); 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(false, 1); + assertNotNull(listener.mLastEvent); + assertFalse(listener.mLastEvent.getBelow()); + assertEquals(1, listener.mCallCount); + } + + @Test + public void testInitiallyBelowPrimaryAndSecondary() { + + TestableListener listener = new TestableListener(); + + mProximitySensor.register(listener); + assertTrue(mProximitySensor.isRegistered()); + 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, 1); + assertNotNull(listener.mLastEvent); + assertTrue(listener.mLastEvent.getBelow()); + assertEquals(1, listener.mCallCount); + } + + @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()); } @Test |