summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author petsjonkin <petsjonkin@google.com> 2024-03-27 19:36:05 +0000
committer Oleg Petšjonkin <petsjonkin@google.com> 2024-03-28 18:54:20 +0000
commit9bca340c07499dabc3d34e25c73ec50b71ec798c (patch)
treee6679249e05921ee5baf935dedb5860aea93803f
parent1cc982e9cce0ff5aa02964d64d5719ea4b47aefd (diff)
Moving HysteresisLevels to DDC, cleanup duplicate code
Bug: b/331650248 Test: atest DisplayDeviceConfigTest Change-Id: I8061a9fd77c1e6f5793f5565485b36f11a6d0e6d
-rw-r--r--services/core/java/com/android/server/display/AutomaticBrightnessController.java13
-rw-r--r--services/core/java/com/android/server/display/DisplayDeviceConfig.java703
-rw-r--r--services/core/java/com/android/server/display/DisplayPowerController.java92
-rw-r--r--services/core/java/com/android/server/display/HysteresisLevels.java152
-rw-r--r--services/core/java/com/android/server/display/config/HysteresisLevels.java463
-rw-r--r--services/tests/displayservicetests/src/com/android/server/display/AutomaticBrightnessControllerTest.java1
-rw-r--r--services/tests/displayservicetests/src/com/android/server/display/DisplayDeviceConfigTest.java146
-rw-r--r--services/tests/displayservicetests/src/com/android/server/display/DisplayPowerControllerTest.java35
8 files changed, 604 insertions, 1001 deletions
diff --git a/services/core/java/com/android/server/display/AutomaticBrightnessController.java b/services/core/java/com/android/server/display/AutomaticBrightnessController.java
index 4aab9d26dbcb..06dc7f54dd8b 100644
--- a/services/core/java/com/android/server/display/AutomaticBrightnessController.java
+++ b/services/core/java/com/android/server/display/AutomaticBrightnessController.java
@@ -55,6 +55,7 @@ import com.android.internal.os.BackgroundThread;
import com.android.server.EventLogTags;
import com.android.server.display.brightness.BrightnessEvent;
import com.android.server.display.brightness.clamper.BrightnessClamperController;
+import com.android.server.display.config.HysteresisLevels;
import java.io.PrintWriter;
import java.lang.annotation.Retention;
@@ -673,14 +674,10 @@ public class AutomaticBrightnessController {
}
pw.println();
- pw.println(" mAmbientBrightnessThresholds=");
- mAmbientBrightnessThresholds.dump(pw);
- pw.println(" mScreenBrightnessThresholds=");
- mScreenBrightnessThresholds.dump(pw);
- pw.println(" mScreenBrightnessThresholdsIdle=");
- mScreenBrightnessThresholdsIdle.dump(pw);
- pw.println(" mAmbientBrightnessThresholdsIdle=");
- mAmbientBrightnessThresholdsIdle.dump(pw);
+ pw.println(" mAmbientBrightnessThresholds=" + mAmbientBrightnessThresholds);
+ pw.println(" mAmbientBrightnessThresholdsIdle=" + mAmbientBrightnessThresholdsIdle);
+ pw.println(" mScreenBrightnessThresholds=" + mScreenBrightnessThresholds);
+ pw.println(" mScreenBrightnessThresholdsIdle=" + mScreenBrightnessThresholdsIdle);
}
public float[] getLastSensorValues() {
diff --git a/services/core/java/com/android/server/display/DisplayDeviceConfig.java b/services/core/java/com/android/server/display/DisplayDeviceConfig.java
index 641b6a2f170b..019f3db42d0e 100644
--- a/services/core/java/com/android/server/display/DisplayDeviceConfig.java
+++ b/services/core/java/com/android/server/display/DisplayDeviceConfig.java
@@ -33,7 +33,6 @@ import android.os.Environment;
import android.os.PowerManager;
import android.text.TextUtils;
import android.util.MathUtils;
-import android.util.Pair;
import android.util.Slog;
import android.util.SparseArray;
import android.util.Spline;
@@ -46,7 +45,6 @@ import com.android.internal.display.BrightnessSynchronizer;
import com.android.server.display.config.AutoBrightness;
import com.android.server.display.config.BlockingZoneConfig;
import com.android.server.display.config.BrightnessLimitMap;
-import com.android.server.display.config.BrightnessThresholds;
import com.android.server.display.config.BrightnessThrottlingMap;
import com.android.server.display.config.BrightnessThrottlingPoint;
import com.android.server.display.config.Density;
@@ -58,6 +56,7 @@ import com.android.server.display.config.EvenDimmerBrightnessData;
import com.android.server.display.config.HbmTiming;
import com.android.server.display.config.HdrBrightnessData;
import com.android.server.display.config.HighBrightnessMode;
+import com.android.server.display.config.HysteresisLevels;
import com.android.server.display.config.IdleScreenRefreshRateTimeout;
import com.android.server.display.config.IdleScreenRefreshRateTimeoutLuxThresholdPoint;
import com.android.server.display.config.IdleScreenRefreshRateTimeoutLuxThresholds;
@@ -80,7 +79,6 @@ import com.android.server.display.config.SdrHdrRatioPoint;
import com.android.server.display.config.SensorData;
import com.android.server.display.config.ThermalStatus;
import com.android.server.display.config.ThermalThrottling;
-import com.android.server.display.config.ThresholdPoint;
import com.android.server.display.config.UsiVersion;
import com.android.server.display.config.XmlParser;
import com.android.server.display.feature.DisplayManagerFlags;
@@ -625,13 +623,6 @@ public class DisplayDeviceConfig {
private static final int DEFAULT_HIGH_REFRESH_RATE = 0;
private static final float[] DEFAULT_BRIGHTNESS_THRESHOLDS = new float[]{};
- private static final float[] DEFAULT_AMBIENT_THRESHOLD_LEVELS = new float[]{0f};
- private static final float[] DEFAULT_AMBIENT_BRIGHTENING_THRESHOLDS = new float[]{100f};
- private static final float[] DEFAULT_AMBIENT_DARKENING_THRESHOLDS = new float[]{200f};
- private static final float[] DEFAULT_SCREEN_THRESHOLD_LEVELS = new float[]{0f};
- private static final float[] DEFAULT_SCREEN_BRIGHTENING_THRESHOLDS = new float[]{100f};
- private static final float[] DEFAULT_SCREEN_DARKENING_THRESHOLDS = new float[]{200f};
-
private static final int INTERPOLATION_DEFAULT = 0;
private static final int INTERPOLATION_LINEAR = 1;
@@ -713,38 +704,16 @@ public class DisplayDeviceConfig {
private long mBrightnessRampIncreaseMaxIdleMillis = 0;
private int mAmbientHorizonLong = AMBIENT_LIGHT_LONG_HORIZON_MILLIS;
private int mAmbientHorizonShort = AMBIENT_LIGHT_SHORT_HORIZON_MILLIS;
- private float mScreenBrighteningMinThreshold = 0.0f; // Retain behaviour as though there is
- private float mScreenBrighteningMinThresholdIdle = 0.0f; // no minimum threshold for change in
- private float mScreenDarkeningMinThreshold = 0.0f; // screen brightness or ambient
- private float mScreenDarkeningMinThresholdIdle = 0.0f; // brightness.
- private float mAmbientLuxBrighteningMinThreshold = 0.0f;
- private float mAmbientLuxBrighteningMinThresholdIdle = 0.0f;
- private float mAmbientLuxDarkeningMinThreshold = 0.0f;
- private float mAmbientLuxDarkeningMinThresholdIdle = 0.0f;
-
- // Screen brightness thresholds levels & percentages
- private float[] mScreenBrighteningLevels = DEFAULT_SCREEN_THRESHOLD_LEVELS;
- private float[] mScreenBrighteningPercentages = DEFAULT_SCREEN_BRIGHTENING_THRESHOLDS;
- private float[] mScreenDarkeningLevels = DEFAULT_SCREEN_THRESHOLD_LEVELS;
- private float[] mScreenDarkeningPercentages = DEFAULT_SCREEN_DARKENING_THRESHOLDS;
-
- // Screen brightness thresholds levels & percentages for idle mode
- private float[] mScreenBrighteningLevelsIdle = DEFAULT_SCREEN_THRESHOLD_LEVELS;
- private float[] mScreenBrighteningPercentagesIdle = DEFAULT_SCREEN_BRIGHTENING_THRESHOLDS;
- private float[] mScreenDarkeningLevelsIdle = DEFAULT_SCREEN_THRESHOLD_LEVELS;
- private float[] mScreenDarkeningPercentagesIdle = DEFAULT_SCREEN_DARKENING_THRESHOLDS;
-
- // Ambient brightness thresholds levels & percentages
- private float[] mAmbientBrighteningLevels = DEFAULT_AMBIENT_THRESHOLD_LEVELS;
- private float[] mAmbientBrighteningPercentages = DEFAULT_AMBIENT_BRIGHTENING_THRESHOLDS;
- private float[] mAmbientDarkeningLevels = DEFAULT_AMBIENT_THRESHOLD_LEVELS;
- private float[] mAmbientDarkeningPercentages = DEFAULT_AMBIENT_DARKENING_THRESHOLDS;
-
- // Ambient brightness thresholds levels & percentages for idle mode
- private float[] mAmbientBrighteningLevelsIdle = DEFAULT_AMBIENT_THRESHOLD_LEVELS;
- private float[] mAmbientBrighteningPercentagesIdle = DEFAULT_AMBIENT_BRIGHTENING_THRESHOLDS;
- private float[] mAmbientDarkeningLevelsIdle = DEFAULT_AMBIENT_THRESHOLD_LEVELS;
- private float[] mAmbientDarkeningPercentagesIdle = DEFAULT_AMBIENT_DARKENING_THRESHOLDS;
+
+ // Hysteresis levels for screen/ambient brightness for normal/idle modes
+ private HysteresisLevels mScreenBrightnessHysteresis =
+ HysteresisLevels.loadDisplayBrightnessConfig(null, null);
+ private HysteresisLevels mScreenBrightnessIdleHysteresis =
+ HysteresisLevels.loadDisplayBrightnessIdleConfig(null, null);
+ private HysteresisLevels mAmbientBrightnessHysteresis =
+ HysteresisLevels.loadAmbientBrightnessConfig(null, null);
+ private HysteresisLevels mAmbientBrightnessIdleHysteresis =
+ HysteresisLevels.loadAmbientBrightnessIdleConfig(null, null);
// A mapping between screen off sensor values and lux values
private int[] mScreenOffBrightnessSensorValueToLux;
@@ -1302,324 +1271,20 @@ public class DisplayDeviceConfig {
return mAmbientHorizonShort;
}
- /**
- * The minimum value for the screen brightness increase to actually occur.
- * @return float value in brightness scale of 0 - 1.
- */
- public float getScreenBrighteningMinThreshold() {
- return mScreenBrighteningMinThreshold;
- }
-
- /**
- * The minimum value for the screen brightness decrease to actually occur.
- * @return float value in brightness scale of 0 - 1.
- */
- public float getScreenDarkeningMinThreshold() {
- return mScreenDarkeningMinThreshold;
- }
-
- /**
- * The minimum value for the screen brightness increase to actually occur while in idle screen
- * brightness mode.
- * @return float value in brightness scale of 0 - 1.
- */
- public float getScreenBrighteningMinThresholdIdle() {
- return mScreenBrighteningMinThresholdIdle;
- }
-
- /**
- * The minimum value for the screen brightness decrease to actually occur while in idle screen
- * brightness mode.
- * @return float value in brightness scale of 0 - 1.
- */
- public float getScreenDarkeningMinThresholdIdle() {
- return mScreenDarkeningMinThresholdIdle;
- }
-
- /**
- * The minimum value for the ambient lux increase for a screen brightness change to actually
- * occur.
- * @return float value in lux.
- */
- public float getAmbientLuxBrighteningMinThreshold() {
- return mAmbientLuxBrighteningMinThreshold;
- }
-
- /**
- * The minimum value for the ambient lux decrease for a screen brightness change to actually
- * occur.
- * @return float value in lux.
- */
- public float getAmbientLuxDarkeningMinThreshold() {
- return mAmbientLuxDarkeningMinThreshold;
- }
-
- /**
- * The minimum value for the ambient lux increase for a screen brightness change to actually
- * occur while in idle screen brightness mode.
- * @return float value in lux.
- */
- public float getAmbientLuxBrighteningMinThresholdIdle() {
- return mAmbientLuxBrighteningMinThresholdIdle;
- }
-
- /**
- * The minimum value for the ambient lux decrease for a screen brightness change to actually
- * occur while in idle screen brightness mode.
- * @return float value in lux.
- */
- public float getAmbientLuxDarkeningMinThresholdIdle() {
- return mAmbientLuxDarkeningMinThresholdIdle;
- }
-
- /**
- * The array that describes the range of screen brightness that each threshold percentage
- * applies within.
- *
- * The (zero-based) index is calculated as follows
- * value = current screen brightness value
- * level = mScreenBrighteningLevels
- *
- * condition return
- * value < level[0] = 0.0f
- * level[n] <= value < level[n+1] = mScreenBrighteningPercentages[n]
- * level[MAX] <= value = mScreenBrighteningPercentages[MAX]
- *
- * @return the screen brightness levels between 0.0 and 1.0 for which each
- * mScreenBrighteningPercentages applies
- */
- public float[] getScreenBrighteningLevels() {
- return mScreenBrighteningLevels;
- }
-
- /**
- * The array that describes the screen brightening threshold percentage change at each screen
- * brightness level described in mScreenBrighteningLevels.
- *
- * @return the percentages between 0 and 100 of brightness increase required in order for the
- * screen brightness to change
- */
- public float[] getScreenBrighteningPercentages() {
- return mScreenBrighteningPercentages;
- }
-
- /**
- * The array that describes the range of screen brightness that each threshold percentage
- * applies within.
- *
- * The (zero-based) index is calculated as follows
- * value = current screen brightness value
- * level = mScreenDarkeningLevels
- *
- * condition return
- * value < level[0] = 0.0f
- * level[n] <= value < level[n+1] = mScreenDarkeningPercentages[n]
- * level[MAX] <= value = mScreenDarkeningPercentages[MAX]
- *
- * @return the screen brightness levels between 0.0 and 1.0 for which each
- * mScreenDarkeningPercentages applies
- */
- public float[] getScreenDarkeningLevels() {
- return mScreenDarkeningLevels;
- }
-
- /**
- * The array that describes the screen darkening threshold percentage change at each screen
- * brightness level described in mScreenDarkeningLevels.
- *
- * @return the percentages between 0 and 100 of brightness decrease required in order for the
- * screen brightness to change
- */
- public float[] getScreenDarkeningPercentages() {
- return mScreenDarkeningPercentages;
- }
-
- /**
- * The array that describes the range of ambient brightness that each threshold
- * percentage applies within.
- *
- * The (zero-based) index is calculated as follows
- * value = current ambient brightness value
- * level = mAmbientBrighteningLevels
- *
- * condition return
- * value < level[0] = 0.0f
- * level[n] <= value < level[n+1] = mAmbientBrighteningPercentages[n]
- * level[MAX] <= value = mAmbientBrighteningPercentages[MAX]
- *
- * @return the ambient brightness levels from 0 lux upwards for which each
- * mAmbientBrighteningPercentages applies
- */
- public float[] getAmbientBrighteningLevels() {
- return mAmbientBrighteningLevels;
- }
-
- /**
- * The array that describes the ambient brightening threshold percentage change at each ambient
- * brightness level described in mAmbientBrighteningLevels.
- *
- * @return the percentages between 0 and 100 of brightness increase required in order for the
- * screen brightness to change
- */
- public float[] getAmbientBrighteningPercentages() {
- return mAmbientBrighteningPercentages;
- }
-
- /**
- * The array that describes the range of ambient brightness that each threshold percentage
- * applies within.
- *
- * The (zero-based) index is calculated as follows
- * value = current ambient brightness value
- * level = mAmbientDarkeningLevels
- *
- * condition return
- * value < level[0] = 0.0f
- * level[n] <= value < level[n+1] = mAmbientDarkeningPercentages[n]
- * level[MAX] <= value = mAmbientDarkeningPercentages[MAX]
- *
- * @return the ambient brightness levels from 0 lux upwards for which each
- * mAmbientDarkeningPercentages applies
- */
- public float[] getAmbientDarkeningLevels() {
- return mAmbientDarkeningLevels;
- }
-
- /**
- * The array that describes the ambient darkening threshold percentage change at each ambient
- * brightness level described in mAmbientDarkeningLevels.
- *
- * @return the percentages between 0 and 100 of brightness decrease required in order for the
- * screen brightness to change
- */
- public float[] getAmbientDarkeningPercentages() {
- return mAmbientDarkeningPercentages;
- }
-
- /**
- * The array that describes the range of screen brightness that each threshold percentage
- * applies within whilst in idle screen brightness mode.
- *
- * The (zero-based) index is calculated as follows
- * value = current screen brightness value
- * level = mScreenBrighteningLevelsIdle
- *
- * condition return
- * value < level[0] = 0.0f
- * level[n] <= value < level[n+1] = mScreenBrighteningPercentagesIdle[n]
- * level[MAX] <= value = mScreenBrighteningPercentagesIdle[MAX]
- *
- * @return the screen brightness levels between 0.0 and 1.0 for which each
- * mScreenBrighteningPercentagesIdle applies
- */
- public float[] getScreenBrighteningLevelsIdle() {
- return mScreenBrighteningLevelsIdle;
- }
-
- /**
- * The array that describes the screen brightening threshold percentage change at each screen
- * brightness level described in mScreenBrighteningLevelsIdle.
- *
- * @return the percentages between 0 and 100 of brightness increase required in order for the
- * screen brightness to change while in idle mode.
- */
- public float[] getScreenBrighteningPercentagesIdle() {
- return mScreenBrighteningPercentagesIdle;
- }
-
- /**
- * The array that describes the range of screen brightness that each threshold percentage
- * applies within whilst in idle screen brightness mode.
- *
- * The (zero-based) index is calculated as follows
- * value = current screen brightness value
- * level = mScreenDarkeningLevelsIdle
- *
- * condition return
- * value < level[0] = 0.0f
- * level[n] <= value < level[n+1] = mScreenDarkeningPercentagesIdle[n]
- * level[MAX] <= value = mScreenDarkeningPercentagesIdle[MAX]
- *
- * @return the screen brightness levels between 0.0 and 1.0 for which each
- * mScreenDarkeningPercentagesIdle applies
- */
- public float[] getScreenDarkeningLevelsIdle() {
- return mScreenDarkeningLevelsIdle;
+ public HysteresisLevels getAmbientBrightnessHysteresis() {
+ return mAmbientBrightnessHysteresis;
}
- /**
- * The array that describes the screen darkening threshold percentage change at each screen
- * brightness level described in mScreenDarkeningLevelsIdle.
- *
- * @return the percentages between 0 and 100 of brightness decrease required in order for the
- * screen brightness to change while in idle mode.
- */
- public float[] getScreenDarkeningPercentagesIdle() {
- return mScreenDarkeningPercentagesIdle;
+ public HysteresisLevels getAmbientBrightnessIdleHysteresis() {
+ return mAmbientBrightnessIdleHysteresis;
}
- /**
- * The array that describes the range of ambient brightness that each threshold percentage
- * applies within whilst in idle screen brightness mode.
- *
- * The (zero-based) index is calculated as follows
- * value = current ambient brightness value
- * level = mAmbientBrighteningLevelsIdle
- *
- * condition return
- * value < level[0] = 0.0f
- * level[n] <= value < level[n+1] = mAmbientBrighteningPercentagesIdle[n]
- * level[MAX] <= value = mAmbientBrighteningPercentagesIdle[MAX]
- *
- * @return the ambient brightness levels from 0 lux upwards for which each
- * mAmbientBrighteningPercentagesIdle applies
- */
- public float[] getAmbientBrighteningLevelsIdle() {
- return mAmbientBrighteningLevelsIdle;
+ public HysteresisLevels getScreenBrightnessHysteresis() {
+ return mScreenBrightnessHysteresis;
}
- /**
- * The array that describes the ambient brightness threshold percentage change whilst in
- * idle screen brightness mode at each ambient brightness level described in
- * mAmbientBrighteningLevelsIdle.
- *
- * @return the percentages between 0 and 100 of ambient brightness increase required in order
- * for the screen brightness to change
- */
- public float[] getAmbientBrighteningPercentagesIdle() {
- return mAmbientBrighteningPercentagesIdle;
- }
-
- /**
- * The array that describes the range of ambient brightness that each threshold percentage
- * applies within whilst in idle screen brightness mode.
- *
- * The (zero-based) index is calculated as follows
- * value = current ambient brightness value
- * level = mAmbientDarkeningLevelsIdle
- *
- * condition return
- * value < level[0] = 0.0f
- * level[n] <= value < level[n+1] = mAmbientDarkeningPercentagesIdle[n]
- * level[MAX] <= value = mAmbientDarkeningPercentagesIdle[MAX]
- *
- * @return the ambient brightness levels from 0 lux upwards for which each
- * mAmbientDarkeningPercentagesIdle applies
- */
- public float[] getAmbientDarkeningLevelsIdle() {
- return mAmbientDarkeningLevelsIdle;
- }
-
- /**
- * The array that describes the ambient brightness threshold percentage change whilst in
- * idle screen brightness mode at each ambient brightness level described in
- * mAmbientDarkeningLevelsIdle.
- *
- * @return the percentages between 0 and 100 of ambient brightness decrease required in order
- * for the screen brightness to change
- */
- public float[] getAmbientDarkeningPercentagesIdle() {
- return mAmbientDarkeningPercentagesIdle;
+ public HysteresisLevels getScreenBrightnessIdleHysteresis() {
+ return mScreenBrightnessIdleHysteresis;
}
public SensorData getAmbientLightSensor() {
@@ -1986,49 +1651,13 @@ public class DisplayDeviceConfig {
+ "mAmbientHorizonLong=" + mAmbientHorizonLong
+ ", mAmbientHorizonShort=" + mAmbientHorizonShort
+ "\n"
- + "mScreenDarkeningMinThreshold=" + mScreenDarkeningMinThreshold
- + ", mScreenDarkeningMinThresholdIdle=" + mScreenDarkeningMinThresholdIdle
- + ", mScreenBrighteningMinThreshold=" + mScreenBrighteningMinThreshold
- + ", mScreenBrighteningMinThresholdIdle=" + mScreenBrighteningMinThresholdIdle
- + ", mAmbientLuxDarkeningMinThreshold=" + mAmbientLuxDarkeningMinThreshold
- + ", mAmbientLuxDarkeningMinThresholdIdle=" + mAmbientLuxDarkeningMinThresholdIdle
- + ", mAmbientLuxBrighteningMinThreshold=" + mAmbientLuxBrighteningMinThreshold
- + ", mAmbientLuxBrighteningMinThresholdIdle="
- + mAmbientLuxBrighteningMinThresholdIdle
+ + "mAmbientBrightnessHysteresis=" + mAmbientBrightnessHysteresis
+ + "\n"
+ + "mAmbientIdleHysteresis=" + mAmbientBrightnessIdleHysteresis
+ "\n"
- + "mScreenBrighteningLevels=" + Arrays.toString(
- mScreenBrighteningLevels)
- + ", mScreenBrighteningPercentages=" + Arrays.toString(
- mScreenBrighteningPercentages)
- + ", mScreenDarkeningLevels=" + Arrays.toString(
- mScreenDarkeningLevels)
- + ", mScreenDarkeningPercentages=" + Arrays.toString(
- mScreenDarkeningPercentages)
- + ", mAmbientBrighteningLevels=" + Arrays.toString(
- mAmbientBrighteningLevels)
- + ", mAmbientBrighteningPercentages=" + Arrays.toString(
- mAmbientBrighteningPercentages)
- + ", mAmbientDarkeningLevels=" + Arrays.toString(
- mAmbientDarkeningLevels)
- + ", mAmbientDarkeningPercentages=" + Arrays.toString(
- mAmbientDarkeningPercentages)
+ + "mScreenBrightnessHysteresis=" + mScreenBrightnessHysteresis
+ "\n"
- + "mAmbientBrighteningLevelsIdle=" + Arrays.toString(
- mAmbientBrighteningLevelsIdle)
- + ", mAmbientBrighteningPercentagesIdle=" + Arrays.toString(
- mAmbientBrighteningPercentagesIdle)
- + ", mAmbientDarkeningLevelsIdle=" + Arrays.toString(
- mAmbientDarkeningLevelsIdle)
- + ", mAmbientDarkeningPercentagesIdle=" + Arrays.toString(
- mAmbientDarkeningPercentagesIdle)
- + ", mScreenBrighteningLevelsIdle=" + Arrays.toString(
- mScreenBrighteningLevelsIdle)
- + ", mScreenBrighteningPercentagesIdle=" + Arrays.toString(
- mScreenBrighteningPercentagesIdle)
- + ", mScreenDarkeningLevelsIdle=" + Arrays.toString(
- mScreenDarkeningLevelsIdle)
- + ", mScreenDarkeningPercentagesIdle=" + Arrays.toString(
- mScreenDarkeningPercentagesIdle)
+ + "mScreenBrightnessIdleHysteresis=" + mScreenBrightnessIdleHysteresis
+ "\n"
+ "mAmbientLightSensor=" + mAmbientLightSensor
+ ", mScreenOffBrightnessSensor=" + mScreenOffBrightnessSensor
@@ -3138,281 +2767,15 @@ public class DisplayDeviceConfig {
}
private void loadBrightnessChangeThresholds(DisplayConfiguration config) {
- loadDisplayBrightnessThresholds(config);
- loadAmbientBrightnessThresholds(config);
- loadDisplayBrightnessThresholdsIdle(config);
- loadAmbientBrightnessThresholdsIdle(config);
- }
-
- private void loadDisplayBrightnessThresholds(DisplayConfiguration config) {
- BrightnessThresholds brighteningScreen = null;
- BrightnessThresholds darkeningScreen = null;
- if (config != null && config.getDisplayBrightnessChangeThresholds() != null) {
- brighteningScreen =
- config.getDisplayBrightnessChangeThresholds().getBrighteningThresholds();
- darkeningScreen =
- config.getDisplayBrightnessChangeThresholds().getDarkeningThresholds();
-
- }
-
- // Screen bright/darkening threshold levels for active mode
- Pair<float[], float[]> screenBrighteningPair = getBrightnessLevelAndPercentage(
- brighteningScreen,
- com.android.internal.R.array.config_screenThresholdLevels,
- com.android.internal.R.array.config_screenBrighteningThresholds,
- DEFAULT_SCREEN_THRESHOLD_LEVELS, DEFAULT_SCREEN_BRIGHTENING_THRESHOLDS,
- /* potentialOldBrightnessScale= */ true);
-
- mScreenBrighteningLevels = screenBrighteningPair.first;
- mScreenBrighteningPercentages = screenBrighteningPair.second;
-
- Pair<float[], float[]> screenDarkeningPair = getBrightnessLevelAndPercentage(
- darkeningScreen,
- com.android.internal.R.array.config_screenThresholdLevels,
- com.android.internal.R.array.config_screenDarkeningThresholds,
- DEFAULT_SCREEN_THRESHOLD_LEVELS, DEFAULT_SCREEN_DARKENING_THRESHOLDS,
- /* potentialOldBrightnessScale= */ true);
- mScreenDarkeningLevels = screenDarkeningPair.first;
- mScreenDarkeningPercentages = screenDarkeningPair.second;
-
- // Screen bright/darkening threshold minimums for active mode
- if (brighteningScreen != null && brighteningScreen.getMinimum() != null) {
- mScreenBrighteningMinThreshold = brighteningScreen.getMinimum().floatValue();
- }
- if (darkeningScreen != null && darkeningScreen.getMinimum() != null) {
- mScreenDarkeningMinThreshold = darkeningScreen.getMinimum().floatValue();
- }
- }
-
- private void loadAmbientBrightnessThresholds(DisplayConfiguration config) {
- // Ambient Brightness Threshold Levels
- BrightnessThresholds brighteningAmbientLux = null;
- BrightnessThresholds darkeningAmbientLux = null;
- if (config != null && config.getAmbientBrightnessChangeThresholds() != null) {
- brighteningAmbientLux =
- config.getAmbientBrightnessChangeThresholds().getBrighteningThresholds();
- darkeningAmbientLux =
- config.getAmbientBrightnessChangeThresholds().getDarkeningThresholds();
- }
-
- // Ambient bright/darkening threshold levels for active mode
- Pair<float[], float[]> ambientBrighteningPair = getBrightnessLevelAndPercentage(
- brighteningAmbientLux,
- com.android.internal.R.array.config_ambientThresholdLevels,
- com.android.internal.R.array.config_ambientBrighteningThresholds,
- DEFAULT_AMBIENT_THRESHOLD_LEVELS, DEFAULT_AMBIENT_BRIGHTENING_THRESHOLDS);
- mAmbientBrighteningLevels = ambientBrighteningPair.first;
- mAmbientBrighteningPercentages = ambientBrighteningPair.second;
-
- Pair<float[], float[]> ambientDarkeningPair = getBrightnessLevelAndPercentage(
- darkeningAmbientLux,
- com.android.internal.R.array.config_ambientThresholdLevels,
- com.android.internal.R.array.config_ambientDarkeningThresholds,
- DEFAULT_AMBIENT_THRESHOLD_LEVELS, DEFAULT_AMBIENT_DARKENING_THRESHOLDS);
- mAmbientDarkeningLevels = ambientDarkeningPair.first;
- mAmbientDarkeningPercentages = ambientDarkeningPair.second;
-
- // Ambient bright/darkening threshold minimums for active/idle mode
- if (brighteningAmbientLux != null && brighteningAmbientLux.getMinimum() != null) {
- mAmbientLuxBrighteningMinThreshold =
- brighteningAmbientLux.getMinimum().floatValue();
- }
-
- if (darkeningAmbientLux != null && darkeningAmbientLux.getMinimum() != null) {
- mAmbientLuxDarkeningMinThreshold = darkeningAmbientLux.getMinimum().floatValue();
- }
- }
-
- private void loadDisplayBrightnessThresholdsIdle(DisplayConfiguration config) {
- BrightnessThresholds brighteningScreenIdle = null;
- BrightnessThresholds darkeningScreenIdle = null;
- if (config != null && config.getDisplayBrightnessChangeThresholdsIdle() != null) {
- brighteningScreenIdle =
- config.getDisplayBrightnessChangeThresholdsIdle().getBrighteningThresholds();
- darkeningScreenIdle =
- config.getDisplayBrightnessChangeThresholdsIdle().getDarkeningThresholds();
- }
-
- Pair<float[], float[]> screenBrighteningPair = getBrightnessLevelAndPercentage(
- brighteningScreenIdle,
- com.android.internal.R.array.config_screenThresholdLevels,
- com.android.internal.R.array.config_screenBrighteningThresholds,
- DEFAULT_SCREEN_THRESHOLD_LEVELS, DEFAULT_SCREEN_BRIGHTENING_THRESHOLDS,
- /* potentialOldBrightnessScale= */ true);
- mScreenBrighteningLevelsIdle = screenBrighteningPair.first;
- mScreenBrighteningPercentagesIdle = screenBrighteningPair.second;
-
- Pair<float[], float[]> screenDarkeningPair = getBrightnessLevelAndPercentage(
- darkeningScreenIdle,
- com.android.internal.R.array.config_screenThresholdLevels,
- com.android.internal.R.array.config_screenDarkeningThresholds,
- DEFAULT_SCREEN_THRESHOLD_LEVELS, DEFAULT_SCREEN_DARKENING_THRESHOLDS,
- /* potentialOldBrightnessScale= */ true);
- mScreenDarkeningLevelsIdle = screenDarkeningPair.first;
- mScreenDarkeningPercentagesIdle = screenDarkeningPair.second;
-
- if (brighteningScreenIdle != null
- && brighteningScreenIdle.getMinimum() != null) {
- mScreenBrighteningMinThresholdIdle =
- brighteningScreenIdle.getMinimum().floatValue();
- }
- if (darkeningScreenIdle != null && darkeningScreenIdle.getMinimum() != null) {
- mScreenDarkeningMinThresholdIdle =
- darkeningScreenIdle.getMinimum().floatValue();
- }
- }
-
- private void loadAmbientBrightnessThresholdsIdle(DisplayConfiguration config) {
- BrightnessThresholds brighteningAmbientLuxIdle = null;
- BrightnessThresholds darkeningAmbientLuxIdle = null;
- if (config != null && config.getAmbientBrightnessChangeThresholdsIdle() != null) {
- brighteningAmbientLuxIdle =
- config.getAmbientBrightnessChangeThresholdsIdle().getBrighteningThresholds();
- darkeningAmbientLuxIdle =
- config.getAmbientBrightnessChangeThresholdsIdle().getDarkeningThresholds();
- }
-
- Pair<float[], float[]> ambientBrighteningPair = getBrightnessLevelAndPercentage(
- brighteningAmbientLuxIdle,
- com.android.internal.R.array.config_ambientThresholdLevels,
- com.android.internal.R.array.config_ambientBrighteningThresholds,
- DEFAULT_AMBIENT_THRESHOLD_LEVELS, DEFAULT_AMBIENT_BRIGHTENING_THRESHOLDS);
- mAmbientBrighteningLevelsIdle = ambientBrighteningPair.first;
- mAmbientBrighteningPercentagesIdle = ambientBrighteningPair.second;
-
- Pair<float[], float[]> ambientDarkeningPair = getBrightnessLevelAndPercentage(
- darkeningAmbientLuxIdle,
- com.android.internal.R.array.config_ambientThresholdLevels,
- com.android.internal.R.array.config_ambientDarkeningThresholds,
- DEFAULT_AMBIENT_THRESHOLD_LEVELS, DEFAULT_AMBIENT_DARKENING_THRESHOLDS);
- mAmbientDarkeningLevelsIdle = ambientDarkeningPair.first;
- mAmbientDarkeningPercentagesIdle = ambientDarkeningPair.second;
-
- if (brighteningAmbientLuxIdle != null
- && brighteningAmbientLuxIdle.getMinimum() != null) {
- mAmbientLuxBrighteningMinThresholdIdle =
- brighteningAmbientLuxIdle.getMinimum().floatValue();
- }
-
- if (darkeningAmbientLuxIdle != null && darkeningAmbientLuxIdle.getMinimum() != null) {
- mAmbientLuxDarkeningMinThresholdIdle =
- darkeningAmbientLuxIdle.getMinimum().floatValue();
- }
- }
-
- private Pair<float[], float[]> getBrightnessLevelAndPercentage(BrightnessThresholds thresholds,
- int configFallbackThreshold, int configFallbackPercentage, float[] defaultLevels,
- float[] defaultPercentage) {
- return getBrightnessLevelAndPercentage(thresholds, configFallbackThreshold,
- configFallbackPercentage, defaultLevels, defaultPercentage, false);
- }
-
- // Returns two float arrays, one of the brightness levels and one of the corresponding threshold
- // percentages for brightness levels at or above the lux value.
- // Historically, config.xml would have an array for brightness levels that was 1 shorter than
- // the levels array. Now we prepend a 0 to this array so they can be treated the same in the
- // rest of the framework. Values were also defined in different units (permille vs percent).
- private Pair<float[], float[]> getBrightnessLevelAndPercentage(BrightnessThresholds thresholds,
- int configFallbackThreshold, int configFallbackPermille,
- float[] defaultLevels, float[] defaultPercentage,
- boolean potentialOldBrightnessScale) {
- if (thresholds != null
- && thresholds.getBrightnessThresholdPoints() != null
- && thresholds.getBrightnessThresholdPoints()
- .getBrightnessThresholdPoint().size() != 0) {
-
- // The level and percentages arrays are equal length in the ddc (new system)
- List<ThresholdPoint> points =
- thresholds.getBrightnessThresholdPoints().getBrightnessThresholdPoint();
- final int size = points.size();
-
- float[] thresholdLevels = new float[size];
- float[] thresholdPercentages = new float[size];
-
- int i = 0;
- for (ThresholdPoint point : points) {
- thresholdLevels[i] = point.getThreshold().floatValue();
- thresholdPercentages[i] = point.getPercentage().floatValue();
- i++;
- }
- return new Pair<>(thresholdLevels, thresholdPercentages);
- } else {
- // The level and percentages arrays are unequal length in config.xml (old system)
- // We prefix the array with a 0 value to ensure they can be handled consistently
- // with the new system.
-
- // Load levels array
- int[] configThresholdArray = mContext.getResources().getIntArray(
- configFallbackThreshold);
- int configThresholdsSize;
- if (configThresholdArray == null || configThresholdArray.length == 0) {
- configThresholdsSize = 1;
- } else {
- configThresholdsSize = configThresholdArray.length + 1;
- }
-
-
- // Load percentage array
- int[] configPermille = mContext.getResources().getIntArray(
- configFallbackPermille);
-
- // Ensure lengths match up
- boolean emptyArray = configPermille == null || configPermille.length == 0;
- if (emptyArray && configThresholdsSize == 1) {
- return new Pair<>(defaultLevels, defaultPercentage);
- }
- if (emptyArray || configPermille.length != configThresholdsSize) {
- throw new IllegalArgumentException(
- "Brightness threshold arrays do not align in length");
- }
-
- // Calculate levels array
- float[] configThresholdWithZeroPrefixed = new float[configThresholdsSize];
- // Start at 1, so that 0 index value is 0.0f (default)
- for (int i = 1; i < configThresholdsSize; i++) {
- configThresholdWithZeroPrefixed[i] = (float) configThresholdArray[i - 1];
- }
- if (potentialOldBrightnessScale) {
- configThresholdWithZeroPrefixed =
- constraintInRangeIfNeeded(configThresholdWithZeroPrefixed);
- }
-
- // Calculate percentages array
- float[] configPercentage = new float[configThresholdsSize];
- for (int i = 0; i < configPermille.length; i++) {
- configPercentage[i] = configPermille[i] / 10.0f;
- } return new Pair<>(configThresholdWithZeroPrefixed, configPercentage);
- }
- }
-
- /**
- * This check is due to historical reasons, where screen thresholdLevels used to be
- * integer values in the range of [0-255], but then was changed to be float values from [0,1].
- * To accommodate both the possibilities, we first check if all the thresholdLevels are in
- * [0,1], and if not, we divide all the levels with 255 to bring them down to the same scale.
- */
- private float[] constraintInRangeIfNeeded(float[] thresholdLevels) {
- if (isAllInRange(thresholdLevels, /* minValueInclusive= */ 0.0f,
- /* maxValueInclusive= */ 1.0f)) {
- return thresholdLevels;
- }
-
- Slog.w(TAG, "Detected screen thresholdLevels on a deprecated brightness scale");
- float[] thresholdLevelsScaled = new float[thresholdLevels.length];
- for (int index = 0; thresholdLevels.length > index; ++index) {
- thresholdLevelsScaled[index] = thresholdLevels[index] / 255.0f;
- }
- return thresholdLevelsScaled;
- }
-
- private boolean isAllInRange(float[] configArray, float minValueInclusive,
- float maxValueInclusive) {
- for (float v : configArray) {
- if (v < minValueInclusive || v > maxValueInclusive) {
- return false;
- }
- }
- return true;
+ Resources res = mContext.getResources();
+ mScreenBrightnessHysteresis =
+ HysteresisLevels.loadDisplayBrightnessConfig(config, res);
+ mScreenBrightnessIdleHysteresis =
+ HysteresisLevels.loadDisplayBrightnessIdleConfig(config, res);
+ mAmbientBrightnessHysteresis =
+ HysteresisLevels.loadAmbientBrightnessConfig(config, res);
+ mAmbientBrightnessIdleHysteresis =
+ HysteresisLevels.loadAmbientBrightnessIdleConfig(config, res);
}
private boolean thermalStatusIsValid(ThermalStatus value) {
diff --git a/services/core/java/com/android/server/display/DisplayPowerController.java b/services/core/java/com/android/server/display/DisplayPowerController.java
index b21a89a92803..404c3ad3a51b 100644
--- a/services/core/java/com/android/server/display/DisplayPowerController.java
+++ b/services/core/java/com/android/server/display/DisplayPowerController.java
@@ -86,6 +86,7 @@ import com.android.server.display.brightness.clamper.BrightnessClamperController
import com.android.server.display.brightness.strategy.AutomaticBrightnessStrategy;
import com.android.server.display.color.ColorDisplayService.ColorDisplayServiceInternal;
import com.android.server.display.color.ColorDisplayService.ReduceBrightColorsListener;
+import com.android.server.display.config.HysteresisLevels;
import com.android.server.display.feature.DisplayManagerFlags;
import com.android.server.display.layout.Layout;
import com.android.server.display.state.DisplayStateController;
@@ -1050,76 +1051,20 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
if (defaultModeBrightnessMapper != null) {
// Ambient Lux - Active Mode Brightness Thresholds
- float[] ambientBrighteningThresholds =
- mDisplayDeviceConfig.getAmbientBrighteningPercentages();
- float[] ambientDarkeningThresholds =
- mDisplayDeviceConfig.getAmbientDarkeningPercentages();
- float[] ambientBrighteningLevels =
- mDisplayDeviceConfig.getAmbientBrighteningLevels();
- float[] ambientDarkeningLevels =
- mDisplayDeviceConfig.getAmbientDarkeningLevels();
- float ambientDarkeningMinThreshold =
- mDisplayDeviceConfig.getAmbientLuxDarkeningMinThreshold();
- float ambientBrighteningMinThreshold =
- mDisplayDeviceConfig.getAmbientLuxBrighteningMinThreshold();
- HysteresisLevels ambientBrightnessThresholds = mInjector.getHysteresisLevels(
- ambientBrighteningThresholds, ambientDarkeningThresholds,
- ambientBrighteningLevels, ambientDarkeningLevels, ambientDarkeningMinThreshold,
- ambientBrighteningMinThreshold);
+ HysteresisLevels ambientBrightnessThresholds =
+ mDisplayDeviceConfig.getAmbientBrightnessHysteresis();
// Display - Active Mode Brightness Thresholds
- float[] screenBrighteningThresholds =
- mDisplayDeviceConfig.getScreenBrighteningPercentages();
- float[] screenDarkeningThresholds =
- mDisplayDeviceConfig.getScreenDarkeningPercentages();
- float[] screenBrighteningLevels =
- mDisplayDeviceConfig.getScreenBrighteningLevels();
- float[] screenDarkeningLevels =
- mDisplayDeviceConfig.getScreenDarkeningLevels();
- float screenDarkeningMinThreshold =
- mDisplayDeviceConfig.getScreenDarkeningMinThreshold();
- float screenBrighteningMinThreshold =
- mDisplayDeviceConfig.getScreenBrighteningMinThreshold();
- HysteresisLevels screenBrightnessThresholds = mInjector.getHysteresisLevels(
- screenBrighteningThresholds, screenDarkeningThresholds,
- screenBrighteningLevels, screenDarkeningLevels, screenDarkeningMinThreshold,
- screenBrighteningMinThreshold, true);
+ HysteresisLevels screenBrightnessThresholds =
+ mDisplayDeviceConfig.getScreenBrightnessHysteresis();
// Ambient Lux - Idle Screen Brightness Thresholds
- float ambientDarkeningMinThresholdIdle =
- mDisplayDeviceConfig.getAmbientLuxDarkeningMinThresholdIdle();
- float ambientBrighteningMinThresholdIdle =
- mDisplayDeviceConfig.getAmbientLuxBrighteningMinThresholdIdle();
- float[] ambientBrighteningThresholdsIdle =
- mDisplayDeviceConfig.getAmbientBrighteningPercentagesIdle();
- float[] ambientDarkeningThresholdsIdle =
- mDisplayDeviceConfig.getAmbientDarkeningPercentagesIdle();
- float[] ambientBrighteningLevelsIdle =
- mDisplayDeviceConfig.getAmbientBrighteningLevelsIdle();
- float[] ambientDarkeningLevelsIdle =
- mDisplayDeviceConfig.getAmbientDarkeningLevelsIdle();
- HysteresisLevels ambientBrightnessThresholdsIdle = mInjector.getHysteresisLevels(
- ambientBrighteningThresholdsIdle, ambientDarkeningThresholdsIdle,
- ambientBrighteningLevelsIdle, ambientDarkeningLevelsIdle,
- ambientDarkeningMinThresholdIdle, ambientBrighteningMinThresholdIdle);
+ HysteresisLevels ambientBrightnessThresholdsIdle =
+ mDisplayDeviceConfig.getAmbientBrightnessIdleHysteresis();
// Display - Idle Screen Brightness Thresholds
- float screenDarkeningMinThresholdIdle =
- mDisplayDeviceConfig.getScreenDarkeningMinThresholdIdle();
- float screenBrighteningMinThresholdIdle =
- mDisplayDeviceConfig.getScreenBrighteningMinThresholdIdle();
- float[] screenBrighteningThresholdsIdle =
- mDisplayDeviceConfig.getScreenBrighteningPercentagesIdle();
- float[] screenDarkeningThresholdsIdle =
- mDisplayDeviceConfig.getScreenDarkeningPercentagesIdle();
- float[] screenBrighteningLevelsIdle =
- mDisplayDeviceConfig.getScreenBrighteningLevelsIdle();
- float[] screenDarkeningLevelsIdle =
- mDisplayDeviceConfig.getScreenDarkeningLevelsIdle();
- HysteresisLevels screenBrightnessThresholdsIdle = mInjector.getHysteresisLevels(
- screenBrighteningThresholdsIdle, screenDarkeningThresholdsIdle,
- screenBrighteningLevelsIdle, screenDarkeningLevelsIdle,
- screenDarkeningMinThresholdIdle, screenBrighteningMinThresholdIdle);
+ HysteresisLevels screenBrightnessThresholdsIdle =
+ mDisplayDeviceConfig.getScreenBrightnessIdleHysteresis();
long brighteningLightDebounce = mDisplayDeviceConfig
.getAutoBrightnessBrighteningLightDebounce();
@@ -3208,25 +3153,6 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
AUTO_BRIGHTNESS_MODE_DEFAULT, displayWhiteBalanceController);
}
- HysteresisLevels getHysteresisLevels(float[] brighteningThresholdsPercentages,
- float[] darkeningThresholdsPercentages, float[] brighteningThresholdLevels,
- float[] darkeningThresholdLevels, float minDarkeningThreshold,
- float minBrighteningThreshold) {
- return new HysteresisLevels(brighteningThresholdsPercentages,
- darkeningThresholdsPercentages, brighteningThresholdLevels,
- darkeningThresholdLevels, minDarkeningThreshold, minBrighteningThreshold);
- }
-
- HysteresisLevels getHysteresisLevels(float[] brighteningThresholdsPercentages,
- float[] darkeningThresholdsPercentages, float[] brighteningThresholdLevels,
- float[] darkeningThresholdLevels, float minDarkeningThreshold,
- float minBrighteningThreshold, boolean potentialOldBrightnessRange) {
- return new HysteresisLevels(brighteningThresholdsPercentages,
- darkeningThresholdsPercentages, brighteningThresholdLevels,
- darkeningThresholdLevels, minDarkeningThreshold, minBrighteningThreshold,
- potentialOldBrightnessRange);
- }
-
ScreenOffBrightnessSensorController getScreenOffBrightnessSensorController(
SensorManager sensorManager,
Sensor lightSensor,
diff --git a/services/core/java/com/android/server/display/HysteresisLevels.java b/services/core/java/com/android/server/display/HysteresisLevels.java
deleted file mode 100644
index 0521b8ac4f3b..000000000000
--- a/services/core/java/com/android/server/display/HysteresisLevels.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.server.display;
-
-import android.util.Slog;
-
-import com.android.server.display.utils.DebugUtils;
-
-import java.io.PrintWriter;
-import java.util.Arrays;
-
-/**
- * A helper class for handling access to illuminance hysteresis level values.
- */
-public class HysteresisLevels {
- private static final String TAG = "HysteresisLevels";
-
- // To enable these logs, run:
- // 'adb shell setprop persist.log.tag.HysteresisLevels DEBUG && adb reboot'
- private static final boolean DEBUG = DebugUtils.isDebuggable(TAG);
-
- private final float[] mBrighteningThresholdsPercentages;
- private final float[] mDarkeningThresholdsPercentages;
- private final float[] mBrighteningThresholdLevels;
- private final float[] mDarkeningThresholdLevels;
- private final float mMinDarkening;
- private final float mMinBrightening;
-
- /**
- * Creates a {@code HysteresisLevels} object with the given equal-length
- * float arrays.
- * @param brighteningThresholdsPercentages 0-100 of thresholds
- * @param darkeningThresholdsPercentages 0-100 of thresholds
- * @param brighteningThresholdLevels float array of brightness values in the relevant units
- * @param minBrighteningThreshold the minimum value for which the brightening value needs to
- * return.
- * @param minDarkeningThreshold the minimum value for which the darkening value needs to return.
- * @param potentialOldBrightnessRange whether or not the values used could be from the old
- * screen brightness range ie, between 1-255.
- */
- HysteresisLevels(float[] brighteningThresholdsPercentages,
- float[] darkeningThresholdsPercentages,
- float[] brighteningThresholdLevels, float[] darkeningThresholdLevels,
- float minDarkeningThreshold, float minBrighteningThreshold,
- boolean potentialOldBrightnessRange) {
- if (brighteningThresholdsPercentages.length != brighteningThresholdLevels.length
- || darkeningThresholdsPercentages.length != darkeningThresholdLevels.length) {
- throw new IllegalArgumentException("Mismatch between hysteresis array lengths.");
- }
- mBrighteningThresholdsPercentages =
- setArrayFormat(brighteningThresholdsPercentages, 100.0f);
- mDarkeningThresholdsPercentages =
- setArrayFormat(darkeningThresholdsPercentages, 100.0f);
- mBrighteningThresholdLevels = setArrayFormat(brighteningThresholdLevels, 1.0f);
- mDarkeningThresholdLevels = setArrayFormat(darkeningThresholdLevels, 1.0f);
- mMinDarkening = minDarkeningThreshold;
- mMinBrightening = minBrighteningThreshold;
- }
-
- HysteresisLevels(float[] brighteningThresholdsPercentages,
- float[] darkeningThresholdsPercentages,
- float[] brighteningThresholdLevels, float[] darkeningThresholdLevels,
- float minDarkeningThreshold, float minBrighteningThreshold) {
- this(brighteningThresholdsPercentages, darkeningThresholdsPercentages,
- brighteningThresholdLevels, darkeningThresholdLevels, minDarkeningThreshold,
- minBrighteningThreshold, false);
- }
-
- /**
- * Return the brightening hysteresis threshold for the given value level.
- */
- public float getBrighteningThreshold(float value) {
- final float brightConstant = getReferenceLevel(value,
- mBrighteningThresholdLevels, mBrighteningThresholdsPercentages);
-
- float brightThreshold = value * (1.0f + brightConstant);
- if (DEBUG) {
- Slog.d(TAG, "bright hysteresis constant=" + brightConstant + ", threshold="
- + brightThreshold + ", value=" + value);
- }
-
- brightThreshold = Math.max(brightThreshold, value + mMinBrightening);
- return brightThreshold;
- }
-
- /**
- * Return the darkening hysteresis threshold for the given value level.
- */
- public float getDarkeningThreshold(float value) {
- final float darkConstant = getReferenceLevel(value,
- mDarkeningThresholdLevels, mDarkeningThresholdsPercentages);
- float darkThreshold = value * (1.0f - darkConstant);
- if (DEBUG) {
- Slog.d(TAG, "dark hysteresis constant=: " + darkConstant + ", threshold="
- + darkThreshold + ", value=" + value);
- }
- darkThreshold = Math.min(darkThreshold, value - mMinDarkening);
- return Math.max(darkThreshold, 0.0f);
- }
-
- /**
- * Return the hysteresis constant for the closest threshold value from the given array.
- */
- private float getReferenceLevel(float value, float[] thresholdLevels,
- float[] thresholdPercentages) {
- if (thresholdLevels == null || thresholdLevels.length == 0 || value < thresholdLevels[0]) {
- return 0.0f;
- }
- int index = 0;
- while (index < thresholdLevels.length - 1 && value >= thresholdLevels[index + 1]) {
- index++;
- }
- return thresholdPercentages[index];
- }
-
- /**
- * Return a float array where each i-th element equals {@code configArray[i]/divideFactor}.
- */
- private float[] setArrayFormat(float[] configArray, float divideFactor) {
- float[] levelArray = new float[configArray.length];
- for (int index = 0; levelArray.length > index; ++index) {
- levelArray[index] = configArray[index] / divideFactor;
- }
- return levelArray;
- }
-
- void dump(PrintWriter pw) {
- pw.println("HysteresisLevels");
- pw.println(" mBrighteningThresholdLevels=" + Arrays.toString(mBrighteningThresholdLevels));
- pw.println(" mBrighteningThresholdsPercentages="
- + Arrays.toString(mBrighteningThresholdsPercentages));
- pw.println(" mMinBrightening=" + mMinBrightening);
- pw.println(" mDarkeningThresholdLevels=" + Arrays.toString(mDarkeningThresholdLevels));
- pw.println(" mDarkeningThresholdsPercentages="
- + Arrays.toString(mDarkeningThresholdsPercentages));
- pw.println(" mMinDarkening=" + mMinDarkening);
- }
-}
diff --git a/services/core/java/com/android/server/display/config/HysteresisLevels.java b/services/core/java/com/android/server/display/config/HysteresisLevels.java
new file mode 100644
index 000000000000..e659d88c9752
--- /dev/null
+++ b/services/core/java/com/android/server/display/config/HysteresisLevels.java
@@ -0,0 +1,463 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.display.config;
+
+import android.annotation.ArrayRes;
+import android.annotation.Nullable;
+import android.content.res.Resources;
+import android.util.Pair;
+import android.util.Slog;
+
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.server.display.utils.DebugUtils;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * A helper class for handling access to illuminance hysteresis level values.
+ */
+public class HysteresisLevels {
+ private static final String TAG = "HysteresisLevels";
+
+ private static final float[] DEFAULT_AMBIENT_BRIGHTENING_THRESHOLDS = new float[]{100f};
+ private static final float[] DEFAULT_AMBIENT_DARKENING_THRESHOLDS = new float[]{200f};
+ private static final float[] DEFAULT_AMBIENT_THRESHOLD_LEVELS = new float[]{0f};
+ private static final float[] DEFAULT_SCREEN_THRESHOLD_LEVELS = new float[]{0f};
+ private static final float[] DEFAULT_SCREEN_BRIGHTENING_THRESHOLDS = new float[]{100f};
+ private static final float[] DEFAULT_SCREEN_DARKENING_THRESHOLDS = new float[]{200f};
+
+ // To enable these logs, run:
+ // 'adb shell setprop persist.log.tag.HysteresisLevels DEBUG && adb reboot'
+ private static final boolean DEBUG = DebugUtils.isDebuggable(TAG);
+
+ /**
+ * The array that describes the brightness threshold percentage change
+ * at each brightness level described in mBrighteningThresholdLevels.
+ */
+ private final float[] mBrighteningThresholdsPercentages;
+
+ /**
+ * The array that describes the brightness threshold percentage change
+ * at each brightness level described in mDarkeningThresholdLevels.
+ */
+ private final float[] mDarkeningThresholdsPercentages;
+
+ /**
+ * The array that describes the range of brightness that each threshold percentage applies to
+ *
+ * The (zero-based) index is calculated as follows
+ * value = current brightness value
+ * level = mBrighteningThresholdLevels
+ *
+ * condition return
+ * value < mBrighteningThresholdLevels[0] = 0.0f
+ * level[n] <= value < level[n+1] = mBrighteningThresholdsPercentages[n]
+ * level[MAX] <= value = mBrighteningThresholdsPercentages[MAX]
+ */
+ private final float[] mBrighteningThresholdLevels;
+
+ /**
+ * The array that describes the range of brightness that each threshold percentage applies to
+ *
+ * The (zero-based) index is calculated as follows
+ * value = current brightness value
+ * level = mDarkeningThresholdLevels
+ *
+ * condition return
+ * value < level[0] = 0.0f
+ * level[n] <= value < level[n+1] = mDarkeningThresholdsPercentages[n]
+ * level[MAX] <= value = mDarkeningThresholdsPercentages[MAX]
+ */
+ private final float[] mDarkeningThresholdLevels;
+
+ /**
+ * The minimum value decrease for darkening event
+ */
+ private final float mMinDarkening;
+
+ /**
+ * The minimum value increase for brightening event.
+ */
+ private final float mMinBrightening;
+
+ /**
+ * Creates a {@code HysteresisLevels} object with the given equal-length
+ * float arrays.
+ *
+ * @param brighteningThresholdsPercentages 0-100 of thresholds
+ * @param darkeningThresholdsPercentages 0-100 of thresholds
+ * @param brighteningThresholdLevels float array of brightness values in the relevant
+ * units
+ * @param minBrighteningThreshold the minimum value for which the brightening value
+ * needs to
+ * return.
+ * @param minDarkeningThreshold the minimum value for which the darkening value needs
+ * to return.
+ */
+ @VisibleForTesting
+ public HysteresisLevels(float[] brighteningThresholdsPercentages,
+ float[] darkeningThresholdsPercentages,
+ float[] brighteningThresholdLevels, float[] darkeningThresholdLevels,
+ float minDarkeningThreshold, float minBrighteningThreshold) {
+ if (brighteningThresholdsPercentages.length != brighteningThresholdLevels.length
+ || darkeningThresholdsPercentages.length != darkeningThresholdLevels.length) {
+ throw new IllegalArgumentException("Mismatch between hysteresis array lengths.");
+ }
+ mBrighteningThresholdsPercentages =
+ setArrayFormat(brighteningThresholdsPercentages, 100.0f);
+ mDarkeningThresholdsPercentages =
+ setArrayFormat(darkeningThresholdsPercentages, 100.0f);
+ mBrighteningThresholdLevels = setArrayFormat(brighteningThresholdLevels, 1.0f);
+ mDarkeningThresholdLevels = setArrayFormat(darkeningThresholdLevels, 1.0f);
+ mMinDarkening = minDarkeningThreshold;
+ mMinBrightening = minBrighteningThreshold;
+ }
+
+ /**
+ * Return the brightening hysteresis threshold for the given value level.
+ */
+ public float getBrighteningThreshold(float value) {
+ final float brightConstant = getReferenceLevel(value,
+ mBrighteningThresholdLevels, mBrighteningThresholdsPercentages);
+
+ float brightThreshold = value * (1.0f + brightConstant);
+ if (DEBUG) {
+ Slog.d(TAG, "bright hysteresis constant=" + brightConstant + ", threshold="
+ + brightThreshold + ", value=" + value);
+ }
+
+ brightThreshold = Math.max(brightThreshold, value + mMinBrightening);
+ return brightThreshold;
+ }
+
+ /**
+ * Return the darkening hysteresis threshold for the given value level.
+ */
+ public float getDarkeningThreshold(float value) {
+ final float darkConstant = getReferenceLevel(value,
+ mDarkeningThresholdLevels, mDarkeningThresholdsPercentages);
+ float darkThreshold = value * (1.0f - darkConstant);
+ if (DEBUG) {
+ Slog.d(TAG, "dark hysteresis constant=: " + darkConstant + ", threshold="
+ + darkThreshold + ", value=" + value);
+ }
+ darkThreshold = Math.min(darkThreshold, value - mMinDarkening);
+ return Math.max(darkThreshold, 0.0f);
+ }
+
+ @VisibleForTesting
+ public float[] getBrighteningThresholdsPercentages() {
+ return mBrighteningThresholdsPercentages;
+ }
+
+ @VisibleForTesting
+ public float[] getDarkeningThresholdsPercentages() {
+ return mDarkeningThresholdsPercentages;
+ }
+
+ @VisibleForTesting
+ public float[] getBrighteningThresholdLevels() {
+ return mBrighteningThresholdLevels;
+ }
+
+ @VisibleForTesting
+ public float[] getDarkeningThresholdLevels() {
+ return mDarkeningThresholdLevels;
+ }
+
+ @VisibleForTesting
+ public float getMinDarkening() {
+ return mMinDarkening;
+ }
+
+ @VisibleForTesting
+ public float getMinBrightening() {
+ return mMinBrightening;
+ }
+
+ /**
+ * Return the hysteresis constant for the closest threshold value from the given array.
+ */
+ private float getReferenceLevel(float value, float[] thresholdLevels,
+ float[] thresholdPercentages) {
+ if (thresholdLevels == null || thresholdLevels.length == 0 || value < thresholdLevels[0]) {
+ return 0.0f;
+ }
+ int index = 0;
+ while (index < thresholdLevels.length - 1 && value >= thresholdLevels[index + 1]) {
+ index++;
+ }
+ return thresholdPercentages[index];
+ }
+
+ /**
+ * Return a float array where each i-th element equals {@code configArray[i]/divideFactor}.
+ */
+ private float[] setArrayFormat(float[] configArray, float divideFactor) {
+ float[] levelArray = new float[configArray.length];
+ for (int index = 0; levelArray.length > index; ++index) {
+ levelArray[index] = configArray[index] / divideFactor;
+ }
+ return levelArray;
+ }
+
+ @Override
+ public String toString() {
+ return "HysteresisLevels {"
+ + "\n"
+ + " mBrighteningThresholdLevels=" + Arrays.toString(mBrighteningThresholdLevels)
+ + ",\n"
+ + " mBrighteningThresholdsPercentages="
+ + Arrays.toString(mBrighteningThresholdsPercentages)
+ + ",\n"
+ + " mMinBrightening=" + mMinBrightening
+ + ",\n"
+ + " mDarkeningThresholdLevels=" + Arrays.toString(mDarkeningThresholdLevels)
+ + ",\n"
+ + " mDarkeningThresholdsPercentages="
+ + Arrays.toString(mDarkeningThresholdsPercentages)
+ + ",\n"
+ + " mMinDarkening=" + mMinDarkening
+ + "\n"
+ + "}";
+ }
+
+ /**
+ * Creates hysteresis levels for Active Ambient Lux
+ */
+ public static HysteresisLevels loadAmbientBrightnessConfig(
+ @Nullable DisplayConfiguration config, @Nullable Resources resources) {
+ return createHysteresisLevels(
+ config == null ? null : config.getAmbientBrightnessChangeThresholds(),
+ com.android.internal.R.array.config_ambientThresholdLevels,
+ com.android.internal.R.array.config_ambientBrighteningThresholds,
+ com.android.internal.R.array.config_ambientDarkeningThresholds,
+ DEFAULT_AMBIENT_THRESHOLD_LEVELS,
+ DEFAULT_AMBIENT_BRIGHTENING_THRESHOLDS,
+ DEFAULT_AMBIENT_DARKENING_THRESHOLDS,
+ resources, /* potentialOldBrightnessScale= */ false);
+ }
+
+ /**
+ * Creates hysteresis levels for Active Screen Brightness
+ */
+ public static HysteresisLevels loadDisplayBrightnessConfig(
+ @Nullable DisplayConfiguration config, @Nullable Resources resources) {
+ return createHysteresisLevels(
+ config == null ? null : config.getDisplayBrightnessChangeThresholds(),
+ com.android.internal.R.array.config_screenThresholdLevels,
+ com.android.internal.R.array.config_screenBrighteningThresholds,
+ com.android.internal.R.array.config_screenDarkeningThresholds,
+ DEFAULT_SCREEN_THRESHOLD_LEVELS,
+ DEFAULT_SCREEN_BRIGHTENING_THRESHOLDS,
+ DEFAULT_SCREEN_DARKENING_THRESHOLDS,
+ resources, /* potentialOldBrightnessScale= */ true);
+ }
+
+ /**
+ * Creates hysteresis levels for Idle Ambient Lux
+ */
+ public static HysteresisLevels loadAmbientBrightnessIdleConfig(
+ @Nullable DisplayConfiguration config, @Nullable Resources resources) {
+ return createHysteresisLevels(
+ config == null ? null : config.getAmbientBrightnessChangeThresholdsIdle(),
+ com.android.internal.R.array.config_ambientThresholdLevels,
+ com.android.internal.R.array.config_ambientBrighteningThresholds,
+ com.android.internal.R.array.config_ambientDarkeningThresholds,
+ DEFAULT_AMBIENT_THRESHOLD_LEVELS,
+ DEFAULT_AMBIENT_BRIGHTENING_THRESHOLDS,
+ DEFAULT_AMBIENT_DARKENING_THRESHOLDS,
+ resources, /* potentialOldBrightnessScale= */ false);
+ }
+
+ /**
+ * Creates hysteresis levels for Idle Screen Brightness
+ */
+ public static HysteresisLevels loadDisplayBrightnessIdleConfig(
+ @Nullable DisplayConfiguration config, @Nullable Resources resources) {
+ return createHysteresisLevels(
+ config == null ? null : config.getDisplayBrightnessChangeThresholdsIdle(),
+ com.android.internal.R.array.config_screenThresholdLevels,
+ com.android.internal.R.array.config_screenBrighteningThresholds,
+ com.android.internal.R.array.config_screenDarkeningThresholds,
+ DEFAULT_SCREEN_THRESHOLD_LEVELS,
+ DEFAULT_SCREEN_BRIGHTENING_THRESHOLDS,
+ DEFAULT_SCREEN_DARKENING_THRESHOLDS,
+ resources, /* potentialOldBrightnessScale= */ true);
+ }
+
+
+ private static HysteresisLevels createHysteresisLevels(
+ @Nullable Thresholds thresholds,
+ @ArrayRes int configLevels,
+ @ArrayRes int configBrighteningThresholds,
+ @ArrayRes int configDarkeningThresholds,
+ float[] defaultLevels,
+ float[] defaultBrighteningThresholds,
+ float[] defaultDarkeningThresholds,
+ @Nullable Resources resources,
+ boolean potentialOldBrightnessScale
+ ) {
+ BrightnessThresholds brighteningThresholds =
+ thresholds == null ? null : thresholds.getBrighteningThresholds();
+ BrightnessThresholds darkeningThresholds =
+ thresholds == null ? null : thresholds.getDarkeningThresholds();
+
+ Pair<float[], float[]> brighteningPair = getBrightnessLevelAndPercentage(
+ brighteningThresholds,
+ configLevels, configBrighteningThresholds,
+ defaultLevels, defaultBrighteningThresholds,
+ potentialOldBrightnessScale, resources);
+
+ Pair<float[], float[]> darkeningPair = getBrightnessLevelAndPercentage(
+ darkeningThresholds,
+ configLevels, configDarkeningThresholds,
+ defaultLevels, defaultDarkeningThresholds,
+ potentialOldBrightnessScale, resources);
+
+ float brighteningMinThreshold =
+ brighteningThresholds != null && brighteningThresholds.getMinimum() != null
+ ? brighteningThresholds.getMinimum().floatValue() : 0f;
+ float darkeningMinThreshold =
+ darkeningThresholds != null && darkeningThresholds.getMinimum() != null
+ ? darkeningThresholds.getMinimum().floatValue() : 0f;
+
+ return new HysteresisLevels(
+ brighteningPair.second,
+ darkeningPair.second,
+ brighteningPair.first,
+ darkeningPair.first,
+ darkeningMinThreshold,
+ brighteningMinThreshold
+ );
+ }
+
+ // Returns two float arrays, one of the brightness levels and one of the corresponding threshold
+ // percentages for brightness levels at or above the lux value.
+ // Historically, config.xml would have an array for brightness levels that was 1 shorter than
+ // the levels array. Now we prepend a 0 to this array so they can be treated the same in the
+ // rest of the framework. Values were also defined in different units (permille vs percent).
+ private static Pair<float[], float[]> getBrightnessLevelAndPercentage(
+ @Nullable BrightnessThresholds thresholds,
+ int configFallbackThreshold, int configFallbackPermille,
+ float[] defaultLevels, float[] defaultPercentage, boolean potentialOldBrightnessScale,
+ @Nullable Resources resources) {
+ if (thresholds != null
+ && thresholds.getBrightnessThresholdPoints() != null
+ && !thresholds.getBrightnessThresholdPoints().getBrightnessThresholdPoint()
+ .isEmpty()) {
+
+ // The level and percentages arrays are equal length in the ddc (new system)
+ List<ThresholdPoint> points =
+ thresholds.getBrightnessThresholdPoints().getBrightnessThresholdPoint();
+ final int size = points.size();
+
+ float[] thresholdLevels = new float[size];
+ float[] thresholdPercentages = new float[size];
+
+ int i = 0;
+ for (ThresholdPoint point : points) {
+ thresholdLevels[i] = point.getThreshold().floatValue();
+ thresholdPercentages[i] = point.getPercentage().floatValue();
+ i++;
+ }
+ return new Pair<>(thresholdLevels, thresholdPercentages);
+ } else if (resources != null) {
+ // The level and percentages arrays are unequal length in config.xml (old system)
+ // We prefix the array with a 0 value to ensure they can be handled consistently
+ // with the new system.
+
+ // Load levels array
+ int[] configThresholdArray = resources.getIntArray(configFallbackThreshold);
+ int configThresholdsSize;
+ // null check is not needed here, however it test we are mocking resources that might
+ // return null
+ if (configThresholdArray == null || configThresholdArray.length == 0) {
+ configThresholdsSize = 1;
+ } else {
+ configThresholdsSize = configThresholdArray.length + 1;
+ }
+
+ // Load percentage array
+ int[] configPermille = resources.getIntArray(configFallbackPermille);
+
+ // Ensure lengths match up
+ // null check is not needed here, however it test we are mocking resources that might
+ // return null
+ boolean emptyArray = configPermille == null || configPermille.length == 0;
+ if (emptyArray && configThresholdsSize == 1) {
+ return new Pair<>(defaultLevels, defaultPercentage);
+ }
+ if (emptyArray || configPermille.length != configThresholdsSize) {
+ throw new IllegalArgumentException(
+ "Brightness threshold arrays do not align in length");
+ }
+
+ // Calculate levels array
+ float[] configThresholdWithZeroPrefixed = new float[configThresholdsSize];
+ // Start at 1, so that 0 index value is 0.0f (default)
+ for (int i = 1; i < configThresholdsSize; i++) {
+ configThresholdWithZeroPrefixed[i] = (float) configThresholdArray[i - 1];
+ }
+ if (potentialOldBrightnessScale) {
+ configThresholdWithZeroPrefixed =
+ constraintInRangeIfNeeded(configThresholdWithZeroPrefixed);
+ }
+
+ // Calculate percentages array
+ float[] configPercentage = new float[configThresholdsSize];
+ for (int i = 0; i < configPermille.length; i++) {
+ configPercentage[i] = configPermille[i] / 10.0f;
+ }
+ return new Pair<>(configThresholdWithZeroPrefixed, configPercentage);
+ } else {
+ return new Pair<>(defaultLevels, defaultPercentage);
+ }
+ }
+
+ /**
+ * This check is due to historical reasons, where screen thresholdLevels used to be
+ * integer values in the range of [0-255], but then was changed to be float values from [0,1].
+ * To accommodate both the possibilities, we first check if all the thresholdLevels are in
+ * [0,1], and if not, we divide all the levels with 255 to bring them down to the same scale.
+ */
+ private static float[] constraintInRangeIfNeeded(float[] thresholdLevels) {
+ if (isAllInRange(thresholdLevels, /* minValueInclusive= */ 0.0f,
+ /* maxValueInclusive= */ 1.0f)) {
+ return thresholdLevels;
+ }
+
+ Slog.w(TAG, "Detected screen thresholdLevels on a deprecated brightness scale");
+ float[] thresholdLevelsScaled = new float[thresholdLevels.length];
+ for (int index = 0; thresholdLevels.length > index; ++index) {
+ thresholdLevelsScaled[index] = thresholdLevels[index] / 255.0f;
+ }
+ return thresholdLevelsScaled;
+ }
+
+ private static boolean isAllInRange(float[] configArray, float minValueInclusive,
+ float maxValueInclusive) {
+ for (float v : configArray) {
+ if (v < minValueInclusive || v > maxValueInclusive) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+}
diff --git a/services/tests/displayservicetests/src/com/android/server/display/AutomaticBrightnessControllerTest.java b/services/tests/displayservicetests/src/com/android/server/display/AutomaticBrightnessControllerTest.java
index 54de64e2f3a8..64253e10bd21 100644
--- a/services/tests/displayservicetests/src/com/android/server/display/AutomaticBrightnessControllerTest.java
+++ b/services/tests/displayservicetests/src/com/android/server/display/AutomaticBrightnessControllerTest.java
@@ -53,6 +53,7 @@ import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import com.android.server.display.brightness.clamper.BrightnessClamperController;
+import com.android.server.display.config.HysteresisLevels;
import com.android.server.testutils.OffsettableClock;
import org.junit.After;
diff --git a/services/tests/displayservicetests/src/com/android/server/display/DisplayDeviceConfigTest.java b/services/tests/displayservicetests/src/com/android/server/display/DisplayDeviceConfigTest.java
index 494a6677e633..b80d44fb8fd8 100644
--- a/services/tests/displayservicetests/src/com/android/server/display/DisplayDeviceConfigTest.java
+++ b/services/tests/displayservicetests/src/com/android/server/display/DisplayDeviceConfigTest.java
@@ -55,6 +55,7 @@ import androidx.test.filters.SmallTest;
import com.android.internal.R;
import com.android.server.display.config.HdrBrightnessData;
+import com.android.server.display.config.HysteresisLevels;
import com.android.server.display.config.IdleScreenRefreshRateTimeoutLuxThresholdPoint;
import com.android.server.display.config.ThermalStatus;
import com.android.server.display.feature.DisplayManagerFlags;
@@ -169,53 +170,57 @@ public final class DisplayDeviceConfigTest {
assertArrayEquals(mDisplayDeviceConfig.getBacklight(), BRIGHTNESS, ZERO_DELTA);
// Test thresholds
- assertEquals(10, mDisplayDeviceConfig.getAmbientLuxBrighteningMinThreshold(),
- ZERO_DELTA);
- assertEquals(20, mDisplayDeviceConfig.getAmbientLuxBrighteningMinThresholdIdle(),
- ZERO_DELTA);
- assertEquals(30, mDisplayDeviceConfig.getAmbientLuxDarkeningMinThreshold(), ZERO_DELTA);
- assertEquals(40, mDisplayDeviceConfig.getAmbientLuxDarkeningMinThresholdIdle(), ZERO_DELTA);
-
- assertEquals(0.1f, mDisplayDeviceConfig.getScreenBrighteningMinThreshold(), ZERO_DELTA);
- assertEquals(0.2f, mDisplayDeviceConfig.getScreenBrighteningMinThresholdIdle(), ZERO_DELTA);
- assertEquals(0.3f, mDisplayDeviceConfig.getScreenDarkeningMinThreshold(), ZERO_DELTA);
- assertEquals(0.4f, mDisplayDeviceConfig.getScreenDarkeningMinThresholdIdle(), ZERO_DELTA);
+ HysteresisLevels ambientHysteresis = mDisplayDeviceConfig.getAmbientBrightnessHysteresis();
+ HysteresisLevels ambientIdleHysteresis =
+ mDisplayDeviceConfig.getAmbientBrightnessIdleHysteresis();
+ HysteresisLevels screenHysteresis = mDisplayDeviceConfig.getScreenBrightnessHysteresis();
+ HysteresisLevels screenIdleHysteresis =
+ mDisplayDeviceConfig.getScreenBrightnessIdleHysteresis();
+ assertEquals(10, ambientHysteresis.getMinBrightening(), ZERO_DELTA);
+ assertEquals(20, ambientIdleHysteresis.getMinBrightening(), ZERO_DELTA);
+ assertEquals(30, ambientHysteresis.getMinDarkening(), ZERO_DELTA);
+ assertEquals(40, ambientIdleHysteresis.getMinDarkening(), ZERO_DELTA);
+
+ assertEquals(0.1f, screenHysteresis.getMinBrightening(), ZERO_DELTA);
+ assertEquals(0.2f, screenIdleHysteresis.getMinBrightening(), ZERO_DELTA);
+ assertEquals(0.3f, screenHysteresis.getMinDarkening(), ZERO_DELTA);
+ assertEquals(0.4f, screenIdleHysteresis.getMinDarkening(), ZERO_DELTA);
assertArrayEquals(new float[]{0, 0.10f, 0.20f},
- mDisplayDeviceConfig.getScreenBrighteningLevels(), ZERO_DELTA);
- assertArrayEquals(new float[]{9, 10, 11},
- mDisplayDeviceConfig.getScreenBrighteningPercentages(), ZERO_DELTA);
+ screenHysteresis.getBrighteningThresholdLevels(), ZERO_DELTA);
+ assertArrayEquals(new float[]{0.09f, 0.10f, 0.11f},
+ screenHysteresis.getBrighteningThresholdsPercentages(), ZERO_DELTA);
assertArrayEquals(new float[]{0, 0.11f, 0.21f},
- mDisplayDeviceConfig.getScreenDarkeningLevels(), ZERO_DELTA);
- assertArrayEquals(new float[]{11, 12, 13},
- mDisplayDeviceConfig.getScreenDarkeningPercentages(), ZERO_DELTA);
+ screenHysteresis.getDarkeningThresholdLevels(), ZERO_DELTA);
+ assertArrayEquals(new float[]{0.11f, 0.12f, 0.13f},
+ screenHysteresis.getDarkeningThresholdsPercentages(), ZERO_DELTA);
assertArrayEquals(new float[]{0, 100, 200},
- mDisplayDeviceConfig.getAmbientBrighteningLevels(), ZERO_DELTA);
- assertArrayEquals(new float[]{13, 14, 15},
- mDisplayDeviceConfig.getAmbientBrighteningPercentages(), ZERO_DELTA);
+ ambientHysteresis.getBrighteningThresholdLevels(), ZERO_DELTA);
+ assertArrayEquals(new float[]{0.13f, 0.14f, 0.15f},
+ ambientHysteresis.getBrighteningThresholdsPercentages(), ZERO_DELTA);
assertArrayEquals(new float[]{0, 300, 400},
- mDisplayDeviceConfig.getAmbientDarkeningLevels(), ZERO_DELTA);
- assertArrayEquals(new float[]{15, 16, 17},
- mDisplayDeviceConfig.getAmbientDarkeningPercentages(), ZERO_DELTA);
+ ambientHysteresis.getDarkeningThresholdLevels(), ZERO_DELTA);
+ assertArrayEquals(new float[]{0.15f, 0.16f, 0.17f},
+ ambientHysteresis.getDarkeningThresholdsPercentages(), ZERO_DELTA);
assertArrayEquals(new float[]{0, 0.12f, 0.22f},
- mDisplayDeviceConfig.getScreenBrighteningLevelsIdle(), ZERO_DELTA);
- assertArrayEquals(new float[]{17, 18, 19},
- mDisplayDeviceConfig.getScreenBrighteningPercentagesIdle(), ZERO_DELTA);
+ screenIdleHysteresis.getBrighteningThresholdLevels(), ZERO_DELTA);
+ assertArrayEquals(new float[]{0.17f, 0.18f, 0.19f},
+ screenIdleHysteresis.getBrighteningThresholdsPercentages(), ZERO_DELTA);
assertArrayEquals(new float[]{0, 0.13f, 0.23f},
- mDisplayDeviceConfig.getScreenDarkeningLevelsIdle(), ZERO_DELTA);
- assertArrayEquals(new float[]{19, 20, 21},
- mDisplayDeviceConfig.getScreenDarkeningPercentagesIdle(), ZERO_DELTA);
+ screenIdleHysteresis.getDarkeningThresholdLevels(), ZERO_DELTA);
+ assertArrayEquals(new float[]{0.19f, 0.20f, 0.21f},
+ screenIdleHysteresis.getDarkeningThresholdsPercentages(), ZERO_DELTA);
assertArrayEquals(new float[]{0, 500, 600},
- mDisplayDeviceConfig.getAmbientBrighteningLevelsIdle(), ZERO_DELTA);
- assertArrayEquals(new float[]{21, 22, 23},
- mDisplayDeviceConfig.getAmbientBrighteningPercentagesIdle(), ZERO_DELTA);
+ ambientIdleHysteresis.getBrighteningThresholdLevels(), ZERO_DELTA);
+ assertArrayEquals(new float[]{0.21f, 0.22f, 0.23f},
+ ambientIdleHysteresis.getBrighteningThresholdsPercentages(), ZERO_DELTA);
assertArrayEquals(new float[]{0, 700, 800},
- mDisplayDeviceConfig.getAmbientDarkeningLevelsIdle(), ZERO_DELTA);
- assertArrayEquals(new float[]{23, 24, 25},
- mDisplayDeviceConfig.getAmbientDarkeningPercentagesIdle(), ZERO_DELTA);
+ ambientIdleHysteresis.getDarkeningThresholdLevels(), ZERO_DELTA);
+ assertArrayEquals(new float[]{0.23f, 0.24f, 0.25f},
+ ambientIdleHysteresis.getDarkeningThresholdsPercentages(), ZERO_DELTA);
assertEquals(75, mDisplayDeviceConfig.getDefaultLowBlockingZoneRefreshRate());
assertEquals(90, mDisplayDeviceConfig.getDefaultHighBlockingZoneRefreshRate());
@@ -686,55 +691,60 @@ public final class DisplayDeviceConfigTest {
new float[]{brightnessIntToFloat(50), brightnessIntToFloat(100),
brightnessIntToFloat(150)}, SMALL_DELTA);
+ HysteresisLevels ambientHysteresis = mDisplayDeviceConfig.getAmbientBrightnessHysteresis();
+ HysteresisLevels ambientIdleHysteresis =
+ mDisplayDeviceConfig.getAmbientBrightnessIdleHysteresis();
+ HysteresisLevels screenHysteresis = mDisplayDeviceConfig.getScreenBrightnessHysteresis();
+ HysteresisLevels screenIdleHysteresis =
+ mDisplayDeviceConfig.getScreenBrightnessIdleHysteresis();
// Test thresholds
- assertEquals(0, mDisplayDeviceConfig.getAmbientLuxBrighteningMinThreshold(), ZERO_DELTA);
- assertEquals(0, mDisplayDeviceConfig.getAmbientLuxBrighteningMinThresholdIdle(),
- ZERO_DELTA);
- assertEquals(0, mDisplayDeviceConfig.getAmbientLuxDarkeningMinThreshold(), ZERO_DELTA);
- assertEquals(0, mDisplayDeviceConfig.getAmbientLuxDarkeningMinThresholdIdle(), ZERO_DELTA);
+ assertEquals(0, ambientHysteresis.getMinBrightening(), ZERO_DELTA);
+ assertEquals(0, ambientIdleHysteresis.getMinBrightening(), ZERO_DELTA);
+ assertEquals(0, ambientHysteresis.getMinDarkening(), ZERO_DELTA);
+ assertEquals(0, ambientIdleHysteresis.getMinDarkening(), ZERO_DELTA);
- assertEquals(0, mDisplayDeviceConfig.getScreenBrighteningMinThreshold(), ZERO_DELTA);
- assertEquals(0, mDisplayDeviceConfig.getScreenBrighteningMinThresholdIdle(), ZERO_DELTA);
- assertEquals(0, mDisplayDeviceConfig.getScreenDarkeningMinThreshold(), ZERO_DELTA);
- assertEquals(0, mDisplayDeviceConfig.getScreenDarkeningMinThresholdIdle(), ZERO_DELTA);
+ assertEquals(0, screenHysteresis.getMinBrightening(), ZERO_DELTA);
+ assertEquals(0, screenIdleHysteresis.getMinBrightening(), ZERO_DELTA);
+ assertEquals(0, screenHysteresis.getMinDarkening(), ZERO_DELTA);
+ assertEquals(0, screenIdleHysteresis.getMinDarkening(), ZERO_DELTA);
// screen levels will be considered "old screen brightness scale"
// and therefore will divide by 255
assertArrayEquals(new float[]{0, 42 / 255f, 43 / 255f},
- mDisplayDeviceConfig.getScreenBrighteningLevels(), SMALL_DELTA);
- assertArrayEquals(new float[]{35, 36, 37},
- mDisplayDeviceConfig.getScreenBrighteningPercentages(), ZERO_DELTA);
+ screenHysteresis.getBrighteningThresholdLevels(), SMALL_DELTA);
+ assertArrayEquals(new float[]{0.35f, 0.36f, 0.37f},
+ screenHysteresis.getBrighteningThresholdsPercentages(), ZERO_DELTA);
assertArrayEquals(new float[]{0, 42 / 255f, 43 / 255f},
- mDisplayDeviceConfig.getScreenDarkeningLevels(), SMALL_DELTA);
- assertArrayEquals(new float[]{37, 38, 39},
- mDisplayDeviceConfig.getScreenDarkeningPercentages(), ZERO_DELTA);
+ screenHysteresis.getDarkeningThresholdLevels(), SMALL_DELTA);
+ assertArrayEquals(new float[]{0.37f, 0.38f, 0.39f},
+ screenHysteresis.getDarkeningThresholdsPercentages(), ZERO_DELTA);
assertArrayEquals(new float[]{0, 30, 31},
- mDisplayDeviceConfig.getAmbientBrighteningLevels(), ZERO_DELTA);
- assertArrayEquals(new float[]{27, 28, 29},
- mDisplayDeviceConfig.getAmbientBrighteningPercentages(), ZERO_DELTA);
+ ambientHysteresis.getBrighteningThresholdLevels(), ZERO_DELTA);
+ assertArrayEquals(new float[]{0.27f, 0.28f, 0.29f},
+ ambientHysteresis.getBrighteningThresholdsPercentages(), ZERO_DELTA);
assertArrayEquals(new float[]{0, 30, 31},
- mDisplayDeviceConfig.getAmbientDarkeningLevels(), ZERO_DELTA);
- assertArrayEquals(new float[]{29, 30, 31},
- mDisplayDeviceConfig.getAmbientDarkeningPercentages(), ZERO_DELTA);
+ ambientHysteresis.getDarkeningThresholdLevels(), ZERO_DELTA);
+ assertArrayEquals(new float[]{0.29f, 0.30f, 0.31f},
+ ambientHysteresis.getDarkeningThresholdsPercentages(), ZERO_DELTA);
assertArrayEquals(new float[]{0, 42 / 255f, 43 / 255f},
- mDisplayDeviceConfig.getScreenBrighteningLevelsIdle(), SMALL_DELTA);
- assertArrayEquals(new float[]{35, 36, 37},
- mDisplayDeviceConfig.getScreenBrighteningPercentagesIdle(), ZERO_DELTA);
+ screenIdleHysteresis.getBrighteningThresholdLevels(), ZERO_DELTA);
+ assertArrayEquals(new float[]{0.35f, 0.36f, 0.37f},
+ screenIdleHysteresis.getBrighteningThresholdsPercentages(), ZERO_DELTA);
assertArrayEquals(new float[]{0, 42 / 255f, 43 / 255f},
- mDisplayDeviceConfig.getScreenDarkeningLevelsIdle(), SMALL_DELTA);
- assertArrayEquals(new float[]{37, 38, 39},
- mDisplayDeviceConfig.getScreenDarkeningPercentagesIdle(), ZERO_DELTA);
+ screenIdleHysteresis.getDarkeningThresholdLevels(), ZERO_DELTA);
+ assertArrayEquals(new float[]{0.37f, 0.38f, 0.39f},
+ screenIdleHysteresis.getDarkeningThresholdsPercentages(), ZERO_DELTA);
assertArrayEquals(new float[]{0, 30, 31},
- mDisplayDeviceConfig.getAmbientBrighteningLevelsIdle(), ZERO_DELTA);
- assertArrayEquals(new float[]{27, 28, 29},
- mDisplayDeviceConfig.getAmbientBrighteningPercentagesIdle(), ZERO_DELTA);
+ ambientIdleHysteresis.getBrighteningThresholdLevels(), ZERO_DELTA);
+ assertArrayEquals(new float[]{0.27f, 0.28f, 0.29f},
+ ambientIdleHysteresis.getBrighteningThresholdsPercentages(), ZERO_DELTA);
assertArrayEquals(new float[]{0, 30, 31},
- mDisplayDeviceConfig.getAmbientDarkeningLevelsIdle(), ZERO_DELTA);
- assertArrayEquals(new float[]{29, 30, 31},
- mDisplayDeviceConfig.getAmbientDarkeningPercentagesIdle(), ZERO_DELTA);
+ ambientIdleHysteresis.getDarkeningThresholdLevels(), ZERO_DELTA);
+ assertArrayEquals(new float[]{0.29f, 0.30f, 0.31f},
+ ambientIdleHysteresis.getDarkeningThresholdsPercentages(), ZERO_DELTA);
assertEquals(mDisplayDeviceConfig.getDefaultLowBlockingZoneRefreshRate(),
DEFAULT_LOW_BLOCKING_ZONE_REFRESH_RATE);
assertEquals(mDisplayDeviceConfig.getDefaultHighBlockingZoneRefreshRate(),
diff --git a/services/tests/displayservicetests/src/com/android/server/display/DisplayPowerControllerTest.java b/services/tests/displayservicetests/src/com/android/server/display/DisplayPowerControllerTest.java
index afb87d1df798..de939146f68e 100644
--- a/services/tests/displayservicetests/src/com/android/server/display/DisplayPowerControllerTest.java
+++ b/services/tests/displayservicetests/src/com/android/server/display/DisplayPowerControllerTest.java
@@ -82,6 +82,7 @@ import com.android.server.display.brightness.BrightnessReason;
import com.android.server.display.brightness.clamper.BrightnessClamperController;
import com.android.server.display.brightness.clamper.HdrClamper;
import com.android.server.display.color.ColorDisplayService;
+import com.android.server.display.config.HysteresisLevels;
import com.android.server.display.config.SensorData;
import com.android.server.display.feature.DisplayManagerFlags;
import com.android.server.display.feature.flags.Flags;
@@ -1954,6 +1955,14 @@ public final class DisplayPowerControllerTest {
.thenReturn(BRIGHTNESS_RAMP_INCREASE_MAX_IDLE);
when(displayDeviceConfigMock.getBrightnessRampDecreaseMaxIdleMillis())
.thenReturn(BRIGHTNESS_RAMP_DECREASE_MAX_IDLE);
+
+ final HysteresisLevels hysteresisLevels = mock(HysteresisLevels.class);
+ when(displayDeviceConfigMock.getAmbientBrightnessHysteresis()).thenReturn(hysteresisLevels);
+ when(displayDeviceConfigMock.getAmbientBrightnessIdleHysteresis()).thenReturn(
+ hysteresisLevels);
+ when(displayDeviceConfigMock.getScreenBrightnessHysteresis()).thenReturn(hysteresisLevels);
+ when(displayDeviceConfigMock.getScreenBrightnessIdleHysteresis()).thenReturn(
+ hysteresisLevels);
}
private DisplayPowerControllerHolder createDisplayPowerController(int displayId,
@@ -1995,7 +2004,7 @@ public final class DisplayPowerControllerTest {
TestInjector injector = spy(new TestInjector(displayPowerState, animator,
automaticBrightnessController, wakelockController, brightnessMappingStrategy,
- hysteresisLevels, screenOffBrightnessSensorController,
+ screenOffBrightnessSensorController,
hbmController, normalBrightnessModeController, hdrClamper,
clamperController, mDisplayManagerFlagsMock));
@@ -2005,6 +2014,11 @@ public final class DisplayPowerControllerTest {
final BrightnessSetting brightnessSetting = mock(BrightnessSetting.class);
final DisplayDeviceConfig config = mock(DisplayDeviceConfig.class);
+ when(config.getAmbientBrightnessHysteresis()).thenReturn(hysteresisLevels);
+ when(config.getAmbientBrightnessIdleHysteresis()).thenReturn(hysteresisLevels);
+ when(config.getScreenBrightnessHysteresis()).thenReturn(hysteresisLevels);
+ when(config.getScreenBrightnessIdleHysteresis()).thenReturn(hysteresisLevels);
+
setUpDisplay(displayId, uniqueId, display, device, config, isEnabled);
when(config.isAutoBrightnessAvailable()).thenReturn(isAutoBrightnessAvailable);
@@ -2080,7 +2094,6 @@ public final class DisplayPowerControllerTest {
private final AutomaticBrightnessController mAutomaticBrightnessController;
private final WakelockController mWakelockController;
private final BrightnessMappingStrategy mBrightnessMappingStrategy;
- private final HysteresisLevels mHysteresisLevels;
private final ScreenOffBrightnessSensorController mScreenOffBrightnessSensorController;
private final HighBrightnessModeController mHighBrightnessModeController;
@@ -2096,7 +2109,6 @@ public final class DisplayPowerControllerTest {
AutomaticBrightnessController automaticBrightnessController,
WakelockController wakelockController,
BrightnessMappingStrategy brightnessMappingStrategy,
- HysteresisLevels hysteresisLevels,
ScreenOffBrightnessSensorController screenOffBrightnessSensorController,
HighBrightnessModeController highBrightnessModeController,
NormalBrightnessModeController normalBrightnessModeController,
@@ -2108,7 +2120,6 @@ public final class DisplayPowerControllerTest {
mAutomaticBrightnessController = automaticBrightnessController;
mWakelockController = wakelockController;
mBrightnessMappingStrategy = brightnessMappingStrategy;
- mHysteresisLevels = hysteresisLevels;
mScreenOffBrightnessSensorController = screenOffBrightnessSensorController;
mHighBrightnessModeController = highBrightnessModeController;
mNormalBrightnessModeController = normalBrightnessModeController;
@@ -2186,22 +2197,6 @@ public final class DisplayPowerControllerTest {
}
@Override
- HysteresisLevels getHysteresisLevels(float[] brighteningThresholdsPercentages,
- float[] darkeningThresholdsPercentages, float[] brighteningThresholdLevels,
- float[] darkeningThresholdLevels, float minDarkeningThreshold,
- float minBrighteningThreshold) {
- return mHysteresisLevels;
- }
-
- @Override
- HysteresisLevels getHysteresisLevels(float[] brighteningThresholdsPercentages,
- float[] darkeningThresholdsPercentages, float[] brighteningThresholdLevels,
- float[] darkeningThresholdLevels, float minDarkeningThreshold,
- float minBrighteningThreshold, boolean potentialOldBrightnessRange) {
- return mHysteresisLevels;
- }
-
- @Override
ScreenOffBrightnessSensorController getScreenOffBrightnessSensorController(
SensorManager sensorManager, Sensor lightSensor, Handler handler,
ScreenOffBrightnessSensorController.Clock clock, int[] sensorValueToLux,