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

Commit 9aa22ad0 authored by Danny Baumann's avatar Danny Baumann Committed by Gerrit Code Review
Browse files

Merge "Fix race condition in backlight adjustment." into cm-10.1

parents d2393efe 5393aa51
Loading
Loading
Loading
Loading
+16 −3
Original line number Diff line number Diff line
@@ -118,6 +118,7 @@ final class DisplayPowerController {
    private static final int MSG_UPDATE_POWER_STATE = 1;
    private static final int MSG_PROXIMITY_SENSOR_DEBOUNCED = 2;
    private static final int MSG_LIGHT_SENSOR_DEBOUNCED = 3;
    private static final int MSG_UPDATE_BACKLIGHT_SETTINGS = 4;

    private static final int PROXIMITY_UNKNOWN = -1;
    private static final int PROXIMITY_NEGATIVE = 0;
@@ -390,9 +391,11 @@ final class DisplayPowerController {
            final ContentObserver observer = new ContentObserver(mHandler) {
                @Override
                public void onChange(boolean selfChange, Uri uri) {
                    mAutoBrightnessSettingsChanged = true;
                    updateAutomaticBrightnessSettings();
                    updatePowerState();
                    // As both LUX and BACKLIGHT might be changed at the same time, there's
                    // a potential race condition. As the settings provider API doesn't give
                    // us transactions to avoid them, wait a little until things settle down
                    mHandler.removeMessages(MSG_UPDATE_BACKLIGHT_SETTINGS);
                    mHandler.sendEmptyMessageDelayed(MSG_UPDATE_BACKLIGHT_SETTINGS, 1000);
                }
            };

@@ -486,6 +489,10 @@ final class DisplayPowerController {
    }

    private static Spline createAutoBrightnessSpline(int[] lux, int[] brightness) {
        if (lux.length < 2 || lux.length != (brightness.length - 1)) {
            return null;
        }

        try {
            final int n = brightness.length;
            float[] x = new float[n];
@@ -1361,6 +1368,12 @@ final class DisplayPowerController {
                case MSG_LIGHT_SENSOR_DEBOUNCED:
                    debounceLightSensor();
                    break;

                case MSG_UPDATE_BACKLIGHT_SETTINGS:
                    mAutoBrightnessSettingsChanged = true;
                    updateAutomaticBrightnessSettings();
                    updatePowerState();
                    break;
            }
        }
    }