Merge "Enable AutoBrightness per display" into tm-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
0a73b2fa9c
@@ -220,6 +220,11 @@ public class BrightnessTracker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void backgroundStart(float initialBrightness) {
|
private void backgroundStart(float initialBrightness) {
|
||||||
|
synchronized (mDataCollectionLock) {
|
||||||
|
if (mStarted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Slog.d(TAG, "Background start");
|
Slog.d(TAG, "Background start");
|
||||||
}
|
}
|
||||||
@@ -250,6 +255,11 @@ public class BrightnessTracker {
|
|||||||
|
|
||||||
/** Stop listening for events */
|
/** Stop listening for events */
|
||||||
void stop() {
|
void stop() {
|
||||||
|
synchronized (mDataCollectionLock) {
|
||||||
|
if (!mStarted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Slog.d(TAG, "Stop");
|
Slog.d(TAG, "Stop");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ import javax.xml.datatype.DatatypeConfigurationException;
|
|||||||
* <quirk>canSetBrightnessViaHwc</quirk>
|
* <quirk>canSetBrightnessViaHwc</quirk>
|
||||||
* </quirks>
|
* </quirks>
|
||||||
*
|
*
|
||||||
* <autoBrightness>
|
* <autoBrightness enable="true">
|
||||||
* <brighteningLightDebounceMillis>
|
* <brighteningLightDebounceMillis>
|
||||||
* 2000
|
* 2000
|
||||||
* </brighteningLightDebounceMillis>
|
* </brighteningLightDebounceMillis>
|
||||||
@@ -507,6 +507,11 @@ public class DisplayDeviceConfig {
|
|||||||
private long mAutoBrightnessDarkeningLightDebounce =
|
private long mAutoBrightnessDarkeningLightDebounce =
|
||||||
INVALID_AUTO_BRIGHTNESS_LIGHT_DEBOUNCE;
|
INVALID_AUTO_BRIGHTNESS_LIGHT_DEBOUNCE;
|
||||||
|
|
||||||
|
// This setting allows non-default displays to have autobrightness enabled.
|
||||||
|
private boolean mAutoBrightnessAvailable = false;
|
||||||
|
// This stores the raw value loaded from the config file - true if not written.
|
||||||
|
private boolean mDdcAutoBrightnessAvailable = true;
|
||||||
|
|
||||||
// Brightness Throttling data may be updated via the DeviceConfig. Here we store the original
|
// Brightness Throttling data may be updated via the DeviceConfig. Here we store the original
|
||||||
// data, which comes from the ddc, and the current one, which may be the DeviceConfig
|
// data, which comes from the ddc, and the current one, which may be the DeviceConfig
|
||||||
// overwritten value.
|
// overwritten value.
|
||||||
@@ -1119,6 +1124,10 @@ public class DisplayDeviceConfig {
|
|||||||
return mProximitySensor;
|
return mProximitySensor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isAutoBrightnessAvailable() {
|
||||||
|
return mAutoBrightnessAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param quirkValue The quirk to test.
|
* @param quirkValue The quirk to test.
|
||||||
* @return {@code true} if the specified quirk is present in this configuration, {@code false}
|
* @return {@code true} if the specified quirk is present in this configuration, {@code false}
|
||||||
@@ -1271,6 +1280,8 @@ public class DisplayDeviceConfig {
|
|||||||
+ mAutoBrightnessDarkeningLightDebounce
|
+ mAutoBrightnessDarkeningLightDebounce
|
||||||
+ ", mBrightnessLevelsLux= " + Arrays.toString(mBrightnessLevelsLux)
|
+ ", mBrightnessLevelsLux= " + Arrays.toString(mBrightnessLevelsLux)
|
||||||
+ ", mBrightnessLevelsNits= " + Arrays.toString(mBrightnessLevelsNits)
|
+ ", mBrightnessLevelsNits= " + Arrays.toString(mBrightnessLevelsNits)
|
||||||
|
+ ", mDdcAutoBrightnessAvailable= " + mDdcAutoBrightnessAvailable
|
||||||
|
+ ", mAutoBrightnessAvailable= " + mAutoBrightnessAvailable
|
||||||
+ "}";
|
+ "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1349,6 +1360,7 @@ public class DisplayDeviceConfig {
|
|||||||
loadBrightnessChangeThresholdsFromXml();
|
loadBrightnessChangeThresholdsFromXml();
|
||||||
setProxSensorUnspecified();
|
setProxSensorUnspecified();
|
||||||
loadAutoBrightnessConfigsFromConfigXml();
|
loadAutoBrightnessConfigsFromConfigXml();
|
||||||
|
loadAutoBrightnessAvailableFromConfigXml();
|
||||||
mLoadedFrom = "<config.xml>";
|
mLoadedFrom = "<config.xml>";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1367,6 +1379,7 @@ public class DisplayDeviceConfig {
|
|||||||
setSimpleMappingStrategyValues();
|
setSimpleMappingStrategyValues();
|
||||||
loadAmbientLightSensorFromConfigXml();
|
loadAmbientLightSensorFromConfigXml();
|
||||||
setProxSensorUnspecified();
|
setProxSensorUnspecified();
|
||||||
|
loadAutoBrightnessAvailableFromConfigXml();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyUninitializedValuesFromSecondaryConfig(DisplayConfiguration defaultConfig) {
|
private void copyUninitializedValuesFromSecondaryConfig(DisplayConfiguration defaultConfig) {
|
||||||
@@ -1559,9 +1572,11 @@ public class DisplayDeviceConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadAutoBrightnessConfigValues(DisplayConfiguration config) {
|
private void loadAutoBrightnessConfigValues(DisplayConfiguration config) {
|
||||||
loadAutoBrightnessBrighteningLightDebounce(config.getAutoBrightness());
|
final AutoBrightness autoBrightness = config.getAutoBrightness();
|
||||||
loadAutoBrightnessDarkeningLightDebounce(config.getAutoBrightness());
|
loadAutoBrightnessBrighteningLightDebounce(autoBrightness);
|
||||||
loadAutoBrightnessDisplayBrightnessMapping(config.getAutoBrightness());
|
loadAutoBrightnessDarkeningLightDebounce(autoBrightness);
|
||||||
|
loadAutoBrightnessDisplayBrightnessMapping(autoBrightness);
|
||||||
|
loadEnableAutoBrightness(autoBrightness);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1623,6 +1638,11 @@ public class DisplayDeviceConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadAutoBrightnessAvailableFromConfigXml() {
|
||||||
|
mAutoBrightnessAvailable = mContext.getResources().getBoolean(
|
||||||
|
R.bool.config_automatic_brightness_available);
|
||||||
|
}
|
||||||
|
|
||||||
private void loadBrightnessMapFromConfigXml() {
|
private void loadBrightnessMapFromConfigXml() {
|
||||||
// Use the config.xml mapping
|
// Use the config.xml mapping
|
||||||
final Resources res = mContext.getResources();
|
final Resources res = mContext.getResources();
|
||||||
@@ -2263,6 +2283,20 @@ public class DisplayDeviceConfig {
|
|||||||
return levels;
|
return levels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadEnableAutoBrightness(AutoBrightness autobrightness) {
|
||||||
|
// mDdcAutoBrightnessAvailable is initialised to true, so that we fallback to using the
|
||||||
|
// config.xml values if the autobrightness tag is not defined in the ddc file.
|
||||||
|
// Autobrightness can still be turned off globally via config_automatic_brightness_available
|
||||||
|
mDdcAutoBrightnessAvailable = true;
|
||||||
|
if (autobrightness != null) {
|
||||||
|
mDdcAutoBrightnessAvailable = autobrightness.getEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
mAutoBrightnessAvailable = mContext.getResources().getBoolean(
|
||||||
|
com.android.internal.R.bool.config_automatic_brightness_available)
|
||||||
|
&& mDdcAutoBrightnessAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
static class SensorData {
|
static class SensorData {
|
||||||
public String type;
|
public String type;
|
||||||
public String name;
|
public String name;
|
||||||
|
|||||||
@@ -558,13 +558,6 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
|
|||||||
mScreenBrightnessForVrRangeMinimum = clampAbsoluteBrightness(
|
mScreenBrightnessForVrRangeMinimum = clampAbsoluteBrightness(
|
||||||
pm.getBrightnessConstraint(PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MINIMUM_VR));
|
pm.getBrightnessConstraint(PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MINIMUM_VR));
|
||||||
|
|
||||||
// Check the setting, but also verify that it is the default display. Only the default
|
|
||||||
// display has an automatic brightness controller running.
|
|
||||||
// TODO: b/179021925 - Fix to work with multiple displays
|
|
||||||
mUseSoftwareAutoBrightnessConfig = resources.getBoolean(
|
|
||||||
com.android.internal.R.bool.config_automatic_brightness_available)
|
|
||||||
&& mDisplayId == Display.DEFAULT_DISPLAY;
|
|
||||||
|
|
||||||
mAllowAutoBrightnessWhileDozingConfig = resources.getBoolean(
|
mAllowAutoBrightnessWhileDozingConfig = resources.getBoolean(
|
||||||
com.android.internal.R.bool.config_allowAutoBrightnessWhileDozing);
|
com.android.internal.R.bool.config_allowAutoBrightnessWhileDozing);
|
||||||
|
|
||||||
@@ -938,6 +931,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setUpAutoBrightness(Resources resources, Handler handler) {
|
private void setUpAutoBrightness(Resources resources, Handler handler) {
|
||||||
|
mUseSoftwareAutoBrightnessConfig = mDisplayDeviceConfig.isAutoBrightnessAvailable();
|
||||||
|
|
||||||
if (!mUseSoftwareAutoBrightnessConfig) {
|
if (!mUseSoftwareAutoBrightnessConfig) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -383,6 +383,7 @@
|
|||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
|
|
||||||
<xs:complexType name="autoBrightness">
|
<xs:complexType name="autoBrightness">
|
||||||
|
<xs:attribute name="enabled" type="xs:boolean" use="optional" default="true"/>
|
||||||
<xs:sequence>
|
<xs:sequence>
|
||||||
<!-- Sets the debounce for autoBrightness brightening in millis-->
|
<!-- Sets the debounce for autoBrightness brightening in millis-->
|
||||||
<xs:element name="brighteningLightDebounceMillis" type="xs:nonNegativeInteger"
|
<xs:element name="brighteningLightDebounceMillis" type="xs:nonNegativeInteger"
|
||||||
|
|||||||
@@ -6,9 +6,11 @@ package com.android.server.display.config {
|
|||||||
method public final java.math.BigInteger getBrighteningLightDebounceMillis();
|
method public final java.math.BigInteger getBrighteningLightDebounceMillis();
|
||||||
method public final java.math.BigInteger getDarkeningLightDebounceMillis();
|
method public final java.math.BigInteger getDarkeningLightDebounceMillis();
|
||||||
method public final com.android.server.display.config.DisplayBrightnessMapping getDisplayBrightnessMapping();
|
method public final com.android.server.display.config.DisplayBrightnessMapping getDisplayBrightnessMapping();
|
||||||
|
method public boolean getEnabled();
|
||||||
method public final void setBrighteningLightDebounceMillis(java.math.BigInteger);
|
method public final void setBrighteningLightDebounceMillis(java.math.BigInteger);
|
||||||
method public final void setDarkeningLightDebounceMillis(java.math.BigInteger);
|
method public final void setDarkeningLightDebounceMillis(java.math.BigInteger);
|
||||||
method public final void setDisplayBrightnessMapping(com.android.server.display.config.DisplayBrightnessMapping);
|
method public final void setDisplayBrightnessMapping(com.android.server.display.config.DisplayBrightnessMapping);
|
||||||
|
method public void setEnabled(boolean);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BrightnessThresholds {
|
public class BrightnessThresholds {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
@@ -885,6 +886,29 @@ public class BrightnessTrackerTest {
|
|||||||
assertNull(mInjector.mLightSensor);
|
assertNull(mInjector.mLightSensor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnlyOneReceiverRegistered() {
|
||||||
|
assertNull(mInjector.mLightSensor);
|
||||||
|
assertNull(mInjector.mSensorListener);
|
||||||
|
startTracker(mTracker, 0.3f, false);
|
||||||
|
|
||||||
|
assertNotNull(mInjector.mLightSensor);
|
||||||
|
assertNotNull(mInjector.mSensorListener);
|
||||||
|
Sensor registeredLightSensor = mInjector.mLightSensor;
|
||||||
|
SensorEventListener registeredSensorListener = mInjector.mSensorListener;
|
||||||
|
|
||||||
|
mTracker.start(0.3f);
|
||||||
|
assertSame(registeredLightSensor, mInjector.mLightSensor);
|
||||||
|
assertSame(registeredSensorListener, mInjector.mSensorListener);
|
||||||
|
|
||||||
|
mTracker.stop();
|
||||||
|
assertNull(mInjector.mLightSensor);
|
||||||
|
assertNull(mInjector.mSensorListener);
|
||||||
|
|
||||||
|
// mInjector asserts that we aren't removing a null receiver
|
||||||
|
mTracker.stop();
|
||||||
|
}
|
||||||
|
|
||||||
private InputStream getInputStream(String data) {
|
private InputStream getInputStream(String data) {
|
||||||
return new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8));
|
return new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user