summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@android.com>2010-02-02 22:40:33 -0500
committerMike Lockwood <lockwood@android.com>2010-03-17 09:20:58 -0400
commit569a46d293b01bcd0a742c78a40e7281e874b0e9 (patch)
treea1241d9e05b9c532676c9ad2468181b4960badc0
parent56285d8fc26dd6a34025516b2ad70317806d5e86 (diff)
downloadbase-569a46d293b01bcd0a742c78a40e7281e874b0e9.tar.gz
Keep automatic screen brightness monotonically increasing until screen is turned off.
This is an experimental change to avoid the light sensor screen fluctuation problem. We only do this when undocked to since the lighting should be stable in the docked case and since the dock keeps the screen on we need to be able to adjust the lighting. Change-Id: I03454cf3b5ad8d6d6335862f0683ff0daa22209a BUG: 2387223 Signed-off-by: Mike Lockwood <lockwood@android.com>
-rw-r--r--services/java/com/android/server/PowerManagerService.java43
1 files changed, 42 insertions, 1 deletions
diff --git a/services/java/com/android/server/PowerManagerService.java b/services/java/com/android/server/PowerManagerService.java
index 966ecb0bf5e3..1977a415588c 100644
--- a/services/java/com/android/server/PowerManagerService.java
+++ b/services/java/com/android/server/PowerManagerService.java
@@ -209,9 +209,11 @@ class PowerManagerService extends IPowerManager.Stub
private Sensor mLightSensor;
private boolean mLightSensorEnabled;
private float mLightSensorValue = -1;
+ private int mHighestLightSensorValue = -1;
private float mLightSensorPendingValue = -1;
private int mLightSensorBrightness = -1;
private boolean mDimScreen = true;
+ private boolean mIsDocked = false;
private long mNextTimeout;
private volatile int mPokey = 0;
private volatile boolean mPokeAwakeOnSet = false;
@@ -361,6 +363,15 @@ class PowerManagerService extends IPowerManager.Stub
}
}
+ private final class DockReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ int state = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
+ Intent.EXTRA_DOCK_STATE_UNDOCKED);
+ dockStateChanged(state);
+ }
+ }
+
/**
* Set the setting that determines whether the device stays on when plugged in.
* The argument is a bit string, with each bit specifying a power source that,
@@ -511,6 +522,9 @@ class PowerManagerService extends IPowerManager.Stub
filter = new IntentFilter();
filter.addAction(Intent.ACTION_BOOT_COMPLETED);
mContext.registerReceiver(new BootCompletedReceiver(), filter);
+ filter = new IntentFilter();
+ filter.addAction(Intent.ACTION_DOCK_EVENT);
+ mContext.registerReceiver(new DockReceiver(), filter);
// Listen for Gservices changes
IntentFilter gservicesChangedFilter =
@@ -1360,6 +1374,8 @@ class PowerManagerService extends IPowerManager.Stub
// clear current value so we will update based on the new conditions
// when the sensor is reenabled.
mLightSensorValue = -1;
+ // reset our highest light sensor value when the screen turns off
+ mHighestLightSensorValue = -1;
}
}
}
@@ -2002,15 +2018,40 @@ class PowerManagerService extends IPowerManager.Stub
}
};
+ private void dockStateChanged(int state) {
+ synchronized (mLocks) {
+ mIsDocked = (state != Intent.EXTRA_DOCK_STATE_UNDOCKED);
+ if (mIsDocked) {
+ mHighestLightSensorValue = -1;
+ }
+ if ((mPowerState & SCREEN_ON_BIT) != 0) {
+ // force lights recalculation
+ int value = (int)mLightSensorValue;
+ mLightSensorValue = -1;
+ lightSensorChangedLocked(value);
+ }
+ }
+ }
+
private void lightSensorChangedLocked(int value) {
if (mDebugLightSensor) {
Log.d(TAG, "lightSensorChangedLocked " + value);
}
+ // do not allow light sensor value to decrease
+ if (mHighestLightSensorValue < value) {
+ mHighestLightSensorValue = value;
+ }
+
if (mLightSensorValue != value) {
mLightSensorValue = value;
if ((mPowerState & BATTERY_LOW_BIT) == 0) {
- int lcdValue = getAutoBrightnessValue(value, mLcdBacklightValues);
+ // use maximum light sensor value seen since screen went on for LCD to avoid flicker
+ // we only do this if we are undocked, since lighting should be stable when
+ // stationary in a dock.
+ int lcdValue = getAutoBrightnessValue(
+ (mIsDocked ? value : mHighestLightSensorValue),
+ mLcdBacklightValues);
int buttonValue = getAutoBrightnessValue(value, mButtonBacklightValues);
int keyboardValue;
if (mKeyboardVisible) {