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

Commit 83cab8bf authored by Ricardo Cerqueira's avatar Ricardo Cerqueira Committed by Ricardo Cerqueira
Browse files

Don't enable the light sensor if it's not being used

We want to fully disable the lightsensor when it's not used, for two reasons:
1 - Power savings
2 - Sensors that control the backlight directly need to be disabled when
brightness control is set to manual. Forcibly enabling the sensor when
the screen turns on makes these devices incapable of using manual
brightness.

Change-Id: I64c1114348ff096e0a72b265f6f141d1ecef249c

Fix button backlights that depend on ALS

On a few devices, lighting the buttons when the screen turns on
depends on the lightsensor, regardless of the user preference.
So go back to enabling the sensor whenever the screen turns on, and
enforce the user preference after running through the light settings
once.

Change-Id: I6f036a32315eb7688a9cd11d4bd70dbca1b2fa8b
parent 97b320df
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import android.os.Process;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.WorkSource;
import android.os.SystemProperties;
import android.provider.Settings.SettingNotFoundException;
import android.provider.Settings;
import android.util.EventLog;
@@ -245,7 +246,7 @@ public class PowerManagerService extends IPowerManager.Stub
    private int mButtonBrightnessOverride = -1;
    private int mScreenBrightnessDim;
    private boolean mUseSoftwareAutoBrightness;
    private boolean mAutoBrightessEnabled;
    private boolean mAutoBrightessEnabled = true;
    private int[] mAutoBrightnessLevels;
    private int[] mLcdBacklightValues;
    private int[] mButtonBacklightValues;
@@ -486,6 +487,7 @@ public class PowerManagerService extends IPowerManager.Stub
        }

        public void update(Observable o, Object arg) {

            synchronized (mLocks) {
                // STAY_ON_WHILE_PLUGGED_IN, default to when plugged into AC
                mStayOnConditions = getInt(STAY_ON_WHILE_PLUGGED_IN,
@@ -1759,6 +1761,13 @@ public class PowerManagerService extends IPowerManager.Stub
                    lightFilterStop();
                    resetLastLightValues();
                }
                else if (!mAutoBrightessEnabled && SystemProperties.getBoolean(
                    "ro.hardware.respect_als", false)) {
                    /* Force a light sensor reset since we enabled it
                       when the screen came on */
                    mAutoBrightessEnabled = true;
                    setScreenBrightnessMode(Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
                }
            }
        }
        return err;
@@ -2697,6 +2706,7 @@ public class PowerManagerService extends IPowerManager.Stub
            return;
        }


        // do not allow light sensor value to decrease unless
        // user has actively permitted it
        if (mLightDecrease) {
@@ -2924,6 +2934,7 @@ public class PowerManagerService extends IPowerManager.Stub
        boolean enabled = (mode == SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
        if (mUseSoftwareAutoBrightness && mAutoBrightessEnabled != enabled) {
            mAutoBrightessEnabled = enabled;
            enableLightSensorLocked(mAutoBrightessEnabled);
            if (isScreenOn()) {
                // force recompute of backlight values
                if (mLightSensorValue >= 0) {