Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add back backlight brightness curve adjustment.

Change-Id: I1dbcc9a35b44abc077e2722a4e81eb1e83d463fa
Signed-off-by: kecinzer <kecinzer@gmail.com>
  • Loading branch information...
commit f81b5126be950398915b50f1b08af31f8f5cbaa0 1 parent 0341d35
@maniac103 maniac103 authored Gerrit Code Review committed
View
18 core/java/android/provider/Settings.java
@@ -1788,6 +1788,24 @@ public static void setShowGTalkServiceStatusForUser(ContentResolver cr, boolean
*/
public static final String MODE_RINGER_STREAMS_AFFECTED = "mode_ringer_streams_affected";
+ /**
+ * Custom automatic brightness light sensor levels.
+ * The value is a comma separated int array with length N.
+ * Example: "100,300,3000".
+ *
+ * @hide
+ */
+ public static final String AUTO_BRIGHTNESS_LUX = "auto_brightness_lux";
+
+ /**
+ * Custom automatic brightness display backlight brightness values.
+ * The value is a comma separated int array with length N+1.
+ * Example: "10,50,100,255".
+ *
+ * @hide
+ */
+ public static final String AUTO_BRIGHTNESS_BACKLIGHT = "auto_brightness_backlight";
+
/**
* Determines which streams are affected by mute. The
* stream type's bit should be set to 1 if it should be muted when a mute request
View
121 services/java/com/android/server/power/DisplayPowerController.java
@@ -23,18 +23,24 @@
import android.animation.Animator;
import android.animation.ObjectAnimator;
+import android.content.ContentResolver;
import android.content.Context;
+import android.database.ContentObserver;
import android.content.res.Resources;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.hardware.SystemSensorManager;
+import android.hardware.display.DisplayManager;
+import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.PowerManager;
import android.os.SystemClock;
+import android.os.UserHandle;
+import android.provider.Settings;
import android.text.format.DateUtils;
import android.util.FloatMath;
import android.util.Slog;
@@ -167,6 +173,9 @@
// The display blanker.
private final DisplayBlanker mDisplayBlanker;
+ // Our context
+ private final Context mContext;
+
// Our handler.
private final DisplayControllerHandler mHandler;
@@ -343,6 +352,7 @@
// Twilight changed. We might recalculate auto-brightness values.
private boolean mTwilightChanged;
+ private boolean mAutoBrightnessSettingsChanged;
/**
* Creates the display power controller.
@@ -352,6 +362,7 @@ public DisplayPowerController(Looper looper, Context context, Notifier notifier,
DisplayManagerService displayManager,
DisplayBlanker displayBlanker,
Callbacks callbacks, Handler callbackHandler) {
+ mContext = context;
mHandler = new DisplayControllerHandler(looper);
mNotifier = notifier;
mDisplayBlanker = displayBlanker;
@@ -372,36 +383,34 @@ public DisplayPowerController(Looper looper, Context context, Notifier notifier,
com.android.internal.R.integer.config_screenBrightnessSettingMinimum),
mScreenBrightnessDimConfig);
+ mScreenBrightnessRangeMinimum = clampAbsoluteBrightness(screenBrightnessMinimum);
+ mScreenBrightnessRangeMaximum = PowerManager.BRIGHTNESS_ON;
+
mUseSoftwareAutoBrightnessConfig = resources.getBoolean(
com.android.internal.R.bool.config_automatic_brightness_available);
if (mUseSoftwareAutoBrightnessConfig) {
- int[] lux = resources.getIntArray(
- com.android.internal.R.array.config_autoBrightnessLevels);
- int[] screenBrightness = resources.getIntArray(
- com.android.internal.R.array.config_autoBrightnessLcdBacklightValues);
-
- mScreenAutoBrightnessSpline = createAutoBrightnessSpline(lux, screenBrightness);
- if (mScreenAutoBrightnessSpline == null) {
- Slog.e(TAG, "Error in config.xml. config_autoBrightnessLcdBacklightValues "
- + "(size " + screenBrightness.length + ") "
- + "must be monotic and have exactly one more entry than "
- + "config_autoBrightnessLevels (size " + lux.length + ") "
- + "which must be strictly increasing. "
- + "Auto-brightness will be disabled.");
- mUseSoftwareAutoBrightnessConfig = false;
- } else {
- if (screenBrightness[0] < screenBrightnessMinimum) {
- screenBrightnessMinimum = screenBrightness[0];
+ final ContentResolver cr = mContext.getContentResolver();
+ final ContentObserver observer = new ContentObserver(mHandler) {
+ @Override
+ public void onChange(boolean selfChange, Uri uri) {
+ mAutoBrightnessSettingsChanged = true;
+ updateAutomaticBrightnessSettings();
+ updatePowerState();
}
- }
+ };
+
+ cr.registerContentObserver(
+ Settings.System.getUriFor(Settings.System.AUTO_BRIGHTNESS_LUX),
+ false, observer, UserHandle.USER_ALL);
+ cr.registerContentObserver(
+ Settings.System.getUriFor(Settings.System.AUTO_BRIGHTNESS_BACKLIGHT),
+ false, observer, UserHandle.USER_ALL);
mLightSensorWarmUpTimeConfig = resources.getInteger(
com.android.internal.R.integer.config_lightSensorWarmupTime);
+ updateAutomaticBrightnessSettings();
}
- mScreenBrightnessRangeMinimum = clampAbsoluteBrightness(screenBrightnessMinimum);
- mScreenBrightnessRangeMaximum = PowerManager.BRIGHTNESS_ON;
-
mElectronBeamFadesConfig = resources.getBoolean(
com.android.internal.R.bool.config_animateScreenLights);
@@ -423,6 +432,61 @@ public DisplayPowerController(Looper looper, Context context, Notifier notifier,
}
}
+ private void updateAutomaticBrightnessSettings() {
+ int[] lux = getIntArrayForSetting(Settings.System.AUTO_BRIGHTNESS_LUX);
+ int[] values = getIntArrayForSetting(Settings.System.AUTO_BRIGHTNESS_BACKLIGHT);
+ Resources res = mContext.getResources();
+
+ mScreenAutoBrightnessSpline = null;
+ mUseSoftwareAutoBrightnessConfig = true;
+
+ if (lux != null && values != null) {
+ mScreenAutoBrightnessSpline = createAutoBrightnessSpline(lux, values);
+ if (mScreenAutoBrightnessSpline == null) {
+ Slog.w(TAG, "Found invalid auto-brightness configuration, falling back to default");
+ }
+ }
+
+ if (mScreenAutoBrightnessSpline == null) {
+ lux = res.getIntArray(com.android.internal.R.array.config_autoBrightnessLevels);
+ values = res.getIntArray(com.android.internal.R.array.config_autoBrightnessLcdBacklightValues);
+ mScreenAutoBrightnessSpline = createAutoBrightnessSpline(lux, values);
+ }
+
+ if (mScreenAutoBrightnessSpline == null) {
+ Slog.e(TAG, "Error in config.xml. config_autoBrightnessLcdBacklightValues "
+ + "(size " + values.length + ") "
+ + "must be monotic and have exactly one more entry than "
+ + "config_autoBrightnessLevels (size " + lux.length + ") "
+ + "which must be strictly increasing. "
+ + "Auto-brightness will be disabled.");
+ mUseSoftwareAutoBrightnessConfig = false;
+ return;
+ }
+ }
+
+ private int[] getIntArrayForSetting(String setting) {
+ final String value = Settings.System.getStringForUser(
+ mContext.getContentResolver(), setting, UserHandle.USER_CURRENT);
+ if (value == null) {
+ return null;
+ }
+ String[] items = value.split(",");
+ if (items == null || items.length == 0) {
+ return null;
+ }
+
+ int[] values = new int[items.length];
+ for (int i = 0; i < items.length; i++) {
+ try {
+ values[i] = Integer.valueOf(items[i]);
+ } catch (NumberFormatException e) {
+ return null;
+ }
+ }
+ return values;
+ }
+
private static Spline createAutoBrightnessSpline(int[] lux, int[] brightness) {
try {
final int n = brightness.length;
@@ -434,6 +498,12 @@ private static Spline createAutoBrightnessSpline(int[] lux, int[] brightness) {
y[i] = normalizeAbsoluteBrightness(brightness[i]);
}
+ if (DEBUG) {
+ for (int i = 0; i < n; i++) {
+ Slog.d(TAG, "Spline data[" + i + "]: x = " + x[i] + " y = " + y[i]);
+ }
+ }
+
Spline spline = Spline.createMonotoneCubicSpline(x, y);
if (DEBUG) {
Slog.d(TAG, "Auto-brightness spline: " + spline);
@@ -561,9 +631,10 @@ private void updatePowerState() {
// Update the power state request.
final boolean mustNotify;
boolean mustInitialize = false;
- boolean updateAutoBrightness = mTwilightChanged;
+ boolean updateAutoBrightness = mTwilightChanged || mAutoBrightnessSettingsChanged;
boolean wasDim = false;
mTwilightChanged = false;
+ mAutoBrightnessSettingsChanged = false;
synchronized (mLock) {
mPendingUpdatePowerStateLocked = false;
@@ -935,7 +1006,7 @@ private void updateAmbientLux(long time) {
mDebounceLuxTime = time;
if (DEBUG) {
Slog.d(TAG, "updateAmbientLux: Initializing: "
- + ", mRecentShortTermAverageLux=" + mRecentShortTermAverageLux
+ + "mRecentShortTermAverageLux=" + mRecentShortTermAverageLux
+ ", mRecentLongTermAverageLux=" + mRecentLongTermAverageLux
+ ", mAmbientLux=" + mAmbientLux);
}
@@ -1059,6 +1130,10 @@ private void updateAutoBrightness(boolean sendUpdate) {
float value = mScreenAutoBrightnessSpline.interpolate(mAmbientLux);
float gamma = 1.0f;
+ if (DEBUG) {
+ Slog.d(TAG, "updateAutoBrightness: mAmbientLux=" + mAmbientLux + " -> value=" + value);
+ }
+
if (USE_SCREEN_AUTO_BRIGHTNESS_ADJUSTMENT
&& mPowerRequest.screenAutoBrightnessAdjustment != 0.0f) {
final float adjGamma = FloatMath.pow(SCREEN_AUTO_BRIGHTNESS_ADJUSTMENT_MAX_GAMMA,
Please sign in to comment.
Something went wrong with that request. Please try again.