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

Commit 45dc38d9 authored by Mike Kasick's avatar Mike Kasick
Browse files

Separate configuration of auto-brightness for button/keyboard backlights.

Presently, light-sensor based automatic brightness
(config_autoBrightnessLevels) controls both button and keyboard backlights
in addition to the screen backlight.  Unfortunately auto-brightness for
button/keyboard backlights doesn't work well on devices (e.g., epicmtd)
with neither (i) dimmable button/keyboard backlights (so when they're on,
they're very bright even if the screen backlight is relatively dark) nor
(ii) identifiable surface features on capacitive buttons (so they can't be
found if the backlights are permanently turned off).

For these devices, the non-auto-brightness behavior of button/keyboard
backlights, whereby they turn on during screen-on events and user activity
and timeout-to-off shortly thereafter, is preferable.  Thus, this commit
adds a config option, config_autoBrightnessButtonKeyboard (defaults to
true), that when disabled allows for automatic brightness control of the
screen backlight, but retains the timeout-based behavior for button and
keyboard backlights.

Also addressed is a bug that disables the button and keyboard backlights on
screen unlock, and reenables the backlights on touch events so that
capacitive keys may be located.
parent 028000af
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -491,6 +491,10 @@
    <integer-array name="config_autoBrightnessLcdBacklightValues">
    </integer-array>

    <!-- Flag indicating whether we should enable automatic brightness for
         the button and keyboard backlights. -->
    <bool name="config_autoBrightnessButtonKeyboard">true</bool>

    <!-- Array of output values for button backlight corresponding to the LUX values
         in the config_autoBrightnessLevels array.  This array should have size one greater
         than the size of the config_autoBrightnessLevels array.
+20 −8
Original line number Diff line number Diff line
@@ -256,6 +256,13 @@ public class PowerManagerService extends IPowerManager.Stub
    private long mWarningSpewThrottleTime;
    private int mAnimationSetting = ANIM_SETTING_OFF;

    // When using software auto-brightness, determines whether (true) button
    // and keyboard backlights should also be under automatic brightness
    // control (i.e., for dimmable backlights), or (false) if they should use
    // hard-coded brightness settings that timeout-to-off in subsequent screen
    // power states.
    private boolean mAutoBrightnessButtonKeyboard;

    // Must match with the ISurfaceComposer constants in C++.
    private static final int ANIM_SETTING_ON = 0x01;
    private static final int ANIM_SETTING_OFF = 0x10;
@@ -637,6 +644,8 @@ public class PowerManagerService extends IPowerManager.Stub
        // read settings for auto-brightness
        mUseSoftwareAutoBrightness = resources.getBoolean(
                com.android.internal.R.bool.config_automatic_brightness_available);
        mAutoBrightnessButtonKeyboard = mUseSoftwareAutoBrightness && resources.getBoolean(
                com.android.internal.R.bool.config_autoBrightnessButtonKeyboard);
        if (mUseSoftwareAutoBrightness) {
            mAutoBrightnessLevels = resources.getIntArray(
                    com.android.internal.R.array.config_autoBrightnessLevels);
@@ -840,7 +849,7 @@ public class PowerManagerService extends IPowerManager.Stub
            switch (wl.flags & LOCK_MASK)
            {
                case PowerManager.FULL_WAKE_LOCK:
                    if (mUseSoftwareAutoBrightness) {
                    if (mAutoBrightnessButtonKeyboard) {
                        wl.minState = SCREEN_BRIGHT;
                    } else {
                        wl.minState = (mKeyboardVisible ? ALL_BRIGHT : SCREEN_BUTTON_BRIGHT);
@@ -1207,6 +1216,7 @@ public class PowerManagerService extends IPowerManager.Stub
                    + " mLightSensorButtonBrightness=" + mLightSensorButtonBrightness
                    + " mLightSensorKeyboardBrightness=" + mLightSensorKeyboardBrightness);
            pw.println("  mUseSoftwareAutoBrightness=" + mUseSoftwareAutoBrightness);
            pw.println("  mAutoBrightnessButtonKeyboard=" + mAutoBrightnessButtonKeyboard);
            pw.println("  mAutoBrightessEnabled=" + mAutoBrightessEnabled);
            mScreenBrightness.dump(pw, "  mScreenBrightness: ");

@@ -1788,7 +1798,7 @@ public class PowerManagerService extends IPowerManager.Stub
                return;
            }

            if (!mBootCompleted && !mUseSoftwareAutoBrightness) {
            if (!mBootCompleted && !mAutoBrightnessButtonKeyboard) {
                newState |= ALL_BRIGHT;
            }

@@ -2301,7 +2311,7 @@ public class PowerManagerService extends IPowerManager.Stub
        }
        if (mButtonBrightnessOverride >= 0) {
            brightness = mButtonBrightnessOverride;
        } else if (mLightSensorButtonBrightness >= 0 && mUseSoftwareAutoBrightness) {
        } else if (mLightSensorButtonBrightness >= 0 && mAutoBrightnessButtonKeyboard) {
            brightness = mLightSensorButtonBrightness;
        }
        if (brightness > 0) {
@@ -2323,7 +2333,7 @@ public class PowerManagerService extends IPowerManager.Stub
            brightness = 0;
        } else if (mButtonBrightnessOverride >= 0) {
            brightness = mButtonBrightnessOverride;
        } else if (mLightSensorKeyboardBrightness >= 0 && mUseSoftwareAutoBrightness) {
        } else if (mLightSensorKeyboardBrightness >= 0 && mAutoBrightnessButtonKeyboard) {
            brightness =  mLightSensorKeyboardBrightness;
        }
        if (brightness > 0) {
@@ -2446,9 +2456,11 @@ public class PowerManagerService extends IPowerManager.Stub
            if (mLastEventTime <= time || force) {
                mLastEventTime = time;
                if ((mUserActivityAllowed && !mProximitySensorActive) || force) {
                    // Only turn on button backlights if a button was pressed
                    // and auto brightness is disabled
                    if (eventType == BUTTON_EVENT && !mUseSoftwareAutoBrightness) {
                    if (!mAutoBrightnessButtonKeyboard) {
                        // Turn on button (and keyboard) backlights on any event, so that they
                        // don't suddenly disappear when the lock screen is unlocked (OTHER_EVENT),
                        // and so capacitive buttons can be found on devices where they lack
                        // identifying surface features.
                        mUserState = (mKeyboardVisible ? ALL_BRIGHT : SCREEN_BUTTON_BRIGHT);
                    } else {
                        // don't clear button/keyboard backlights when the screen is touched.
@@ -3208,7 +3220,7 @@ public class PowerManagerService extends IPowerManager.Stub
        // wait until sensors are enabled before turning on screen.
        // some devices will not activate the light sensor properly on boot
        // unless we do this.
        if (mUseSoftwareAutoBrightness) {
        if (mAutoBrightnessButtonKeyboard) {
            // turn the screen on
            setPowerState(SCREEN_BRIGHT);
        } else {