Merge "Force an initial event to be sent to ProximitySensor." into sc-dev am: 831b21f456
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15455734 Change-Id: I18307b7b86a23a7f5271375766b0f8cd16789f30
This commit is contained in:
@@ -115,6 +115,7 @@ public class DozeSensors {
|
||||
mSecureSettings = secureSettings;
|
||||
mCallback = callback;
|
||||
mProximitySensor = proximitySensor;
|
||||
mProximitySensor.setTag(TAG);
|
||||
mSelectivelyRegisterProxSensors = dozeParameters.getSelectivelyRegisterSensorsUsingProx();
|
||||
mListeningProxSensors = !mSelectivelyRegisterProxSensors;
|
||||
mScreenOffUdfpsEnabled =
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -59,6 +60,68 @@ public class ProximitySensorDualTest extends SysuiTestCase {
|
||||
new FakeExecution());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitiallyAbovePrimary() {
|
||||
|
||||
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(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();
|
||||
@@ -74,8 +137,6 @@ public class ProximitySensorDualTest extends SysuiTestCase {
|
||||
mThresholdSensorPrimary.triggerEvent(false, 0);
|
||||
assertFalse(mThresholdSensorPrimary.isPaused());
|
||||
assertTrue(mThresholdSensorSecondary.isPaused());
|
||||
assertNull(listener.mLastEvent);
|
||||
assertEquals(0, listener.mCallCount);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user