Skip to content
Browse files

Keyboard backlight for non-autobrightness fix

  • Loading branch information...
1 parent b28f884 commit 07bb1e44a90a49a1919b1a92ac2bf238a018d4d0 Jeff Corcoran committed with existz Apr 3, 2012
Showing with 39 additions and 13 deletions.
  1. +39 −13 services/java/com/android/server/PowerManagerService.java
View
52 services/java/com/android/server/PowerManagerService.java
@@ -31,6 +31,7 @@
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Resources;
+import android.content.res.Configuration;
import android.database.ContentObserver;
import android.database.Cursor;
import android.hardware.Sensor;
@@ -178,6 +179,14 @@
private int mScreenOffReason;
private int mUserState;
private boolean mKeyboardVisible = false;
+ private boolean mHardwareKeyboardVisible() { return mContext.getResources().getConfiguration().hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO; }
+ private boolean mAutoBrightnessToggledOn() {
+ try {
+ return Settings.System.getInt(mContext.getContentResolver(), "screen_brightness_mode") == SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
+ } catch (SettingNotFoundException snfe) {
+ return false;
+ }
+ }
private boolean mUserActivityAllowed = true;
private int mProximityWakeLockCount = 0;
private boolean mProximitySensorEnabled = false;
@@ -851,7 +860,7 @@ public void acquireWakeLockLocked(int flags, IBinder lock, int uid, int pid, Str
switch (wl.flags & LOCK_MASK)
{
case PowerManager.FULL_WAKE_LOCK:
- if (mAutoBrightnessButtonKeyboard) {
+ if (mAutoBrightnessToggledOn()) {
wl.minState = SCREEN_BRIGHT;
} else {
wl.minState = (mKeyboardVisible ? ALL_BRIGHT : SCREEN_BUTTON_BRIGHT);
@@ -1681,8 +1690,8 @@ public void setButtonBrightnessOverride(int brightness) {
synchronized (mLocks) {
if (mButtonBrightnessOverride != brightness) {
mButtonBrightnessOverride = brightness;
- if (isScreenOn()) {
- updateLightsLocked(mPowerState, BUTTON_BRIGHT_BIT | KEYBOARD_BRIGHT_BIT);
+ if (isScreenOn() && brightness >= 0) {
+ updateLightsLocked(mPowerState, (mHardwareKeyboardVisible() ? SCREEN_BUTTON_BRIGHT : LIGHTS_MASK));
}
}
}
@@ -1807,7 +1816,7 @@ private void setPowerState(int newState, boolean noChangeLights, int reason)
return;
}
- if (!mBootCompleted && !mAutoBrightnessButtonKeyboard) {
+ if (!mBootCompleted && !mUseSoftwareAutoBrightness) {
newState |= ALL_BRIGHT;
}
@@ -2320,9 +2329,13 @@ private int applyButtonState(int state) {
}
if (mButtonBrightnessOverride >= 0) {
brightness = mButtonBrightnessOverride;
- } else if (mLightSensorButtonBrightness >= 0 && mAutoBrightnessButtonKeyboard) {
+ } else if (!mAutoBrightnessToggledOn()) {
+ // Light sensor is not on, mLightSensorButtonBrightness has not been cleared
+ brightness = getPreferredBrightness();
+ } else if (mLightSensorButtonBrightness >= 0 && mUseSoftwareAutoBrightness) {
brightness = mLightSensorButtonBrightness;
}
+ Slog.d(TAG, "applyButtonState brightness:" + brightness + " mButtonBrightnessOverride:" + mButtonBrightnessOverride + " mLightSensorButtonBrightness:" + mLightSensorButtonBrightness);
if (brightness > 0) {
return state | BUTTON_BRIGHT_BIT;
} else if (brightness == 0) {
@@ -2342,9 +2355,13 @@ private int applyKeyboardState(int state) {
brightness = 0;
} else if (mButtonBrightnessOverride >= 0) {
brightness = mButtonBrightnessOverride;
- } else if (mLightSensorKeyboardBrightness >= 0 && mAutoBrightnessButtonKeyboard) {
+ } else if (!mAutoBrightnessToggledOn() && mHardwareKeyboardVisible()) {
+ // Light sensor is not on, mLightSensorButtonBrightness has not been cleared
+ brightness = getPreferredBrightness();
+ } else if (mLightSensorKeyboardBrightness >= 0 && mUseSoftwareAutoBrightness) {
brightness = mLightSensorKeyboardBrightness;
}
+ Slog.d(TAG, "applyKeyboardState brightness:" + brightness + " mButtonBrightnessOverride:" + mButtonBrightnessOverride + " mLightSensorKeyboardBrightness:" + mLightSensorKeyboardBrightness);
if (brightness > 0) {
return state | KEYBOARD_BRIGHT_BIT;
} else if (brightness == 0) {
@@ -2465,12 +2482,10 @@ private void userActivity(long time, long timeoutOverride, boolean noChangeLight
if (mLastEventTime <= time || force) {
mLastEventTime = time;
if ((mUserActivityAllowed && !mProximitySensorActive) || force) {
- 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);
+ // Only turn on button backlights if a button was pressed
+ // and auto brightness is disabled
+ if (eventType == BUTTON_EVENT && mAutoBrightnessToggledOn()) {
+ mUserState = (mHardwareKeyboardVisible() ? ALL_BRIGHT : SCREEN_BUTTON_BRIGHT);
} else {
// don't clear button/keyboard backlights when the screen is touched.
mUserState |= SCREEN_BRIGHT;
@@ -2897,17 +2912,28 @@ public void setKeyboardVisibility(boolean visible) {
// will take care of turning on due to a true change to the lid
// switch and synchronized with the lock screen.
if ((mPowerState & SCREEN_ON_BIT) != 0) {
+ Slog.w(TAG, "mKeyboardVisible:" + mKeyboardVisible + " mAutoBrightnessToggledOn:" + mAutoBrightnessToggledOn() + " mUseSoftwareAutoBrightness:" + mUseSoftwareAutoBrightness + " mLightSensorValue:" + mLightSensorValue + " mHardwareKeyboardVisible():" + mHardwareKeyboardVisible());
if (mUseSoftwareAutoBrightness) {
// force recompute of backlight values
if (mLightSensorValue >= 0) {
int value = (int)mLightSensorValue;
mLightSensorValue = -1;
lightSensorChangedLocked(value);
lightFilterReset((int)mLightSensorValue);
+ } else {
+ int preferredBrightness = getPreferredBrightness();
+ Slog.d(TAG, "mButtonBrightnessOverride:" + preferredBrightness);
+ // mLightSensorValue is not active, use preferredBrightness instead
+ if (preferredBrightness > 0) {
+ setButtonBrightnessOverride(preferredBrightness);
+ }
}
}
userActivity(SystemClock.uptimeMillis(), false, BUTTON_EVENT, true);
}
+ else if (mHardwareKeyboardVisible()) {
+ mKeyboardLight.turnOff();
+ }
}
}
}
@@ -3231,7 +3257,7 @@ void systemReady() {
// 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 (mAutoBrightnessButtonKeyboard) {
+ if (mAutoBrightnessToggledOn()) {
// turn the screen on
setPowerState(SCREEN_BRIGHT);
} else {

0 comments on commit 07bb1e4

Please sign in to comment.
Something went wrong with that request. Please try again.