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

Unverified Commit 7389f839 authored by Cosmin Tanislav's avatar Cosmin Tanislav Committed by Michael Bestas
Browse files

Partially revert "Assume sensors perform prox check"

This commit partially reverts f40bd8fb
("Assume sensors perform prox check").

Some devices do not have proximity gated sensors, and still require
gating in software.
Partially revert this commit to bring back the ability for sensors to
be proximity gated in software.

Change-Id: Ic3d5c6e98d1767623ace4ee4eea1c52606fabd4a
parent 3c2a5dcb
Loading
Loading
Loading
Loading
+102 −3
Original line number Diff line number Diff line
@@ -525,6 +525,7 @@ public class DozeSensors {
        private final boolean mSettingDefault;
        private final boolean mRequiresTouchscreen;
        private final boolean mRequiresProx;
        private final boolean mPerformsProxCheck;

        // Whether the sensor should only register if the device is in AOD
        private final boolean mRequiresAod;
@@ -546,6 +547,26 @@ public class DozeSensors {
                int pulseReason,
                boolean reportsTouchCoordinates,
                boolean requiresTouchscreen
        ) {
            this(
                    sensor,
                    setting,
                    configured,
                    pulseReason,
                    reportsTouchCoordinates,
                    requiresTouchscreen,
                    true
            );
        }

        TriggerSensor(
                Sensor sensor,
                String setting,
                boolean configured,
                int pulseReason,
                boolean reportsTouchCoordinates,
                boolean requiresTouchscreen,
                boolean performsProxCheck
        ) {
            this(
                    sensor,
@@ -557,6 +578,7 @@ public class DozeSensors {
                    requiresTouchscreen,
                    false /* ignoresSetting */,
                    false /* requiresProx */,
                    performsProxCheck,
                    true /* immediatelyReRegister */,
                    false
            );
@@ -574,6 +596,36 @@ public class DozeSensors {
                boolean requiresProx,
                boolean immediatelyReRegister,
                boolean requiresAod
        ) {
            this(
                    sensor,
                    setting,
                    settingDef,
                    configured,
                    pulseReason,
                    reportsTouchCoordinates,
                    requiresTouchscreen,
                    ignoresSetting,
                    requiresProx,
                    true,
                    immediatelyReRegister,
                    requiresAod
            );
        }

        TriggerSensor(
                Sensor sensor,
                String setting,
                boolean settingDef,
                boolean configured,
                int pulseReason,
                boolean reportsTouchCoordinates,
                boolean requiresTouchscreen,
                boolean ignoresSetting,
                boolean requiresProx,
                boolean performsProxCheck,
                boolean immediatelyReRegister,
                boolean requiresAod
        ) {
            this(
                    new Sensor[]{ sensor },
@@ -585,6 +637,7 @@ public class DozeSensors {
                    requiresTouchscreen,
                    ignoresSetting,
                    requiresProx,
                    performsProxCheck,
                    immediatelyReRegister,
                    DevicePostureController.DEVICE_POSTURE_UNKNOWN,
                    requiresAod
@@ -604,6 +657,38 @@ public class DozeSensors {
                boolean immediatelyReRegister,
                @DevicePostureController.DevicePostureInt int posture,
                boolean requiresAod
        ) {
            this(
                    sensors,
                    setting,
                    settingDef,
                    configured,
                    pulseReason,
                    reportsTouchCoordinates,
                    requiresTouchscreen,
                    ignoresSetting,
                    requiresProx,
                    true,
                    immediatelyReRegister,
                    posture,
                    requiresAod
            );
        }

        TriggerSensor(
                @NonNull Sensor[] sensors,
                String setting,
                boolean settingDef,
                boolean configured,
                int pulseReason,
                boolean reportsTouchCoordinates,
                boolean requiresTouchscreen,
                boolean ignoresSetting,
                boolean requiresProx,
                boolean performsProxCheck,
                boolean immediatelyReRegister,
                @DevicePostureController.DevicePostureInt int posture,
                boolean requiresAod
        ) {
            mSensors = sensors;
            mSetting = setting;
@@ -614,6 +699,7 @@ public class DozeSensors {
            mRequiresTouchscreen = requiresTouchscreen;
            mIgnoresSetting = ignoresSetting;
            mRequiresProx = requiresProx;
            mPerformsProxCheck = performsProxCheck;
            mRequiresAod = requiresAod;
            mPosture = posture;
            mImmediatelyReRegister = immediatelyReRegister;
@@ -741,13 +827,23 @@ public class DozeSensors {
                    screenX = event.values[0];
                    screenY = event.values[1];
                }
                mSensorCallback.onSensorPulse(mPulseReason, screenX, screenY, event.values);
                mSensorCallback.onSensorPulse(mPulseReason, mPerformsProxCheck,
                        screenX, screenY, event.values);
                if (!mRegistered && mImmediatelyReRegister) {
                    updateListening();
                }
            }));
        }

        /**
         * If the sensor itself performs proximity checks, to avoid pocket dialing.
         * Gated sensors don't need to be stopped when the {@link DozeMachine} is
         * {@link DozeMachine.State#DOZE_AOD_PAUSED}.
         */
        public boolean performsProxCheck() {
            return mPerformsProxCheck;
        }

        public void registerSettingsObserver(ContentObserver settingsObserver) {
            if (mConfigured && !TextUtils.isEmpty(mSetting)) {
                mSecureSettings.registerContentObserverForUserSync(
@@ -841,7 +937,8 @@ public class DozeSensors {
                    mDozeLog.traceSensorEventDropped(mPulseReason, "debounce");
                    return;
                }
                mSensorCallback.onSensorPulse(mPulseReason, -1, -1, event.getValues());
                mSensorCallback.onSensorPulse(mPulseReason, true /* sensorPerformsProxCheck */,
                        -1, -1, event.getValues());
            }));
        }
    }
@@ -890,11 +987,13 @@ public class DozeSensors {
        /**
         * Called when a sensor requests a pulse
         * @param pulseReason Requesting sensor, e.g. {@link DozeLog#REASON_SENSOR_PICKUP}
         * @param sensorPerformedProxCheck true if the sensor already checked for FAR proximity.
         * @param screenX the location on the screen where the sensor fired or -1
         *                if the sensor doesn't support reporting screen locations.
         * @param screenY the location on the screen where the sensor fired or -1
         * @param rawValues raw values array from the event.
         */
        void onSensorPulse(int pulseReason, float screenX, float screenY, float[] rawValues);
        void onSensorPulse(int pulseReason, boolean sensorPerformedProxCheck,
                float screenX, float screenY, float[] rawValues);
    }
}
+5 −4
Original line number Diff line number Diff line
@@ -300,7 +300,8 @@ public class DozeTriggers implements DozeMachine.Part {
    }

    @VisibleForTesting
    void onSensor(int pulseReason, float screenX, float screenY, float[] rawValues) {
    void onSensor(int pulseReason, boolean sensorPerformedProxCheck,
            float screenX, float screenY, float[] rawValues) {
        boolean isDoubleTap = pulseReason == DozeLog.REASON_SENSOR_DOUBLE_TAP;
        boolean isTap = pulseReason == DozeLog.REASON_SENSOR_TAP;
        boolean isPickup = pulseReason == DozeLog.REASON_SENSOR_PICKUP;
@@ -317,11 +318,11 @@ public class DozeTriggers implements DozeMachine.Part {
                    mMachine.isExecutingTransition() ? null : mMachine.getState(),
                    pulseReason);
        } else if (isLongPress) {
            requestPulse(pulseReason, true /* alreadyPerformedProxCheck */,
            requestPulse(pulseReason, sensorPerformedProxCheck /* alreadyPerformedProxCheck */,
                    null /* onPulseSuppressedListener */);
        } else if (isWakeOnReach || isQuickPickup) {
            if (isWakeDisplayEvent) {
                requestPulse(pulseReason, true /* alreadyPerformedProxCheck */,
                requestPulse(pulseReason, sensorPerformedProxCheck /* alreadyPerformedProxCheck */,
                        null /* onPulseSuppressedListener */);
            }
        } else {
@@ -357,7 +358,7 @@ public class DozeTriggers implements DozeMachine.Part {
                } else {
                    mDozeHost.extendPulse(pulseReason);
                }
            }, true /* alreadyPerformedProxCheck */, pulseReason);
            }, sensorPerformedProxCheck /* alreadyPerformedProxCheck */, pulseReason);
        }

        if (isPickup && !shouldDropPickupEvent()) {
+2 −2
Original line number Diff line number Diff line
@@ -154,14 +154,14 @@ public class DozeSensorsTest extends SysuiTestCase {
        mWakeLockScreenListener.onSensorChanged(mock(SensorManagerPlugin.SensorEvent.class));
        mTestableLooper.processAllMessages();
        verify(mCallback).onSensorPulse(eq(DozeLog.PULSE_REASON_SENSOR_WAKE_REACH),
                anyFloat(), anyFloat(), eq(null));
                eq(false), anyFloat(), anyFloat(), eq(null));

        mDozeSensors.requestTemporaryDisable();
        reset(mCallback);
        mWakeLockScreenListener.onSensorChanged(mock(SensorManagerPlugin.SensorEvent.class));
        mTestableLooper.processAllMessages();
        verify(mCallback, never()).onSensorPulse(eq(DozeLog.PULSE_REASON_SENSOR_WAKE_REACH),
                anyFloat(), anyFloat(), eq(null));
                eq(false), anyFloat(), anyFloat(), eq(null));
    }

    @Test
