Remove PowerManager.setAutoBrightness()
We will use the System.SCREEN_BRIGHTNESS_MODE Settings value instead.
Add SCREEN_BRIGHTNESS_MODE_MANUAL and SCREEN_BRIGHTNESS_MODE_AUTOMATIC constants.
Change-Id: I01935be3fcb48cf76392d2c594205cb47babc5b2
Signed-off-by: Mike Lockwood <lockwood@android.com>
diff --git a/services/java/com/android/server/PowerManagerService.java b/services/java/com/android/server/PowerManagerService.java
index e1bea37..a1220b6 100644
--- a/services/java/com/android/server/PowerManagerService.java
+++ b/services/java/com/android/server/PowerManagerService.java
@@ -53,6 +53,7 @@
import static android.provider.Settings.System.DIM_SCREEN;
import static android.provider.Settings.System.SCREEN_BRIGHTNESS;
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE;
+import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
import static android.provider.Settings.System.STAY_ON_WHILE_PLUGGED_IN;
@@ -199,6 +200,8 @@
private long mScreenOnStartTime;
private boolean mPreventScreenOn;
private int mScreenBrightnessOverride = -1;
+ private boolean mHasHardwareAutoBrightness;
+ private boolean mAutoBrightessEnabled;
// Used when logging number and duration of touch-down cycles
private long mTotalTouchDownTime;
@@ -344,6 +347,9 @@
// DIM_SCREEN
//mDimScreen = getInt(DIM_SCREEN) != 0;
+ // SCREEN_BRIGHTNESS_MODE
+ setScreenBrightnessMode(getInt(SCREEN_BRIGHTNESS_MODE));
+
// recalculate everything
setScreenOffTimeoutsLocked();
}
@@ -415,12 +421,17 @@
mScreenOffIntent = new Intent(Intent.ACTION_SCREEN_OFF);
mScreenOffIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
- ContentResolver resolver = mContext.getContentResolver();
+ mHasHardwareAutoBrightness = mContext.getResources().getBoolean(
+ com.android.internal.R.bool.config_hardware_automatic_brightness_available);
+
+ ContentResolver resolver = mContext.getContentResolver();
Cursor settingsCursor = resolver.query(Settings.System.CONTENT_URI, null,
"(" + Settings.System.NAME + "=?) or ("
+ Settings.System.NAME + "=?) or ("
+ + Settings.System.NAME + "=?) or ("
+ Settings.System.NAME + "=?)",
- new String[]{STAY_ON_WHILE_PLUGGED_IN, SCREEN_OFF_TIMEOUT, DIM_SCREEN},
+ new String[]{STAY_ON_WHILE_PLUGGED_IN, SCREEN_OFF_TIMEOUT, DIM_SCREEN,
+ SCREEN_BRIGHTNESS_MODE},
null);
mSettings = new ContentQueryMap(settingsCursor, Settings.System.NAME, true, mHandler);
SettingsObserver settingsObserver = new SettingsObserver();
@@ -444,10 +455,6 @@
// turn everything on
setPowerState(ALL_BRIGHT);
- // set auto brightness mode to user setting
- boolean brightnessMode = Settings.System.getInt(resolver, SCREEN_BRIGHTNESS_MODE, 1) != 0;
- mHardware.setAutoBrightness_UNCHECKED(brightnessMode);
-
synchronized (mHandlerThread) {
mInitComplete = true;
mHandlerThread.notifyAll();
@@ -1885,6 +1892,18 @@
}
}
+ private void setScreenBrightnessMode(int mode) {
+ mAutoBrightessEnabled = (mode == SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
+
+ if (mHasHardwareAutoBrightness) {
+ // When setting auto-brightness, must reset the brightness afterwards
+ mHardware.setAutoBrightness_UNCHECKED(mAutoBrightessEnabled);
+ setBacklightBrightness((int)mScreenBrightness.curValue);
+ } else {
+ // not yet implemented
+ }
+ }
+
/** Sets the screen off timeouts:
* mKeylightDelay
* mDimDelay
@@ -2098,11 +2117,6 @@
}
}
- public void setAutoBrightness(boolean on) {
- mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
- mHardware.setAutoBrightness_UNCHECKED(on);
- }
-
private SensorManager getSensorManager() {
if (mSensorManager == null) {
mSensorManager = new SensorManager(mHandlerThread.getLooper());