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

Commit 19ef3004 authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Fix issue where notif wouldn't HUN

DozeSensors and DozeTriggers have code that perform proximity
checks in slightly different ways. DozeSensors was updated as
part of ag/9185335 bug DozeTriggers wasn't.

Bug: 9185335
Fixes: 140701062
Bug: 138765669
Test: partially cover prox, send notification, look at screen
Change-Id: Ic85181abb3edd4c77c427faefa4cd6b9c35b498f
Merged-In: Ic85181abb3edd4c77c427faefa4cd6b9c35b498f
parent 9bab4a26
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -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,6 +431,7 @@ public class DozeTriggers implements DozeMachine.Part {
        private boolean mRegistered;
        private boolean mFinished;
        private float mMaxRange;
        private boolean mUsingBrightnessSensor;

        protected abstract void onProximityResult(int result);

@@ -435,6 +439,7 @@ public class DozeTriggers implements DozeMachine.Part {
            Preconditions.checkState(!mFinished && !mRegistered);
            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);
            }
@@ -453,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) {
@@ -462,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);
            }
        }