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

Commit 00cd27f6 authored by Mike Kasick's avatar Mike Kasick Committed by Ricardo Cerqueira
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.

Additional fixes for button/keyboard backlight auto-brightness.

- Use sensor-determined brightness values when the button and/or keyboard
  lights are on, even if button/keyboard auto-brightness is disabled, since
  users may want to specify a custom brightness setting that disables the
  button/keyboard backlight entirely in low-ambient light situations.

- When button/keyboard auto-brightness is disabled, don't update button and
  keyboard brightnesses immediately if ambient light (the sensor) changes,
  as this may reactivate these lights after they've turned off in absense of
  user activity.  This is a particular problem when watching video or other
  circumstances when the lights are not expected to reactivate.

Change-Id: Idb26aa907ce4b04fb1f52a884e4e5bcb40fe695f
parent d72a37ce
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -882,4 +882,8 @@
    <!-- Workaround for devices with broken keyboards -->
    <bool name="config_forceDisableHardwareKeyboard">false</bool>

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

</resources>
+1 −0
Original line number Diff line number Diff line
@@ -3660,5 +3660,6 @@
  <java-symbol type="string" name="config_legacyUmsLunFile" />
  <java-symbol type="bool" name="config_forceDisableHardwareKeyboard" />
  <java-symbol type="array" name="config_telephony_set_audioparameters" />
  <java-symbol type="bool" name="config_autoBrightnessButtonKeyboard" />

</resources>
+32 −12
Original line number Diff line number Diff line
@@ -292,6 +292,13 @@ public class PowerManagerService extends IPowerManager.Stub
    private int mAnimationSetting = ANIM_SETTING_OFF;
    private float mWindowScaleAnimation;

    // 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;
@@ -643,6 +650,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);
@@ -868,7 +877,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);
@@ -1237,6 +1246,7 @@ public class PowerManagerService extends IPowerManager.Stub
                    + " mLightSensorButtonBrightness=" + mLightSensorButtonBrightness
                    + " mLightSensorKeyboardBrightness=" + mLightSensorKeyboardBrightness);
            pw.println("  mUseSoftwareAutoBrightness=" + mUseSoftwareAutoBrightness);
            pw.println("  mAutoBrightnessButtonKeyboard=" + mAutoBrightnessButtonKeyboard);
            pw.println("  mAutoBrightessEnabled=" + mAutoBrightessEnabled);
            mScreenBrightnessAnimator.dump(pw, "mScreenBrightnessAnimator: ");

@@ -1817,7 +1827,7 @@ public class PowerManagerService extends IPowerManager.Stub
                return;
            }

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

@@ -2213,10 +2223,18 @@ public class PowerManagerService extends IPowerManager.Stub
                        }
                        long elapsed = SystemClock.uptimeMillis() - tStart;
                        if ((mask & BUTTON_BRIGHT_BIT) != 0) {
                            mButtonLight.setBrightness(value);
                            // Use sensor-determined brightness values when the button (or keyboard)
                            // light is on, since users may want to specify a custom brightness setting
                            // that disables the button (or keyboard) backlight entirely in low-ambient
                            // light situations.
                            mButtonLight.setBrightness(mLightSensorButtonBrightness >= 0 && value > 0 ?
                                    mLightSensorButtonBrightness : value);


                        }
                        if ((mask & KEYBOARD_BRIGHT_BIT) != 0) {
                            mKeyboardLight.setBrightness(value);
                            mKeyboardLight.setBrightness(mLightSensorKeyboardBrightness >= 0 && value > 0 ?
                                    mLightSensorKeyboardBrightness : value);
                        }

                        if (elapsed > 100) {
@@ -2410,7 +2428,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) {
@@ -2432,7 +2450,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) {
@@ -2562,9 +2580,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.
@@ -2739,10 +2759,10 @@ public class PowerManagerService extends IPowerManager.Stub
                                SCREEN_BRIGHT_BIT, steps * NOMINAL_FRAME_TIME_MS);
                    }
                }
                if (mButtonBrightnessOverride < 0) {
                if (mButtonBrightnessOverride < 0 && mAutoBrightnessButtonKeyboard) {
                    mButtonLight.setBrightness(buttonValue);
                }
                if (mButtonBrightnessOverride < 0 || !mKeyboardVisible) {
                if ((mButtonBrightnessOverride < 0 || !mKeyboardVisible) && mAutoBrightnessButtonKeyboard) {
                    mKeyboardLight.setBrightness(keyboardValue);
                }
            }
@@ -3079,7 +3099,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 {