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

Commit 1ed27213 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "cherry-pick-dropped-sensor" into qt-r1-dev

* changes:
  Fix issue where notif wouldn't HUN
  Assume sensors perform prox check
parents 4dd2150e 19ef3004
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -196,9 +196,6 @@
    <!-- Doze: duration to avoid false pickup gestures triggered by notification vibrations -->
    <integer name="doze_pickup_vibration_threshold">2000</integer>

    <!-- Doze: can we assume the pickup sensor includes a proximity check? -->
    <bool name="doze_pickup_performs_proximity_check">false</bool>

    <!-- Type of a sensor that provides a low-power estimate of the desired display
         brightness, suitable to listen to while the device is asleep (e.g. during
         always-on display) -->
+9 −30
Original line number Diff line number Diff line
@@ -107,8 +107,7 @@ public class DozeSensors {
                        config.dozePickupSensorAvailable(),
                        DozeLog.REASON_SENSOR_PICKUP, false /* touchCoords */,
                        false /* touchscreen */,
                        false /* ignoresSetting */,
                        mDozeParameters.getPickupPerformsProxCheck()),
                        false /* ignoresSetting */),
                new TriggerSensor(
                        findSensorWithType(config.doubleTapSensorType()),
                        Settings.Secure.DOZE_DOUBLE_TAP_GESTURE,
@@ -205,11 +204,8 @@ public class DozeSensors {
    public void updateListening() {
        boolean anyListening = false;
        for (TriggerSensor s : mSensors) {
            // We don't want to be listening while we're PAUSED (prox sensor is covered)
            // except when the sensor is already gated by prox.
            boolean listen = mListening && (!mPaused || s.performsProxCheck());
            s.setListening(listen);
            if (listen) {
            s.setListening(mListening);
            if (mListening) {
                anyListening = true;
            }
        }
@@ -391,7 +387,6 @@ public class DozeSensors {
        private final boolean mReportsTouchCoordinates;
        private final boolean mSettingDefault;
        private final boolean mRequiresTouchscreen;
        private final boolean mSensorPerformsProxCheck;

        protected boolean mRequested;
        protected boolean mRegistered;
@@ -408,14 +403,12 @@ public class DozeSensors {
                boolean configured, int pulseReason, boolean reportsTouchCoordinates,
                boolean requiresTouchscreen) {
            this(sensor, setting, settingDef, configured, pulseReason, reportsTouchCoordinates,
                    requiresTouchscreen, false /* ignoresSetting */,
                    false /* sensorPerformsProxCheck */);
                    requiresTouchscreen, false /* ignoresSetting */);
        }

        private TriggerSensor(Sensor sensor, String setting, boolean settingDef,
                boolean configured, int pulseReason, boolean reportsTouchCoordinates,
                boolean requiresTouchscreen, boolean ignoresSetting,
                boolean sensorPerformsProxCheck) {
                boolean requiresTouchscreen, boolean ignoresSetting) {
            mSensor = sensor;
            mSetting = setting;
            mSettingDefault = settingDef;
@@ -424,7 +417,6 @@ public class DozeSensors {
            mReportsTouchCoordinates = reportsTouchCoordinates;
            mRequiresTouchscreen = requiresTouchscreen;
            mIgnoresSetting = ignoresSetting;
            mSensorPerformsProxCheck = sensorPerformsProxCheck;
        }

        public void setListening(boolean listen) {
@@ -498,23 +490,13 @@ public class DozeSensors {
                    screenX = event.values[0];
                    screenY = event.values[1];
                }
                mCallback.onSensorPulse(mPulseReason, mSensorPerformsProxCheck, screenX, screenY,
                        event.values);
                mCallback.onSensorPulse(mPulseReason, 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 mSensorPerformsProxCheck;
        }

        public void registerSettingsObserver(ContentObserver settingsObserver) {
            if (mConfigured && !TextUtils.isEmpty(mSetting)) {
                mResolver.registerContentObserver(
@@ -610,8 +592,7 @@ public class DozeSensors {
                    return;
                }
                if (DEBUG) Log.d(TAG, "onSensorEvent: " + triggerEventToString(event));
                mCallback.onSensorPulse(mPulseReason, true /* sensorPerformsProxCheck */, -1, -1,
                        event.getValues());
                mCallback.onSensorPulse(mPulseReason, -1, -1, event.getValues());
            }));
        }
    }
@@ -621,13 +602,11 @@ 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, boolean sensorPerformedProxCheck,
                float screenX, float screenY, float[] rawValues);
        void onSensorPulse(int pulseReason, float screenX, float screenY, float[] rawValues);
    }
}
+28 −9
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.util.Preconditions;
import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.dock.DockManager;
import com.android.systemui.statusbar.phone.DozeParameters;
import com.android.systemui.util.Assert;
@@ -156,8 +157,7 @@ public class DozeTriggers implements DozeMachine.Part {
    }

    @VisibleForTesting
    void onSensor(int pulseReason, boolean sensorPerformedProxCheck,
            float screenX, float screenY, float[] rawValues) {
    void onSensor(int pulseReason, 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;
@@ -169,10 +169,11 @@ public class DozeTriggers implements DozeMachine.Part {
        if (isWakeDisplay) {
            onWakeScreen(wakeEvent, mMachine.isExecutingTransition() ? null : mMachine.getState());
        } else if (isLongPress) {
            requestPulse(pulseReason, sensorPerformedProxCheck, null /* onPulseSupressedListener */);
            requestPulse(pulseReason, true /* alreadyPerformedProxCheck */,
                    null /* onPulseSupressedListener */);
        } else if (isWakeLockScreen) {
            if (wakeEvent) {
                requestPulse(pulseReason, sensorPerformedProxCheck,
                requestPulse(pulseReason, true /* alreadyPerformedProxCheck */,
                        null /* onPulseSupressedListener */);
            }
        } else {
@@ -191,8 +192,7 @@ public class DozeTriggers implements DozeMachine.Part {
                } else {
                    mDozeHost.extendPulse(pulseReason);
                }
            }, sensorPerformedProxCheck
                    || (mDockManager != null && mDockManager.isDocked()), pulseReason);
            }, true /* alreadyPerformedProxCheck */, pulseReason);
        }

        if (isPickup) {
@@ -278,7 +278,7 @@ public class DozeTriggers implements DozeMachine.Part {
                            .setType(MetricsEvent.TYPE_OPEN)
                            .setSubtype(DozeLog.REASON_SENSOR_WAKE_UP));
                }
            }, false /* alreadyPerformedProxCheck */, DozeLog.REASON_SENSOR_WAKE_UP);
            }, true /* alreadyPerformedProxCheck */, DozeLog.REASON_SENSOR_WAKE_UP);
        } else {
            boolean paused = (state == DozeMachine.State.DOZE_AOD_PAUSED);
            boolean pausing = (state == DozeMachine.State.DOZE_AOD_PAUSING);
@@ -417,6 +417,9 @@ public class DozeTriggers implements DozeMachine.Part {
        mDozeSensors.dump(pw);
    }

    /**
     * @see DozeSensors.ProxSensor
     */
    private abstract class ProximityCheck implements SensorEventListener, Runnable {
        private static final int TIMEOUT_DELAY_MS = 500;

@@ -428,12 +431,18 @@ public class DozeTriggers implements DozeMachine.Part {
        private boolean mRegistered;
        private boolean mFinished;
        private float mMaxRange;
        private boolean mUsingBrightnessSensor;

        protected abstract void onProximityResult(int result);

        public void check() {
            Preconditions.checkState(!mFinished && !mRegistered);
            final Sensor sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
            Sensor sensor = DozeSensors.findSensorWithType(mSensorManager,
                    mContext.getString(R.string.doze_brightness_sensor_type));
            mUsingBrightnessSensor = sensor != null;
            if (sensor == null) {
                sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
            }
            if (sensor == null) {
                if (DozeMachine.DEBUG) Log.d(TAG, "ProxCheck: No sensor found");
                finishWithResult(RESULT_UNKNOWN);
@@ -449,6 +458,9 @@ public class DozeTriggers implements DozeMachine.Part {
            mRegistered = true;
        }

        /**
         * @see DozeSensors.ProxSensor#onSensorChanged(SensorEvent)
         */
        @Override
        public void onSensorChanged(SensorEvent event) {
            if (event.values.length == 0) {
@@ -458,7 +470,14 @@ public class DozeTriggers implements DozeMachine.Part {
                if (DozeMachine.DEBUG) {
                    Log.d(TAG, "ProxCheck: Event: value=" + event.values[0] + " max=" + mMaxRange);
                }
                final boolean isNear = event.values[0] < mMaxRange;
                final boolean isNear;
                if (mUsingBrightnessSensor) {
                    // The custom brightness sensor is gated by the proximity sensor and will
                    // return 0 whenever prox is covered.
                    isNear = event.values[0] == 0;
                } else {
                    isNear = event.values[0] < mMaxRange;
                }
                finishWithResult(isNear ? RESULT_NEAR : RESULT_FAR);
            }
        }
+0 −4
Original line number Diff line number Diff line
@@ -207,10 +207,6 @@ public class DozeParameters implements TunerService.Tunable,
        return SystemProperties.get(propName, mContext.getString(resId));
    }

    public boolean getPickupPerformsProxCheck() {
        return mContext.getResources().getBoolean(R.bool.doze_pickup_performs_proximity_check);
    }

    public int getPulseVisibleDurationExtended() {
        return 2 * getPulseVisibleDuration();
    }
+0 −1
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@ public class DozeConfigurationUtil {
        when(params.getPulseOnSigMotion()).thenReturn(false);
        when(params.getPickupVibrationThreshold()).thenReturn(0);
        when(params.getProxCheckBeforePulse()).thenReturn(true);
        when(params.getPickupPerformsProxCheck()).thenReturn(true);
        when(params.getPolicy()).thenReturn(mock(AlwaysOnDisplayPolicy.class));
        when(params.doubleTapReportsTouchCoordinates()).thenReturn(false);
        when(params.getDisplayNeedsBlanking()).thenReturn(false);
Loading