+12 −12
Original line number Diff line number Diff line
@@ -327,10 +327,10 @@ public class DozeTriggersTest extends SysuiTestCase {
    @Test
    public void testProximitySensorNotAvailable() {
        mProximitySensor.setSensorAvailable(false);
        mTriggers.onSensor(DozeLog.PULSE_REASON_SENSOR_LONG_PRESS, 100, 100, null);
        mTriggers.onSensor(DozeLog.PULSE_REASON_SENSOR_WAKE_REACH, 100, 100,
        mTriggers.onSensor(DozeLog.PULSE_REASON_SENSOR_LONG_PRESS, false, 100, 100, null);
        mTriggers.onSensor(DozeLog.PULSE_REASON_SENSOR_WAKE_REACH, false, 100, 100,
                new float[]{1});
        mTriggers.onSensor(DozeLog.REASON_SENSOR_TAP, 100, 100, null);
        mTriggers.onSensor(DozeLog.REASON_SENSOR_TAP, false, 100, 100, null);
    }

    @Test
@@ -347,7 +347,7 @@ public class DozeTriggersTest extends SysuiTestCase {
        ).when(mHost).setPulsePending(boolCaptor.capture());

        // WHEN quick pick up is triggered
        mTriggers.onSensor(DozeLog.REASON_SENSOR_QUICK_PICKUP, 100, 100, null);
        mTriggers.onSensor(DozeLog.REASON_SENSOR_QUICK_PICKUP, false, 100, 100, null);

        // THEN request pulse
        verify(mMachine).requestPulse(anyInt());
@@ -364,7 +364,7 @@ public class DozeTriggersTest extends SysuiTestCase {

        // WHEN the pick up gesture is triggered and keyguard isn't occluded
        when(mKeyguardStateController.isOccluded()).thenReturn(false);
        mTriggers.onSensor(DozeLog.REASON_SENSOR_PICKUP, 100, 100, null);
        mTriggers.onSensor(DozeLog.REASON_SENSOR_PICKUP, false, 100, 100, null);

        // THEN wakeup
        verify(mMachine).wakeUp(DozeLog.REASON_SENSOR_PICKUP);
@@ -372,7 +372,7 @@ public class DozeTriggersTest extends SysuiTestCase {

    @Test
    public void test_onSensor_tap() {
        mTriggers.onSensor(DozeLog.REASON_SENSOR_TAP, 100, 200, null);
        mTriggers.onSensor(DozeLog.REASON_SENSOR_TAP, false, 100, 200, null);

        verify(mHost).onSlpiTap(100, 200);
        verify(mMachine).wakeUp(DozeLog.REASON_SENSOR_TAP);
@@ -380,7 +380,7 @@ public class DozeTriggersTest extends SysuiTestCase {

    @Test
    public void test_onSensor_double_tap() {
        mTriggers.onSensor(DozeLog.REASON_SENSOR_DOUBLE_TAP, 100, 200, null);
        mTriggers.onSensor(DozeLog.REASON_SENSOR_DOUBLE_TAP, false, 100, 200, null);

        verify(mHost).onSlpiTap(100, 200);
        verify(mMachine).wakeUp(DozeLog.REASON_SENSOR_DOUBLE_TAP);
@@ -393,7 +393,7 @@ public class DozeTriggersTest extends SysuiTestCase {

        // WHEN the pick up gesture is triggered and keyguard IS occluded
        when(mKeyguardStateController.isOccluded()).thenReturn(true);
        mTriggers.onSensor(DozeLog.REASON_SENSOR_PICKUP, 100, 100, null);
        mTriggers.onSensor(DozeLog.REASON_SENSOR_PICKUP, false, 100, 100, null);

        // THEN never wakeup
        verify(mMachine, never()).wakeUp(DozeLog.REASON_SENSOR_PICKUP);
@@ -412,7 +412,7 @@ public class DozeTriggersTest extends SysuiTestCase {
        float[] rawValues = new float[]{screenX, screenY, misc, major, minor};

        // WHEN longpress gesture is triggered
        mTriggers.onSensor(reason, screenX, screenY, rawValues);
        mTriggers.onSensor(reason, false, screenX, screenY, rawValues);

        // THEN
        // * don't immediately send interrupt
@@ -438,7 +438,7 @@ public class DozeTriggersTest extends SysuiTestCase {
        when(mHost.isPulsePending()).thenReturn(false);
        when(mMachine.isExecutingTransition()).thenReturn(true);

        mTriggers.onSensor(DozeLog.PULSE_REASON_SENSOR_LONG_PRESS, 100, 100, null);
        mTriggers.onSensor(DozeLog.PULSE_REASON_SENSOR_LONG_PRESS, false, 100, 100, null);

        verify(mDozeLog).tracePulseDropped(anyString(), eq(null));
    }
@@ -449,7 +449,7 @@ public class DozeTriggersTest extends SysuiTestCase {
        when(mMachine.getState()).thenReturn(DozeMachine.State.DOZE_AOD_PAUSED);

        // WHEN udfps long-press is triggered
        mTriggers.onSensor(DozeLog.REASON_SENSOR_UDFPS_LONG_PRESS, 100, 100,
        mTriggers.onSensor(DozeLog.REASON_SENSOR_UDFPS_LONG_PRESS, false, 100, 100,
                new float[]{0, 1, 2, 3, 4});

        // THEN the pulse is NOT dropped
@@ -468,7 +468,7 @@ public class DozeTriggersTest extends SysuiTestCase {
        when(mMachine.getState()).thenReturn(DozeMachine.State.DOZE_AOD_PAUSING);

        // WHEN udfps long-press is triggered
        mTriggers.onSensor(DozeLog.REASON_SENSOR_UDFPS_LONG_PRESS, 100, 100,
        mTriggers.onSensor(DozeLog.REASON_SENSOR_UDFPS_LONG_PRESS, false, 100, 100,
                new float[]{0, 1, 2, 3, 4});

        // THEN the pulse is NOT dropped