summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2015-04-29 01:17:56 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-04-29 01:18:05 +0000
commitb957a742b29fa6c7a2eda7d60cf61e8af4668ef8 (patch)
tree4edc97b46272e47f16285460c19db8bf802ff332 /services
parent46fc110104f3017f23abb397ca817db2be39f1a2 (diff)
parenta576b4d3be8687f0a65fc5777424955d551604e4 (diff)
downloadframeworks_base-b957a742b29fa6c7a2eda7d60cf61e8af4668ef8.zip
frameworks_base-b957a742b29fa6c7a2eda7d60cf61e8af4668ef8.tar.gz
frameworks_base-b957a742b29fa6c7a2eda7d60cf61e8af4668ef8.tar.bz2
Merge changes from topic 'brightness' into mnc-dev
* changes: Add code to collect data about auto-brightness adjustments. Add float support to binary event log.
Diffstat (limited to 'services')
-rw-r--r--services/core/java/com/android/server/EventLogTags.logtags5
-rw-r--r--services/core/java/com/android/server/display/AutomaticBrightnessController.java119
-rw-r--r--services/core/java/com/android/server/display/DisplayPowerController.java8
-rw-r--r--services/core/java/com/android/server/power/PowerManagerService.java3
4 files changed, 100 insertions, 35 deletions
diff --git a/services/core/java/com/android/server/EventLogTags.logtags b/services/core/java/com/android/server/EventLogTags.logtags
index abd2ca0..ef9d0c3 100644
--- a/services/core/java/com/android/server/EventLogTags.logtags
+++ b/services/core/java/com/android/server/EventLogTags.logtags
@@ -180,6 +180,11 @@ option java_package com.android.server
34001 device_idle_step
34002 device_idle_wake_from_idle (is_idle|1|5), (reason|3)
+# ---------------------------
+# DisplayManagerService.java
+# ---------------------------
+# Auto-brightness adjustments by the user.
+35000 auto_brightness_adj (old_adj|5),(old_lux|5),(old_brightness|5),(old_gamma|5),(new_adj|5),(new_lux|5),(new_brightness|5),(new_gamma|5)
# ---------------------------
# ConnectivityService.java
diff --git a/services/core/java/com/android/server/display/AutomaticBrightnessController.java b/services/core/java/com/android/server/display/AutomaticBrightnessController.java
index 93d37f1..e15bca6 100644
--- a/services/core/java/com/android/server/display/AutomaticBrightnessController.java
+++ b/services/core/java/com/android/server/display/AutomaticBrightnessController.java
@@ -16,6 +16,7 @@
package com.android.server.display;
+import com.android.server.EventLogTags;
import com.android.server.LocalServices;
import com.android.server.twilight.TwilightListener;
import com.android.server.twilight.TwilightManager;
@@ -31,13 +32,13 @@ import android.os.Message;
import android.os.PowerManager;
import android.os.SystemClock;
import android.text.format.DateUtils;
+import android.util.EventLog;
import android.util.MathUtils;
import android.util.Spline;
import android.util.Slog;
import android.util.TimeUtils;
import java.io.PrintWriter;
-import java.util.Arrays;
class AutomaticBrightnessController {
private static final String TAG = "AutomaticBrightnessController";
@@ -87,7 +88,12 @@ class AutomaticBrightnessController {
// well after dusk.
private static final long TWILIGHT_ADJUSTMENT_TIME = DateUtils.HOUR_IN_MILLIS * 2;
+ // Debounce for sampling user-initiated changes in display brightness to ensure
+ // the user is satisfied with the result before storing the sample.
+ private static final int BRIGHTNESS_ADJUSTMENT_SAMPLE_DEBOUNCE_MILLIS = 10000;
+
private static final int MSG_UPDATE_AMBIENT_LUX = 1;
+ private static final int MSG_BRIGHTNESS_ADJUSTMENT_SAMPLE = 2;
// Callbacks for requesting updates to the the display's power state
private final Callbacks mCallbacks;
@@ -179,6 +185,14 @@ class AutomaticBrightnessController {
// Are we going to adjust brightness while dozing.
private boolean mDozing;
+ // True if we are collecting a brightness adjustment sample, along with some data
+ // for the initial state of the sample.
+ private boolean mBrightnessAdjustmentSamplePending;
+ private float mBrightnessAdjustmentSampleOldAdjustment;
+ private float mBrightnessAdjustmentSampleOldLux;
+ private int mBrightnessAdjustmentSampleOldBrightness;
+ private float mBrightnessAdjustmentSampleOldGamma;
+
public AutomaticBrightnessController(Callbacks callbacks, Looper looper,
SensorManager sensorManager, Spline autoBrightnessSpline, int lightSensorWarmUpTime,
int brightnessMin, int brightnessMax, float dozeScaleFactor,
@@ -216,7 +230,8 @@ class AutomaticBrightnessController {
return mScreenAutoBrightness;
}
- public void configure(boolean enable, float adjustment, boolean dozing) {
+ public void configure(boolean enable, float adjustment, boolean dozing,
+ boolean userInitiatedChange) {
// While dozing, the application processor may be suspended which will prevent us from
// receiving new information from the light sensor. On some devices, we may be able to
// switch to a wake-up light sensor instead but for now we will simply disable the sensor
@@ -228,6 +243,9 @@ class AutomaticBrightnessController {
if (changed) {
updateAutoBrightness(false /*sendUpdate*/);
}
+ if (enable && !dozing && userInitiatedChange) {
+ prepareBrightnessAdjustmentSample();
+ }
}
public void dump(PrintWriter pw) {
@@ -486,7 +504,7 @@ class AutomaticBrightnessController {
}
int newScreenAutoBrightness =
- clampScreenBrightness(Math.round(value * PowerManager.BRIGHTNESS_ON));
+ clampScreenBrightness(Math.round(value * PowerManager.BRIGHTNESS_ON));
if (mScreenAutoBrightness != newScreenAutoBrightness) {
if (DEBUG) {
Slog.d(TAG, "updateAutoBrightness: mScreenAutoBrightness="
@@ -507,6 +525,54 @@ class AutomaticBrightnessController {
mScreenBrightnessRangeMinimum, mScreenBrightnessRangeMaximum);
}
+ private void prepareBrightnessAdjustmentSample() {
+ if (!mBrightnessAdjustmentSamplePending) {
+ mBrightnessAdjustmentSamplePending = true;
+ mBrightnessAdjustmentSampleOldAdjustment = mScreenAutoBrightnessAdjustment;
+ mBrightnessAdjustmentSampleOldLux = mAmbientLuxValid ? mAmbientLux : -1;
+ mBrightnessAdjustmentSampleOldBrightness = mScreenAutoBrightness;
+ mBrightnessAdjustmentSampleOldGamma = mLastScreenAutoBrightnessGamma;
+ } else {
+ mHandler.removeMessages(MSG_BRIGHTNESS_ADJUSTMENT_SAMPLE);
+ }
+
+ mHandler.sendEmptyMessageDelayed(MSG_BRIGHTNESS_ADJUSTMENT_SAMPLE,
+ BRIGHTNESS_ADJUSTMENT_SAMPLE_DEBOUNCE_MILLIS);
+ }
+
+ private void cancelBrightnessAdjustmentSample() {
+ if (mBrightnessAdjustmentSamplePending) {
+ mBrightnessAdjustmentSamplePending = false;
+ mHandler.removeMessages(MSG_BRIGHTNESS_ADJUSTMENT_SAMPLE);
+ }
+ }
+
+ private void collectBrightnessAdjustmentSample() {
+ if (mBrightnessAdjustmentSamplePending) {
+ mBrightnessAdjustmentSamplePending = false;
+ if (mAmbientLuxValid && mScreenAutoBrightness >= 0) {
+ if (DEBUG) {
+ Slog.d(TAG, "Auto-brightness adjustment changed by user: "
+ + "adj=" + mScreenAutoBrightnessAdjustment
+ + ", lux=" + mAmbientLux
+ + ", brightness=" + mScreenAutoBrightness
+ + ", gamma=" + mLastScreenAutoBrightnessGamma
+ + ", ring=" + mAmbientLightRingBuffer);
+ }
+
+ EventLog.writeEvent(EventLogTags.AUTO_BRIGHTNESS_ADJ,
+ mBrightnessAdjustmentSampleOldAdjustment,
+ mBrightnessAdjustmentSampleOldLux,
+ mBrightnessAdjustmentSampleOldBrightness,
+ mBrightnessAdjustmentSampleOldGamma,
+ mScreenAutoBrightnessAdjustment,
+ mAmbientLux,
+ mScreenAutoBrightness,
+ mLastScreenAutoBrightnessGamma);
+ }
+ }
+ }
+
private static float getTwilightGamma(long now, long lastSunset, long nextSunrise) {
if (lastSunset < 0 || nextSunrise < 0
|| now < lastSunset || now > nextSunrise) {
@@ -537,6 +603,10 @@ class AutomaticBrightnessController {
case MSG_UPDATE_AMBIENT_LUX:
updateAmbientLux();
break;
+
+ case MSG_BRIGHTNESS_ADJUSTMENT_SAMPLE:
+ collectBrightnessAdjustmentSample();
+ break;
}
}
}
@@ -584,11 +654,7 @@ class AutomaticBrightnessController {
private int mCount;
public AmbientLightRingBuffer(long lightSensorRate) {
- this((int) Math.ceil(AMBIENT_LIGHT_HORIZON * BUFFER_SLACK / lightSensorRate));
- }
-
- public AmbientLightRingBuffer(int initialCapacity) {
- mCapacity = initialCapacity;
+ mCapacity = (int) Math.ceil(AMBIENT_LIGHT_HORIZON * BUFFER_SLACK / lightSensorRate);
mRingLux = new float[mCapacity];
mRingTime = new long[mCapacity];
}
@@ -664,10 +730,6 @@ class AutomaticBrightnessController {
return mCount;
}
- public boolean isEmpty() {
- return mCount == 0;
- }
-
public void clear() {
mStart = 0;
mEnd = 0;
@@ -676,27 +738,20 @@ class AutomaticBrightnessController {
@Override
public String toString() {
- final int length = mCapacity - mStart;
- float[] lux = new float[mCount];
- long[] time = new long[mCount];
-
- if (mCount <= length) {
- System.arraycopy(mRingLux, mStart, lux, 0, mCount);
- System.arraycopy(mRingTime, mStart, time, 0, mCount);
- } else {
- System.arraycopy(mRingLux, mStart, lux, 0, length);
- System.arraycopy(mRingLux, 0, lux, length, mCount - length);
-
- System.arraycopy(mRingTime, mStart, time, 0, length);
- System.arraycopy(mRingTime, 0, time, length, mCount - length);
+ StringBuffer buf = new StringBuffer();
+ buf.append('[');
+ for (int i = 0; i < mCount; i++) {
+ final long next = i + 1 < mCount ? getTime(i + 1) : SystemClock.uptimeMillis();
+ if (i != 0) {
+ buf.append(", ");
+ }
+ buf.append(getLux(i));
+ buf.append(" / ");
+ buf.append(next - getTime(i));
+ buf.append("ms");
}
- return "AmbientLightRingBuffer{mCapacity=" + mCapacity
- + ", mStart=" + mStart
- + ", mEnd=" + mEnd
- + ", mCount=" + mCount
- + ", mRingLux=" + Arrays.toString(lux)
- + ", mRingTime=" + Arrays.toString(time)
- + "}";
+ buf.append(']');
+ return buf.toString();
}
private int offsetOf(int index) {
diff --git a/services/core/java/com/android/server/display/DisplayPowerController.java b/services/core/java/com/android/server/display/DisplayPowerController.java
index f74601e..35fbef6 100644
--- a/services/core/java/com/android/server/display/DisplayPowerController.java
+++ b/services/core/java/com/android/server/display/DisplayPowerController.java
@@ -70,12 +70,11 @@ import java.io.PrintWriter;
*/
final class DisplayPowerController implements AutomaticBrightnessController.Callbacks {
private static final String TAG = "DisplayPowerController";
+ private static final String SCREEN_ON_BLOCKED_TRACE_NAME = "Screen on blocked";
private static boolean DEBUG = false;
private static final boolean DEBUG_PRETEND_PROXIMITY_SENSOR_ABSENT = false;
- private static final String SCREEN_ON_BLOCKED_TRACE_NAME = "Screen on blocked";
-
// If true, uses the color fade on animation.
// We might want to turn this off if we cannot get a guarantee that the screen
// actually turns on and starts showing new content after the call to set the
@@ -599,8 +598,11 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
autoBrightnessEnabled = mPowerRequest.useAutoBrightness
&& (state == Display.STATE_ON || autoBrightnessEnabledInDoze)
&& brightness < 0;
+ final boolean userInitiatedChange = autoBrightnessAdjustmentChanged
+ && mPowerRequest.brightnessSetByUser;
mAutomaticBrightnessController.configure(autoBrightnessEnabled,
- mPowerRequest.screenAutoBrightnessAdjustment, state != Display.STATE_ON);
+ mPowerRequest.screenAutoBrightnessAdjustment, state != Display.STATE_ON,
+ userInitiatedChange);
}
// Apply brightness boost.
diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java
index 6c8959c..f790f75 100644
--- a/services/core/java/com/android/server/power/PowerManagerService.java
+++ b/services/core/java/com/android/server/power/PowerManagerService.java
@@ -1819,6 +1819,7 @@ public final class PowerManagerService extends SystemService
mDisplayPowerRequest.policy = getDesiredScreenPolicyLocked();
// Determine appropriate screen brightness and auto-brightness adjustments.
+ boolean brightnessSetByUser = true;
int screenBrightness = mScreenBrightnessSettingDefault;
float screenAutoBrightnessAdjustment = 0.0f;
boolean autoBrightness = (mScreenBrightnessModeSetting ==
@@ -1826,6 +1827,7 @@ public final class PowerManagerService extends SystemService
if (isValidBrightness(mScreenBrightnessOverrideFromWindowManager)) {
screenBrightness = mScreenBrightnessOverrideFromWindowManager;
autoBrightness = false;
+ brightnessSetByUser = false;
} else if (isValidBrightness(mTemporaryScreenBrightnessSettingOverride)) {
screenBrightness = mTemporaryScreenBrightnessSettingOverride;
} else if (isValidBrightness(mScreenBrightnessSetting)) {
@@ -1851,6 +1853,7 @@ public final class PowerManagerService extends SystemService
mDisplayPowerRequest.screenBrightness = screenBrightness;
mDisplayPowerRequest.screenAutoBrightnessAdjustment =
screenAutoBrightnessAdjustment;
+ mDisplayPowerRequest.brightnessSetByUser = brightnessSetByUser;
mDisplayPowerRequest.useAutoBrightness = autoBrightness;
mDisplayPowerRequest.useProximitySensor = shouldUseProximitySensorLocked();
mDisplayPowerRequest.lowPowerMode = mLowPowerModeEnabled;