Merge "Only send brightnessChangeEvent if display is on" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
d02f519e8e
@@ -22,6 +22,7 @@ import android.annotation.SystemApi;
|
|||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -233,6 +234,31 @@ public final class BrightnessChangeEvent implements Parcelable {
|
|||||||
dest.writeLong(colorSampleDuration);
|
dest.writeLong(colorSampleDuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "BrightnessChangeEvent{"
|
||||||
|
+ "brightness: " + brightness
|
||||||
|
+ ", timeStamp: " + timeStamp
|
||||||
|
+ ", packageName: " + packageName
|
||||||
|
+ ", userId: " + userId
|
||||||
|
+ ", uniqueDisplayId: " + uniqueDisplayId
|
||||||
|
+ ", luxValues: " + Arrays.toString(luxValues)
|
||||||
|
+ ", luxTimestamps: " + Arrays.toString(luxTimestamps)
|
||||||
|
+ ", batteryLevel: " + batteryLevel
|
||||||
|
+ ", powerBrightnessFactor: " + powerBrightnessFactor
|
||||||
|
+ ", nightMode: " + nightMode
|
||||||
|
+ ", colorTemperature: " + colorTemperature
|
||||||
|
+ ", reduceBrightColors: " + reduceBrightColors
|
||||||
|
+ ", reduceBrightColorsStrength: " + reduceBrightColorsStrength
|
||||||
|
+ ", reduceBrightColorsOffset: " + reduceBrightColorsOffset
|
||||||
|
+ ", lastBrightness: " + lastBrightness
|
||||||
|
+ ", isDefaultBrightnessConfig: " + isDefaultBrightnessConfig
|
||||||
|
+ ", isUserSetBrightness: " + isUserSetBrightness
|
||||||
|
+ ", colorValueBuckets: " + Arrays.toString(colorValueBuckets)
|
||||||
|
+ ", colorSampleDuration: " + colorSampleDuration
|
||||||
|
+ "}";
|
||||||
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
private float mBrightness;
|
private float mBrightness;
|
||||||
|
|||||||
@@ -316,7 +316,9 @@ public class BrightnessTracker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify the BrightnessTracker that the user has changed the brightness of the display.
|
* Notify the BrightnessTracker that the brightness of the display has changed.
|
||||||
|
* We pass both the user change and system changes, so that we know the starting point
|
||||||
|
* of the next user interaction. Only user interactions are then sent as BrightnessChangeEvents.
|
||||||
*/
|
*/
|
||||||
public void notifyBrightnessChanged(float brightness, boolean userInitiated,
|
public void notifyBrightnessChanged(float brightness, boolean userInitiated,
|
||||||
float powerBrightnessFactor, boolean wasShortTermModelActive,
|
float powerBrightnessFactor, boolean wasShortTermModelActive,
|
||||||
@@ -352,10 +354,8 @@ public class BrightnessTracker {
|
|||||||
// Not currently gathering brightness change information
|
// Not currently gathering brightness change information
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
float previousBrightness = mLastBrightness;
|
float previousBrightness = mLastBrightness;
|
||||||
mLastBrightness = brightness;
|
mLastBrightness = brightness;
|
||||||
|
|
||||||
if (!userInitiated) {
|
if (!userInitiated) {
|
||||||
// We want to record what current brightness is so that we know what the user
|
// We want to record what current brightness is so that we know what the user
|
||||||
// changed it from, but if it wasn't user initiated then we don't want to record it
|
// changed it from, but if it wasn't user initiated then we don't want to record it
|
||||||
@@ -429,7 +429,7 @@ public class BrightnessTracker {
|
|||||||
|
|
||||||
BrightnessChangeEvent event = builder.build();
|
BrightnessChangeEvent event = builder.build();
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Slog.d(TAG, "Event " + event.brightness + " " + event.packageName);
|
Slog.d(TAG, "Event: " + event.toString());
|
||||||
}
|
}
|
||||||
synchronized (mEventsLock) {
|
synchronized (mEventsLock) {
|
||||||
mEventsDirty = true;
|
mEventsDirty = true;
|
||||||
|
|||||||
@@ -1908,21 +1908,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Report brightness to brightnesstracker:
|
notifyBrightnessTrackerChanged(brightnessState, userInitiatedChange,
|
||||||
// If brightness is not temporary (ie the slider has been released)
|
wasShortTermModelActive, autoBrightnessEnabled, brightnessIsTemporary);
|
||||||
// AND if we are not in idle screen brightness mode.
|
|
||||||
if (!brightnessIsTemporary
|
|
||||||
&& (mAutomaticBrightnessController != null
|
|
||||||
&& !mAutomaticBrightnessController.isInIdleMode())) {
|
|
||||||
if (userInitiatedChange && (mAutomaticBrightnessController == null
|
|
||||||
|| !mAutomaticBrightnessController.hasValidAmbientLux())) {
|
|
||||||
// If we don't have a valid lux reading we can't report a valid
|
|
||||||
// slider event so notify as if the system changed the brightness.
|
|
||||||
userInitiatedChange = false;
|
|
||||||
}
|
|
||||||
notifyBrightnessTrackerChanged(brightnessState, userInitiatedChange,
|
|
||||||
wasShortTermModelActive);
|
|
||||||
}
|
|
||||||
|
|
||||||
// We save the brightness info *after* the brightness setting has been changed and
|
// We save the brightness info *after* the brightness setting has been changed and
|
||||||
// adjustments made so that the brightness info reflects the latest value.
|
// adjustments made so that the brightness info reflects the latest value.
|
||||||
@@ -2758,22 +2745,43 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void notifyBrightnessTrackerChanged(float brightness, boolean userInitiated,
|
private void notifyBrightnessTrackerChanged(float brightness, boolean userInitiated,
|
||||||
boolean wasShortTermModelActive) {
|
boolean wasShortTermModelActive, boolean autobrightnessEnabled,
|
||||||
|
boolean brightnessIsTemporary) {
|
||||||
final float brightnessInNits = convertToAdjustedNits(brightness);
|
final float brightnessInNits = convertToAdjustedNits(brightness);
|
||||||
if (mUseAutoBrightness && brightnessInNits >= 0.0f
|
|
||||||
&& mAutomaticBrightnessController != null && mBrightnessTracker != null) {
|
// Don't report brightness to brightnessTracker:
|
||||||
// We only want to track changes on devices that can actually map the display backlight
|
// If brightness is temporary (ie the slider has not been released)
|
||||||
// values into a physical brightness unit since the value provided by the API is in
|
// or if we are in idle screen brightness mode.
|
||||||
// nits and not using the arbitrary backlight units.
|
// or display is not on
|
||||||
final float powerFactor = mPowerRequest.lowPowerMode
|
// or we shouldn't be using autobrightness
|
||||||
? mPowerRequest.screenLowPowerBrightnessFactor
|
// or the nits is invalid.
|
||||||
: 1.0f;
|
if (brightnessIsTemporary
|
||||||
mBrightnessTracker.notifyBrightnessChanged(brightnessInNits, userInitiated,
|
|| mAutomaticBrightnessController == null
|
||||||
powerFactor, wasShortTermModelActive,
|
|| mAutomaticBrightnessController.isInIdleMode()
|
||||||
mAutomaticBrightnessController.isDefaultConfig(), mUniqueDisplayId,
|
|| !autobrightnessEnabled
|
||||||
mAutomaticBrightnessController.getLastSensorValues(),
|
|| mBrightnessTracker == null
|
||||||
mAutomaticBrightnessController.getLastSensorTimestamps());
|
|| !mUseAutoBrightness
|
||||||
|
|| brightnessInNits < 0.0f) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (userInitiated && !mAutomaticBrightnessController.hasValidAmbientLux()) {
|
||||||
|
// If we don't have a valid lux reading we can't report a valid
|
||||||
|
// slider event so notify as if the system changed the brightness.
|
||||||
|
userInitiated = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We only want to track changes on devices that can actually map the display backlight
|
||||||
|
// values into a physical brightness unit since the value provided by the API is in
|
||||||
|
// nits and not using the arbitrary backlight units.
|
||||||
|
final float powerFactor = mPowerRequest.lowPowerMode
|
||||||
|
? mPowerRequest.screenLowPowerBrightnessFactor
|
||||||
|
: 1.0f;
|
||||||
|
mBrightnessTracker.notifyBrightnessChanged(brightnessInNits, userInitiated,
|
||||||
|
powerFactor, wasShortTermModelActive,
|
||||||
|
mAutomaticBrightnessController.isDefaultConfig(), mUniqueDisplayId,
|
||||||
|
mAutomaticBrightnessController.getLastSensorValues(),
|
||||||
|
mAutomaticBrightnessController.getLastSensorTimestamps());
|
||||||
}
|
}
|
||||||
|
|
||||||
private float convertToNits(float brightness) {
|
private float convertToNits(float brightness) {
|
||||||
|
|||||||
@@ -1539,21 +1539,9 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Report brightness to brightnesstracker:
|
notifyBrightnessTrackerChanged(brightnessState, userInitiatedChange,
|
||||||
// If brightness is not temporary (ie the slider has been released)
|
wasShortTermModelActive, mAutomaticBrightnessStrategy.isAutoBrightnessEnabled(),
|
||||||
// AND if we are not in idle screen brightness mode.
|
brightnessIsTemporary);
|
||||||
if (!brightnessIsTemporary
|
|
||||||
&& (mAutomaticBrightnessController != null
|
|
||||||
&& !mAutomaticBrightnessController.isInIdleMode())) {
|
|
||||||
if (userInitiatedChange && (mAutomaticBrightnessController == null
|
|
||||||
|| !mAutomaticBrightnessController.hasValidAmbientLux())) {
|
|
||||||
// If we don't have a valid lux reading we can't report a valid
|
|
||||||
// slider event so notify as if the system changed the brightness.
|
|
||||||
userInitiatedChange = false;
|
|
||||||
}
|
|
||||||
notifyBrightnessTrackerChanged(brightnessState, userInitiatedChange,
|
|
||||||
wasShortTermModelActive);
|
|
||||||
}
|
|
||||||
|
|
||||||
// We save the brightness info *after* the brightness setting has been changed and
|
// We save the brightness info *after* the brightness setting has been changed and
|
||||||
// adjustments made so that the brightness info reflects the latest value.
|
// adjustments made so that the brightness info reflects the latest value.
|
||||||
@@ -2215,23 +2203,45 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void notifyBrightnessTrackerChanged(float brightness, boolean userInitiated,
|
private void notifyBrightnessTrackerChanged(float brightness, boolean userInitiated,
|
||||||
boolean wasShortTermModelActive) {
|
boolean wasShortTermModelActive, boolean autobrightnessEnabled,
|
||||||
|
boolean brightnessIsTemporary) {
|
||||||
|
|
||||||
final float brightnessInNits =
|
final float brightnessInNits =
|
||||||
mDisplayBrightnessController.convertToAdjustedNits(brightness);
|
mDisplayBrightnessController.convertToAdjustedNits(brightness);
|
||||||
if (mAutomaticBrightnessStrategy.shouldUseAutoBrightness() && brightnessInNits >= 0.0f
|
// Don't report brightness to brightnessTracker:
|
||||||
&& mAutomaticBrightnessController != null && mBrightnessTracker != null) {
|
// If brightness is temporary (ie the slider has not been released)
|
||||||
// We only want to track changes on devices that can actually map the display backlight
|
// or if we are in idle screen brightness mode.
|
||||||
// values into a physical brightness unit since the value provided by the API is in
|
// or display is not on
|
||||||
// nits and not using the arbitrary backlight units.
|
// or we shouldn't be using autobrightness
|
||||||
final float powerFactor = mPowerRequest.lowPowerMode
|
// or the nits is invalid.
|
||||||
? mPowerRequest.screenLowPowerBrightnessFactor
|
if (brightnessIsTemporary
|
||||||
: 1.0f;
|
|| mAutomaticBrightnessController == null
|
||||||
mBrightnessTracker.notifyBrightnessChanged(brightnessInNits, userInitiated,
|
|| mAutomaticBrightnessController.isInIdleMode()
|
||||||
powerFactor, wasShortTermModelActive,
|
|| !autobrightnessEnabled
|
||||||
mAutomaticBrightnessController.isDefaultConfig(), mUniqueDisplayId,
|
|| mBrightnessTracker == null
|
||||||
mAutomaticBrightnessController.getLastSensorValues(),
|
|| !mAutomaticBrightnessStrategy.shouldUseAutoBrightness()
|
||||||
mAutomaticBrightnessController.getLastSensorTimestamps());
|
|| brightnessInNits < 0.0f) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (userInitiated && (mAutomaticBrightnessController == null
|
||||||
|
|| !mAutomaticBrightnessController.hasValidAmbientLux())) {
|
||||||
|
// If we don't have a valid lux reading we can't report a valid
|
||||||
|
// slider event so notify as if the system changed the brightness.
|
||||||
|
userInitiated = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We only want to track changes on devices that can actually map the display backlight
|
||||||
|
// values into a physical brightness unit since the value provided by the API is in
|
||||||
|
// nits and not using the arbitrary backlight units.
|
||||||
|
final float powerFactor = mPowerRequest.lowPowerMode
|
||||||
|
? mPowerRequest.screenLowPowerBrightnessFactor
|
||||||
|
: 1.0f;
|
||||||
|
mBrightnessTracker.notifyBrightnessChanged(brightnessInNits, userInitiated,
|
||||||
|
powerFactor, wasShortTermModelActive,
|
||||||
|
mAutomaticBrightnessController.isDefaultConfig(), mUniqueDisplayId,
|
||||||
|
mAutomaticBrightnessController.getLastSensorValues(),
|
||||||
|
mAutomaticBrightnessController.getLastSensorTimestamps());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user