Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 311fb193 authored by Dave Mankoff's avatar Dave Mankoff
Browse files

RESTRICT AUTOMERGE ProximitySensor now supports dual-sensor approach.

The ProximitySensor now supports the concept of a primary and a
secondary hardware sensor. The primary sensor is used for a first
pass check if the phone covered. When triggered, it then checks
the secondary sensor for confirmation (if there is one). It does
not send a proximity event until the secondary sensor confirms (or
rejects) the reading. The secondary sensor is, in fact, the source
of truth.

This is necessary as sometimes keeping the secondary sensor on for
extends periods is undesirable. It may, however, result in increased
latency for proximity readings.

Phones should configure this via a config.xml overlay. If no
proximity sensor is set (primary or secondary) we fall back to the
default Sensor.TYPE_PROXIMITY. If proximity_sensor_type is set in
config.xml, that will be used as the primary sensor. If
proximity_sensor_secondary_type is set, that will function as the
secondary sensor. If no secondary is set, only the primary will be
used.

This CL also introduces the ThresholdSensor interface. This is a
simple sensor wrapper for sensors that need to report a binary
above/below value. ProximitySensor now implements this interface
and also takes in ThresholdSensor as its primary and secondary
inputs.

Bug: 147026387
Test: atest SystemUITests && manual
Change-Id: I1e808e591f1db05c664df6190670cb92315f63f3
Merged-In: I1e808e591f1db05c664df6190670cb92315f63f3
parent 6f2658d5
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -205,6 +205,14 @@
         far break points. A sensor value less than this is considered "near". -->
    <item name="proximity_sensor_threshold" translatable="false" format="float" type="dimen"></item>

    <!-- Override value to use for proximity sensor as confirmation for proximity_sensor_type. -->
    <string name="proximity_sensor_secondary_type" translatable="false"></string>

    <!-- If using proximity_sensor_confirmation_type, specifies a threshold value to distinguish
         near and far break points. A sensor value less than this is considered "near". -->
    <item name="proximity_sensor_secondary_threshold" translatable="false" format="float"
          type="dimen"></item>

    <!-- Doze: pulse parameter - how long does it take to fade in? -->
    <integer name="doze_pulse_duration_in">130</integer>

+1 −1
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ public class FalsingManagerProxy implements FalsingManager, Dumpable {
        mUiBgExecutor = uiBgExecutor;
        mStatusBarStateController = statusBarStateController;
        mProximitySensor.setTag(PROXIMITY_SENSOR_TAG);
        mProximitySensor.setSensorDelay(SensorManager.SENSOR_DELAY_GAME);
        mProximitySensor.setDelay(SensorManager.SENSOR_DELAY_GAME);
        mDeviceConfig = deviceConfig;
        mDeviceConfigListener =
                properties -> onDeviceConfigPropertiesChanged(context, properties.getNamespace());
+3 −2
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.StatusBarState;
import com.android.systemui.util.DeviceConfigProxy;
import com.android.systemui.util.sensors.ProximitySensor;
import com.android.systemui.util.sensors.ThresholdSensor;

import java.io.PrintWriter;
import java.util.ArrayDeque;
@@ -76,7 +77,7 @@ public class BrightLineFalsingManager implements FalsingManager {

    private final List<FalsingClassifier> mClassifiers;

    private ProximitySensor.ProximitySensorListener mSensorEventListener = this::onProximityEvent;
    private ThresholdSensor.Listener mSensorEventListener = this::onProximityEvent;

    private final KeyguardUpdateMonitorCallback mKeyguardUpdateCallback =
            new KeyguardUpdateMonitorCallback() {
@@ -240,7 +241,7 @@ public class BrightLineFalsingManager implements FalsingManager {
        mClassifiers.forEach((classifier) -> classifier.onTouchEvent(motionEvent));
    }

    private void onProximityEvent(ProximitySensor.ProximityEvent proximityEvent) {
    private void onProximityEvent(ThresholdSensor.ThresholdSensorEvent proximityEvent) {
        // TODO: some of these classifiers might allow us to abort early, meaning we don't have to
        // make these calls.
        mClassifiers.forEach((classifier) -> classifier.onProximityEvent(proximityEvent));
+1 −1
Original line number Diff line number Diff line
@@ -96,7 +96,7 @@ abstract class FalsingClassifier {
    /**
     * Called when a ProximityEvent occurs (change in near/far).
     */
    void onProximityEvent(ProximitySensor.ProximityEvent proximityEvent) {};
    void onProximityEvent(ProximitySensor.ThresholdSensorEvent proximityEvent) {};

    /**
     * The phone screen has turned on and we need to begin falsing detection.
+2 −2
Original line number Diff line number Diff line
@@ -101,8 +101,8 @@ class ProximityClassifier extends FalsingClassifier {

    @Override
    public void onProximityEvent(
            ProximitySensor.ProximityEvent proximityEvent) {
        boolean near = proximityEvent.getNear();
            ProximitySensor.ThresholdSensorEvent proximityEvent) {
        boolean near = proximityEvent.getBelow();
        long timestampNs = proximityEvent.getTimestampNs();
        logDebug("Sensor is: " + near + " at time " + timestampNs);
        update(near, timestampNs);
Loading