From d89039534ac61fe1a19a6b159175e542f9be7f4c Mon Sep 17 00:00:00 2001 From: Fiona Campbell Date: Wed, 6 Jul 2022 09:25:40 +0000 Subject: [PATCH] Enable AutoBrightness per display Allow each display to specify whether autobrightness should be used or not. Bug: 179021925 Test: atest BrightnessTrackerTest Test: check both displays use autobrightness; adb shell dumpsys display | grep "mAutoBrightnessAvailable\|mUseSoftwareAutoBrightnessConfig" Change-Id: I7e0b8442c0724da8f9a9b0c6b455f558a42f40c9 Merged-In: I7e0b8442c0724da8f9a9b0c6b455f558a42f40c9 --- .../server/display/BrightnessTracker.java | 10 +++++ .../server/display/DisplayDeviceConfig.java | 42 +++++++++++++++++-- .../display/DisplayPowerController.java | 9 +--- .../display-device-config.xsd | 1 + .../display-device-config/schema/current.txt | 2 + .../server/display/BrightnessTrackerTest.java | 24 +++++++++++ 6 files changed, 77 insertions(+), 11 deletions(-) diff --git a/services/core/java/com/android/server/display/BrightnessTracker.java b/services/core/java/com/android/server/display/BrightnessTracker.java index 17215e5ae4adf..8f59ffd30bbaa 100644 --- a/services/core/java/com/android/server/display/BrightnessTracker.java +++ b/services/core/java/com/android/server/display/BrightnessTracker.java @@ -220,6 +220,11 @@ public class BrightnessTracker { } private void backgroundStart(float initialBrightness) { + synchronized (mDataCollectionLock) { + if (mStarted) { + return; + } + } if (DEBUG) { Slog.d(TAG, "Background start"); } @@ -250,6 +255,11 @@ public class BrightnessTracker { /** Stop listening for events */ void stop() { + synchronized (mDataCollectionLock) { + if (!mStarted) { + return; + } + } if (DEBUG) { Slog.d(TAG, "Stop"); } diff --git a/services/core/java/com/android/server/display/DisplayDeviceConfig.java b/services/core/java/com/android/server/display/DisplayDeviceConfig.java index 4165186135683..cbc8fc7cd2a06 100644 --- a/services/core/java/com/android/server/display/DisplayDeviceConfig.java +++ b/services/core/java/com/android/server/display/DisplayDeviceConfig.java @@ -149,7 +149,7 @@ import javax.xml.datatype.DatatypeConfigurationException; * canSetBrightnessViaHwc * * - * + * * * 2000 * @@ -363,6 +363,11 @@ public class DisplayDeviceConfig { private long mAutoBrightnessDarkeningLightDebounce = 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 // data, which comes from the ddc, and the current one, which may be the DeviceConfig // overwritten value. @@ -725,6 +730,10 @@ public class DisplayDeviceConfig { return mProximitySensor; } + boolean isAutoBrightnessAvailable() { + return mAutoBrightnessAvailable; + } + /** * @param quirkValue The quirk to test. * @return {@code true} if the specified quirk is present in this configuration, {@code false} @@ -839,6 +848,8 @@ public class DisplayDeviceConfig { + mAutoBrightnessDarkeningLightDebounce + ", mBrightnessLevelsLux= " + Arrays.toString(mBrightnessLevelsLux) + ", mBrightnessLevelsNits= " + Arrays.toString(mBrightnessLevelsNits) + + ", mDdcAutoBrightnessAvailable= " + mDdcAutoBrightnessAvailable + + ", mAutoBrightnessAvailable= " + mAutoBrightnessAvailable + "}"; } @@ -916,6 +927,7 @@ public class DisplayDeviceConfig { loadAmbientLightSensorFromConfigXml(); setProxSensorUnspecified(); loadAutoBrightnessConfigsFromConfigXml(); + loadAutoBrightnessAvailableFromConfigXml(); mLoadedFrom = ""; } @@ -934,6 +946,7 @@ public class DisplayDeviceConfig { setSimpleMappingStrategyValues(); loadAmbientLightSensorFromConfigXml(); setProxSensorUnspecified(); + loadAutoBrightnessAvailableFromConfigXml(); } private void copyUninitializedValuesFromSecondaryConfig(DisplayConfiguration defaultConfig) { @@ -1126,9 +1139,11 @@ public class DisplayDeviceConfig { } private void loadAutoBrightnessConfigValues(DisplayConfiguration config) { - loadAutoBrightnessBrighteningLightDebounce(config.getAutoBrightness()); - loadAutoBrightnessDarkeningLightDebounce(config.getAutoBrightness()); - loadAutoBrightnessDisplayBrightnessMapping(config.getAutoBrightness()); + final AutoBrightness autoBrightness = config.getAutoBrightness(); + loadAutoBrightnessBrighteningLightDebounce(autoBrightness); + loadAutoBrightnessDarkeningLightDebounce(autoBrightness); + loadAutoBrightnessDisplayBrightnessMapping(autoBrightness); + loadEnableAutoBrightness(autoBrightness); } /** @@ -1190,6 +1205,11 @@ public class DisplayDeviceConfig { } } + private void loadAutoBrightnessAvailableFromConfigXml() { + mAutoBrightnessAvailable = mContext.getResources().getBoolean( + R.bool.config_automatic_brightness_available); + } + private void loadBrightnessMapFromConfigXml() { // Use the config.xml mapping final Resources res = mContext.getResources(); @@ -1634,6 +1654,20 @@ public class DisplayDeviceConfig { 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 { public String type; public String name; diff --git a/services/core/java/com/android/server/display/DisplayPowerController.java b/services/core/java/com/android/server/display/DisplayPowerController.java index efd2e34144666..78470478d4902 100644 --- a/services/core/java/com/android/server/display/DisplayPowerController.java +++ b/services/core/java/com/android/server/display/DisplayPowerController.java @@ -558,13 +558,6 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call mScreenBrightnessForVrRangeMinimum = clampAbsoluteBrightness( 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( com.android.internal.R.bool.config_allowAutoBrightnessWhileDozing); @@ -938,6 +931,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call } private void setUpAutoBrightness(Resources resources, Handler handler) { + mUseSoftwareAutoBrightnessConfig = mDisplayDeviceConfig.isAutoBrightnessAvailable(); + if (!mUseSoftwareAutoBrightnessConfig) { return; } diff --git a/services/core/xsd/display-device-config/display-device-config.xsd b/services/core/xsd/display-device-config/display-device-config.xsd index 267cff6652bb1..98bad016500c3 100644 --- a/services/core/xsd/display-device-config/display-device-config.xsd +++ b/services/core/xsd/display-device-config/display-device-config.xsd @@ -354,6 +354,7 @@ +