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

Commit cf06eb3a authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Fix sensor triggering issue

Code duplication was causing the wrong sensor to be re-registered,
also, binned brightness isn't a drop-in replacement for proximity
as expected.

Brightness can be low when prox is not covered, the correct behavior
is to verify if brightness is not 0

Test: manual, covering sensor
Test: atest DozeSensorsTest
Fixes: 139298207
Change-Id: I8673e7d9bcb56d7a34741cfad35cf397d976c18d
parent 82aec2e9
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -292,6 +292,7 @@ public class DozeSensors {
        final AlarmTimeout mCooldownTimer;
        final AlwaysOnDisplayPolicy mPolicy;
        final Sensor mSensor;
        final boolean mUsingBrightnessSensor;

        public ProxSensor(AlwaysOnDisplayPolicy policy) {
            mPolicy = policy;
@@ -302,6 +303,7 @@ public class DozeSensors {
            // if available.
            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);
            }
@@ -331,8 +333,7 @@ public class DozeSensors {
                return;
            }
            if (register) {
                mRegistered = mSensorManager.registerListener(this,
                        mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY),
                mRegistered = mSensorManager.registerListener(this, mSensor,
                        SensorManager.SENSOR_DELAY_NORMAL, mHandler);
            } else {
                mSensorManager.unregisterListener(this);
@@ -345,7 +346,13 @@ public class DozeSensors {
        public void onSensorChanged(android.hardware.SensorEvent event) {
            if (DEBUG) Log.d(TAG, "onSensorChanged " + event);

            if (mUsingBrightnessSensor) {
                // The custom brightness sensor is gated by the proximity sensor and will return 0
                // whenever prox is covered.
                mCurrentlyFar = event.values[0] > 0;
            } else {
                mCurrentlyFar = event.values[0] >= event.sensor.getMaximumRange();
            }
            mProxCallback.accept(mCurrentlyFar);

            long now = SystemClock.elapsedRealtime();