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

Commit 10005858 authored by Cosmin Tanislav's avatar Cosmin Tanislav Committed by Jan Altensen
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 6422e600
Loading
Loading
Loading
Loading
+95 −4
Original line number Diff line number Diff line
@@ -492,6 +492,7 @@ public class DozeSensors {
        private final boolean mSettingDefault;
        private final boolean mRequiresTouchscreen;
        private final boolean mRequiresProx;
        private final boolean mPerformsProxCheck;

        protected boolean mRequested;
        protected boolean mRegistered;
@@ -506,6 +507,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,
@@ -516,7 +537,8 @@ public class DozeSensors {
                    reportsTouchCoordinates,
                    requiresTouchscreen,
                    false /* ignoresSetting */,
                    false /* requiresProx */
                    false /* requiresProx */,
                    performsProxCheck
            );
        }

@@ -530,6 +552,32 @@ public class DozeSensors {
                boolean requiresTouchscreen,
                boolean ignoresSetting,
                boolean requiresProx
        ) {
            this(
                    sensor,
                    setting,
                    settingDef,
                    configured,
                    pulseReason,
                    reportsTouchCoordinates,
                    requiresTouchscreen,
                    ignoresSetting,
                    requiresProx,
                    true
            );
        }

        TriggerSensor(
                Sensor sensor,
                String setting,
                boolean settingDef,
                boolean configured,
                int pulseReason,
                boolean reportsTouchCoordinates,
                boolean requiresTouchscreen,
                boolean ignoresSetting,
                boolean requiresProx,
                boolean performsProxCheck
        ) {
            this(
                    new Sensor[]{ sensor },
@@ -541,6 +589,7 @@ public class DozeSensors {
                    requiresTouchscreen,
                    ignoresSetting,
                    requiresProx,
                    performsProxCheck,
                    DevicePostureController.DEVICE_POSTURE_UNKNOWN
            );
        }
@@ -556,6 +605,34 @@ public class DozeSensors {
                boolean ignoresSetting,
                boolean requiresProx,
                @DevicePostureController.DevicePostureInt int posture
        ) {
            this(
                    sensors,
                    setting,
                    settingDef,
                    configured,
                    pulseReason,
                    reportsTouchCoordinates,
                    requiresTouchscreen,
                    ignoresSetting,
                    requiresProx,
                    true,
                    posture
            );
        }

        TriggerSensor(
                @NonNull Sensor[] sensors,
                String setting,
                boolean settingDef,
                boolean configured,
                int pulseReason,
                boolean reportsTouchCoordinates,
                boolean requiresTouchscreen,
                boolean ignoresSetting,
                boolean requiresProx,
                boolean performsProxCheck,
                @DevicePostureController.DevicePostureInt int posture
        ) {
            mSensors = sensors;
            mSetting = setting;
@@ -566,6 +643,7 @@ public class DozeSensors {
            mRequiresTouchscreen = requiresTouchscreen;
            mIgnoresSetting = ignoresSetting;
            mRequiresProx = requiresProx;
            mPerformsProxCheck = performsProxCheck;
            mPosture = posture;
        }

@@ -701,13 +779,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) {
                    updateListening();  // reregister, this sensor only fires once
                }
            }));
        }

        /**
         * 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.registerContentObserverForUser(
@@ -802,7 +890,8 @@ public class DozeSensors {
                    return;
                }
                if (DEBUG) Log.d(TAG, "onSensorEvent: " + triggerEventToString(event));
                mSensorCallback.onSensorPulse(mPulseReason, -1, -1, event.getValues());
                mSensorCallback.onSensorPulse(mPulseReason, true /* sensorPerformsProxCheck */,
                        -1, -1, event.getValues());
            }));
        }
    }
@@ -847,11 +936,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
@@ -282,7 +282,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;
@@ -299,11 +300,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 {
@@ -338,7 +339,7 @@ public class DozeTriggers implements DozeMachine.Part {
                } else {
                    mDozeHost.extendPulse(pulseReason);
                }
            }, true /* alreadyPerformedProxCheck */, pulseReason);
            }, sensorPerformedProxCheck /* alreadyPerformedProxCheck */, pulseReason);
        }

        if (isPickup && !shouldDropPickupEvent()) {