Force an initial event to be sent to ProximitySensor.

When registering a proximity sensor, if the sensor is a
"dual" sensor, and the device starts uncovered, we need to
alert sensor listeners. Prior to this change, we left the
ProximitySensor in an "unknown" state, even though we knew
the device was uncovered.

Add tag to DozeSensor's ProximitySensor

Bug: 194974904
Test: manual && atest SystemUITests
Change-Id: I430cd0d63de9c8f0914d5b0d0ff0d86fc38c0190
This commit is contained in:
Dave Mankoff
2021-08-03 14:47:19 -04:00
parent 2458c8f8c6
commit 405e89be71
3 changed files with 69 additions and 4 deletions

View File

@@ -115,6 +115,7 @@ public class DozeSensors {
mSecureSettings = secureSettings;
mCallback = callback;
mProximitySensor = proximitySensor;
mProximitySensor.setTag(TAG);
mSelectivelyRegisterProxSensors = dozeParameters.getSelectivelyRegisterSensorsUsingProx();
mListeningProxSensors = !mSelectivelyRegisterProxSensors;
mScreenOffUdfpsEnabled =

View File

@@ -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);
}
}

View File

@@ -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