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

Commit 98d3198b authored by Adrian Roos's avatar Adrian Roos
Browse files

AOD: Unregister touchscreen sensors while pulsing

While we're pulsing, the touch screen is fully on. Keeping touchscreen
sensors registered can lead to the sensorhub and kernel touch driver
racing on who gets to control the touchscreen; the losing party may
also logspam and consume increased power.

To avoid this, we unregister touchscreen sensors when turning the screen
on.

Change-Id: Ie236d0a40c92d7fc544bd34ff883e613915c8e46
Fixes: 64160164
Test: receive notification; adb shell dumpsys sensorservice, verify double tap sensor is not registered; verify it is again registered after swiping away the notification.
parent 273bb516
Loading
Loading
Loading
Loading
+23 −7
Original line number Diff line number Diff line
@@ -87,25 +87,29 @@ public class DozeSensors {
                        mSensorManager.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION),
                        null /* setting */,
                        dozeParameters.getPulseOnSigMotion(),
                        DozeLog.PULSE_REASON_SENSOR_SIGMOTION, false /* touchCoords */),
                        DozeLog.PULSE_REASON_SENSOR_SIGMOTION, false /* touchCoords */,
                        false /* touchscreen */),
                mPickupSensor = new TriggerSensor(
                        mSensorManager.getDefaultSensor(Sensor.TYPE_PICK_UP_GESTURE),
                        Settings.Secure.DOZE_PULSE_ON_PICK_UP,
                        config.pulseOnPickupAvailable(),
                        DozeLog.PULSE_REASON_SENSOR_PICKUP, false /* touchCoords */),
                        DozeLog.PULSE_REASON_SENSOR_PICKUP, false /* touchCoords */,
                        false /* touchscreen */),
                new TriggerSensor(
                        findSensorWithType(config.doubleTapSensorType()),
                        Settings.Secure.DOZE_PULSE_ON_DOUBLE_TAP,
                        true /* configured */,
                        DozeLog.PULSE_REASON_SENSOR_DOUBLE_TAP,
                        dozeParameters.doubleTapReportsTouchCoordinates()),
                        dozeParameters.doubleTapReportsTouchCoordinates(),
                        true /* touchscreen */),
                new TriggerSensor(
                        findSensorWithType(config.longPressSensorType()),
                        Settings.Secure.DOZE_PULSE_ON_LONG_PRESS,
                        false /* settingDef */,
                        true /* configured */,
                        DozeLog.PULSE_REASON_SENSOR_LONG_PRESS,
                        true /* reports touch coordinates */),
                        true /* reports touch coordinates */,
                        true /* touchscreen */),
        };

        mProxSensor = new ProxSensor();
@@ -141,6 +145,15 @@ public class DozeSensors {
        }
    }

    /** Set the listening state of only the sensors that require the touchscreen. */
    public void setTouchscreenSensorsListening(boolean listening) {
        for (TriggerSensor sensor : mSensors) {
            if (sensor.mRequiresTouchscreen) {
                sensor.setListening(listening);
            }
        }
    }

    public void reregisterAllSensors() {
        for (TriggerSensor s : mSensors) {
            s.setListening(false);
@@ -278,25 +291,28 @@ public class DozeSensors {
        final String mSetting;
        final boolean mReportsTouchCoordinates;
        final boolean mSettingDefault;
        final boolean mRequiresTouchscreen;

        private boolean mRequested;
        private boolean mRegistered;
        private boolean mDisabled;

        public TriggerSensor(Sensor sensor, String setting, boolean configured, int pulseReason,
                boolean reportsTouchCoordinates) {
                boolean reportsTouchCoordinates, boolean requiresTouchscreen) {
            this(sensor, setting, true /* settingDef */, configured, pulseReason,
                    reportsTouchCoordinates);
                    reportsTouchCoordinates, requiresTouchscreen);
        }

        public TriggerSensor(Sensor sensor, String setting, boolean settingDef,
                boolean configured, int pulseReason, boolean reportsTouchCoordinates) {
                boolean configured, int pulseReason, boolean reportsTouchCoordinates,
                boolean requiresTouchscreen) {
            mSensor = sensor;
            mSetting = setting;
            mSettingDefault = settingDef;
            mConfigured = configured;
            mPulseReason = pulseReason;
            mReportsTouchCoordinates = reportsTouchCoordinates;
            mRequiresTouchscreen = requiresTouchscreen;
        }

        public void setListening(boolean listen) {
+1 −0
Original line number Diff line number Diff line
@@ -198,6 +198,7 @@ public class DozeTriggers implements DozeMachine.Part {
                mDozeSensors.setListening(false);
                break;
            case DOZE_PULSING:
                mDozeSensors.setTouchscreenSensorsListening(false);
                mDozeSensors.setProxListening(true);
                break;
            case FINISH: