diff options
8 files changed, 1148 insertions, 254 deletions
diff --git a/services/core/java/com/android/server/display/AutomaticBrightnessController.java b/services/core/java/com/android/server/display/AutomaticBrightnessController.java index a7d372977ebb..40e28dadb4da 100644 --- a/services/core/java/com/android/server/display/AutomaticBrightnessController.java +++ b/services/core/java/com/android/server/display/AutomaticBrightnessController.java @@ -592,10 +592,14 @@ class AutomaticBrightnessController { } pw.println(); + pw.println(" mAmbientBrightnessThresholds="); mAmbientBrightnessThresholds.dump(pw); + pw.println(" mScreenBrightnessThresholds="); mScreenBrightnessThresholds.dump(pw); + pw.println(" mScreenBrightnessThresholdsIdle="); mScreenBrightnessThresholdsIdle.dump(pw); - mScreenBrightnessThresholdsIdle.dump(pw); + pw.println(" mAmbientBrightnessThresholdsIdle="); + mAmbientBrightnessThresholdsIdle.dump(pw); } private String configStateToString(int state) { @@ -860,6 +864,7 @@ class AutomaticBrightnessController { Slog.d(TAG, "updateAmbientLux: " + ((mFastAmbientLux > mAmbientLux) ? "Brightened" : "Darkened") + ": " + "mBrighteningLuxThreshold=" + mAmbientBrighteningThreshold + ", " + + "mAmbientDarkeningThreshold=" + mAmbientDarkeningThreshold + ", " + "mAmbientLightRingBuffer=" + mAmbientLightRingBuffer + ", " + "mAmbientLux=" + mAmbientLux); } diff --git a/services/core/java/com/android/server/display/DisplayDeviceConfig.java b/services/core/java/com/android/server/display/DisplayDeviceConfig.java index 416518613568..1ae37bb5d66b 100644 --- a/services/core/java/com/android/server/display/DisplayDeviceConfig.java +++ b/services/core/java/com/android/server/display/DisplayDeviceConfig.java @@ -27,6 +27,7 @@ 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.Spline; import android.view.DisplayAddress; @@ -51,7 +52,7 @@ import com.android.server.display.config.SdrHdrRatioPoint; import com.android.server.display.config.SensorDetails; import com.android.server.display.config.ThermalStatus; import com.android.server.display.config.ThermalThrottling; -import com.android.server.display.config.Thresholds; +import com.android.server.display.config.ThresholdPoint; import com.android.server.display.config.XmlParser; import org.xmlpull.v1.XmlPullParserException; @@ -188,42 +189,153 @@ import javax.xml.datatype.DatatypeConfigurationException; * <ambientLightHorizonLong>10001</ambientLightHorizonLong> * <ambientLightHorizonShort>2001</ambientLightHorizonShort> * - * <displayBrightnessChangeThresholds> // Thresholds for screen changes - * <brighteningThresholds> // Thresholds for active mode brightness changes. - * <minimum>0.001</minimum> // Minimum change needed in screen brightness to brighten. - * </brighteningThresholds> - * <darkeningThresholds> - * <minimum>0.002</minimum> // Minimum change needed in screen brightness to darken. - * </darkeningThresholds> - * </displayBrightnessChangeThresholds> - * - * <ambientBrightnessChangeThresholds> // Thresholds for lux changes - * <brighteningThresholds> // Thresholds for active mode brightness changes. - * <minimum>0.003</minimum> // Minimum change needed in ambient brightness to brighten. - * </brighteningThresholds> - * <darkeningThresholds> - * <minimum>0.004</minimum> // Minimum change needed in ambient brightness to darken. - * </darkeningThresholds> - * </ambientBrightnessChangeThresholds> - * - * <displayBrightnessChangeThresholdsIdle> // Thresholds for screen changes in idle mode - * <brighteningThresholds> // Thresholds for idle mode brightness changes. - * <minimum>0.001</minimum> // Minimum change needed in screen brightness to brighten. - * </brighteningThresholds> - * <darkeningThresholds> - * <minimum>0.002</minimum> // Minimum change needed in screen brightness to darken. - * </darkeningThresholds> - * </displayBrightnessChangeThresholdsIdle> - * - * <ambientBrightnessChangeThresholdsIdle> // Thresholds for lux changes in idle mode - * <brighteningThresholds> // Thresholds for idle mode brightness changes. - * <minimum>0.003</minimum> // Minimum change needed in ambient brightness to brighten. - * </brighteningThresholds> - * <darkeningThresholds> - * <minimum>0.004</minimum> // Minimum change needed in ambient brightness to darken. - * </darkeningThresholds> - * </ambientBrightnessChangeThresholdsIdle> - * + * <ambientBrightnessChangeThresholds> // Thresholds for lux changes + * <brighteningThresholds> + * // Minimum change needed in ambient brightness to brighten screen. + * <minimum>10</minimum> + * // Percentage increase of lux needed to increase the screen brightness at a lux range + * // above the specified threshold. + * <brightnessThresholdPoints> + * <brightnessThresholdPoint> + * <threshold>0</threshold><percentage>13</percentage> + * </brightnessThresholdPoint> + * <brightnessThresholdPoint> + * <threshold>100</threshold><percentage>14</percentage> + * </brightnessThresholdPoint> + * <brightnessThresholdPoint> + * <threshold>200</threshold><percentage>15</percentage> + * </brightnessThresholdPoint> + * </brightnessThresholdPoints> + * </brighteningThresholds> + * <darkeningThresholds> +* // Minimum change needed in ambient brightness to darken screen. + * <minimum>30</minimum> + * // Percentage increase of lux needed to decrease the screen brightness at a lux range + * // above the specified threshold. + * <brightnessThresholdPoints> + * <brightnessThresholdPoint> + * <threshold>0</threshold><percentage>15</percentage> + * </brightnessThresholdPoint> + * <brightnessThresholdPoint> + * <threshold>300</threshold><percentage>16</percentage> + * </brightnessThresholdPoint> + * <brightnessThresholdPoint> + * <threshold>400</threshold><percentage>17</percentage> + * </brightnessThresholdPoint> + * </brightnessThresholdPoints> + * </darkeningThresholds> + * </ambientBrightnessChangeThresholds> + * <displayBrightnessChangeThresholds> // Thresholds for screen brightness changes + * <brighteningThresholds> + * // Minimum change needed in screen brightness to brighten screen. + * <minimum>0.1</minimum> + * // Percentage increase of screen brightness needed to increase the screen brightness + * // at a lux range above the specified threshold. + * <brightnessThresholdPoints> + * <brightnessThresholdPoint> + * <threshold>0</threshold> + * <percentage>9</percentage> + * </brightnessThresholdPoint> + * <brightnessThresholdPoint> + * <threshold>0.10</threshold> + * <percentage>10</percentage> + * </brightnessThresholdPoint> + * <brightnessThresholdPoint> + * <threshold>0.20</threshold> + * <percentage>11</percentage> + * </brightnessThresholdPoint> + * </brightnessThresholdPoints> + * </brighteningThresholds> + * <darkeningThresholds> + * // Minimum change needed in screen brightness to darken screen. + * <minimum>0.3</minimum> + * // Percentage increase of screen brightness needed to decrease the screen brightness + * // at a lux range above the specified threshold. + * <brightnessThresholdPoints> + * <brightnessThresholdPoint> + * <threshold>0</threshold><percentage>11</percentage> + * </brightnessThresholdPoint> + * <brightnessThresholdPoint> + * <threshold>0.11</threshold><percentage>12</percentage> + * </brightnessThresholdPoint> + * <brightnessThresholdPoint> + * <threshold>0.21</threshold><percentage>13</percentage> + * </brightnessThresholdPoint> + * </brightnessThresholdPoints> + * </darkeningThresholds> + * </displayBrightnessChangeThresholds> + * <ambientBrightnessChangeThresholdsIdle> // Thresholds for lux changes in idle mode + * <brighteningThresholds> + * // Minimum change needed in ambient brightness to brighten screen in idle mode + * <minimum>20</minimum> + * // Percentage increase of lux needed to increase the screen brightness at a lux range + * // above the specified threshold whilst in idle mode. + * <brightnessThresholdPoints> + * <brightnessThresholdPoint> + * <threshold>0</threshold><percentage>21</percentage> + * </brightnessThresholdPoint> + * <brightnessThresholdPoint> + * <threshold>500</threshold><percentage>22</percentage> + * </brightnessThresholdPoint> + * <brightnessThresholdPoint> + * <threshold>600</threshold><percentage>23</percentage> + * </brightnessThresholdPoint> + * </brightnessThresholdPoints> + * </brighteningThresholds> + * <darkeningThresholds> + * // Minimum change needed in ambient brightness to darken screen in idle mode + * <minimum>40</minimum> + * // Percentage increase of lux needed to decrease the screen brightness at a lux range + * // above the specified threshold whilst in idle mode. + * <brightnessThresholdPoints> + * <brightnessThresholdPoint> + * <threshold>0</threshold><percentage>23</percentage> + * </brightnessThresholdPoint> + * <brightnessThresholdPoint> + * <threshold>700</threshold><percentage>24</percentage> + * </brightnessThresholdPoint> + * <brightnessThresholdPoint> + * <threshold>800</threshold><percentage>25</percentage> + * </brightnessThresholdPoint> + * </brightnessThresholdPoints> + * </darkeningThresholds> + * </ambientBrightnessChangeThresholdsIdle> + * <displayBrightnessChangeThresholdsIdle> // Thresholds for idle screen brightness changes + * <brighteningThresholds> + * // Minimum change needed in screen brightness to brighten screen in idle mode + * <minimum>0.2</minimum> + * // Percentage increase of screen brightness needed to increase the screen brightness + * // at a lux range above the specified threshold whilst in idle mode + * <brightnessThresholdPoints> + * <brightnessThresholdPoint> + * <threshold>0</threshold><percentage>17</percentage> + * </brightnessThresholdPoint> + * <brightnessThresholdPoint> + * <threshold>0.12</threshold><percentage>18</percentage> + * </brightnessThresholdPoint> + * <brightnessThresholdPoint> + * <threshold>0.22</threshold><percentage>19</percentage> + * </brightnessThresholdPoint> + * </brightnessThresholdPoints> + * </brighteningThresholds> + * <darkeningThresholds> + * // Minimum change needed in screen brightness to darken screen in idle mode + * <minimum>0.4</minimum> + * // Percentage increase of screen brightness needed to decrease the screen brightness + * // at a lux range above the specified threshold whilst in idle mode + * <brightnessThresholdPoints> + * <brightnessThresholdPoint> + * <threshold>0</threshold><percentage>19</percentage> + * </brightnessThresholdPoint> + * <brightnessThresholdPoint> + * <threshold>0.13</threshold><percentage>20</percentage> + * </brightnessThresholdPoint> + * <brightnessThresholdPoint> + * <threshold>0.23</threshold><percentage>21</percentage> + * </brightnessThresholdPoint> + * </brightnessThresholdPoints> + * </darkeningThresholds> + * </displayBrightnessChangeThresholdsIdle> * </displayConfiguration> * } * </pre> @@ -247,6 +359,13 @@ public class DisplayDeviceConfig { private static final String NO_SUFFIX_FORMAT = "%d"; private static final long STABLE_FLAG = 1L << 62; + 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; @@ -344,6 +463,31 @@ public class DisplayDeviceConfig { 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; + private Spline mBrightnessToBacklightSpline; private Spline mBacklightToBrightnessSpline; private Spline mBacklightToNitsSpline; @@ -684,7 +828,7 @@ public class DisplayDeviceConfig { /** * The minimum value for the ambient lux increase for a screen brightness change to actually * occur. - * @return float value in brightness scale of 0 - 1. + * @return float value in lux. */ public float getAmbientLuxBrighteningMinThreshold() { return mAmbientLuxBrighteningMinThreshold; @@ -693,7 +837,7 @@ public class DisplayDeviceConfig { /** * The minimum value for the ambient lux decrease for a screen brightness change to actually * occur. - * @return float value in brightness scale of 0 - 1. + * @return float value in lux. */ public float getAmbientLuxDarkeningMinThreshold() { return mAmbientLuxDarkeningMinThreshold; @@ -702,7 +846,7 @@ public class DisplayDeviceConfig { /** * 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 brightness scale of 0 - 1. + * @return float value in lux. */ public float getAmbientLuxBrighteningMinThresholdIdle() { return mAmbientLuxBrighteningMinThresholdIdle; @@ -711,12 +855,262 @@ public class DisplayDeviceConfig { /** * 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 brightness scale of 0 - 1. + * @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; + } + + /** + * 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; + } + + /** + * 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; + } + + /** + * 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; + } + SensorData getAmbientLightSensor() { return mAmbientLightSensor; } @@ -812,14 +1206,17 @@ public class DisplayDeviceConfig { + ", mSdrToHdrRatioSpline=" + mSdrToHdrRatioSpline + ", mBrightnessThrottlingData=" + mBrightnessThrottlingData + ", mOriginalBrightnessThrottlingData=" + mOriginalBrightnessThrottlingData + + "\n" + ", mBrightnessRampFastDecrease=" + mBrightnessRampFastDecrease + ", mBrightnessRampFastIncrease=" + mBrightnessRampFastIncrease + ", mBrightnessRampSlowDecrease=" + mBrightnessRampSlowDecrease + ", mBrightnessRampSlowIncrease=" + mBrightnessRampSlowIncrease + ", mBrightnessRampDecreaseMaxMillis=" + mBrightnessRampDecreaseMaxMillis + ", mBrightnessRampIncreaseMaxMillis=" + mBrightnessRampIncreaseMaxMillis + + "\n" + ", mAmbientHorizonLong=" + mAmbientHorizonLong + ", mAmbientHorizonShort=" + mAmbientHorizonShort + + "\n" + ", mScreenDarkeningMinThreshold=" + mScreenDarkeningMinThreshold + ", mScreenDarkeningMinThresholdIdle=" + mScreenDarkeningMinThresholdIdle + ", mScreenBrighteningMinThreshold=" + mScreenBrighteningMinThreshold @@ -829,6 +1226,41 @@ public class DisplayDeviceConfig { + ", mAmbientLuxBrighteningMinThreshold=" + mAmbientLuxBrighteningMinThreshold + ", mAmbientLuxBrighteningMinThresholdIdle=" + mAmbientLuxBrighteningMinThresholdIdle + + "\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) + + "\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) + + "\n" + ", mAmbientLightSensor=" + mAmbientLightSensor + ", mProximitySensor=" + mProximitySensor + ", mRefreshRateLimitations= " + Arrays.toString(mRefreshRateLimitations.toArray()) @@ -914,6 +1346,7 @@ public class DisplayDeviceConfig { loadBrightnessMapFromConfigXml(); loadBrightnessRampsFromConfigXml(); loadAmbientLightSensorFromConfigXml(); + loadBrightnessChangeThresholdsFromXml(); setProxSensorUnspecified(); loadAutoBrightnessConfigsFromConfigXml(); mLoadedFrom = "<config.xml>"; @@ -1454,91 +1887,287 @@ public class DisplayDeviceConfig { } } + private void loadBrightnessChangeThresholdsFromXml() { + loadBrightnessChangeThresholds(/* config= */ null); + } + private void loadBrightnessChangeThresholds(DisplayConfiguration config) { - Thresholds displayBrightnessThresholds = config.getDisplayBrightnessChangeThresholds(); - Thresholds ambientBrightnessThresholds = config.getAmbientBrightnessChangeThresholds(); - Thresholds displayBrightnessThresholdsIdle = - config.getDisplayBrightnessChangeThresholdsIdle(); - Thresholds ambientBrightnessThresholdsIdle = - config.getAmbientBrightnessChangeThresholdsIdle(); - - loadDisplayBrightnessThresholds(displayBrightnessThresholds); - loadAmbientBrightnessThresholds(ambientBrightnessThresholds); - loadIdleDisplayBrightnessThresholds(displayBrightnessThresholdsIdle); - loadIdleAmbientBrightnessThresholds(ambientBrightnessThresholdsIdle); - } - - private void loadDisplayBrightnessThresholds(Thresholds displayBrightnessThresholds) { - if (displayBrightnessThresholds != null) { - BrightnessThresholds brighteningScreen = - displayBrightnessThresholds.getBrighteningThresholds(); - BrightnessThresholds darkeningScreen = - displayBrightnessThresholds.getDarkeningThresholds(); - - if (brighteningScreen != null && brighteningScreen.getMinimum() != null) { - mScreenBrighteningMinThreshold = brighteningScreen.getMinimum().floatValue(); + 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++; } - if (darkeningScreen != null && darkeningScreen.getMinimum() != null) { - mScreenDarkeningMinThreshold = darkeningScreen.getMinimum().floatValue(); + 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; } - } - } - private void loadAmbientBrightnessThresholds(Thresholds ambientBrightnessThresholds) { - if (ambientBrightnessThresholds != null) { - BrightnessThresholds brighteningAmbientLux = - ambientBrightnessThresholds.getBrighteningThresholds(); - BrightnessThresholds darkeningAmbientLux = - ambientBrightnessThresholds.getDarkeningThresholds(); - final BigDecimal ambientBrighteningThreshold = brighteningAmbientLux.getMinimum(); - final BigDecimal ambientDarkeningThreshold = darkeningAmbientLux.getMinimum(); + // Load percentage array + int[] configPermille = mContext.getResources().getIntArray( + configFallbackPermille); - if (ambientBrighteningThreshold != null) { - mAmbientLuxBrighteningMinThreshold = ambientBrighteningThreshold.floatValue(); + // Ensure lengths match up + boolean emptyArray = configPermille == null || configPermille.length == 0; + if (emptyArray && configThresholdsSize == 1) { + return new Pair<>(defaultLevels, defaultPercentage); } - if (ambientDarkeningThreshold != null) { - mAmbientLuxDarkeningMinThreshold = ambientDarkeningThreshold.floatValue(); + if (emptyArray || configPermille.length != configThresholdsSize) { + throw new IllegalArgumentException( + "Brightness threshold arrays do not align in length"); } - } - } - - private void loadIdleDisplayBrightnessThresholds(Thresholds idleDisplayBrightnessThresholds) { - if (idleDisplayBrightnessThresholds != null) { - BrightnessThresholds brighteningScreenIdle = - idleDisplayBrightnessThresholds.getBrighteningThresholds(); - BrightnessThresholds darkeningScreenIdle = - idleDisplayBrightnessThresholds.getDarkeningThresholds(); - if (brighteningScreenIdle != null - && brighteningScreenIdle.getMinimum() != null) { - mScreenBrighteningMinThresholdIdle = - brighteningScreenIdle.getMinimum().floatValue(); + // 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 (darkeningScreenIdle != null && darkeningScreenIdle.getMinimum() != null) { - mScreenDarkeningMinThresholdIdle = - darkeningScreenIdle.getMinimum().floatValue(); + 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); } } - private void loadIdleAmbientBrightnessThresholds(Thresholds idleAmbientBrightnessThresholds) { - if (idleAmbientBrightnessThresholds != null) { - BrightnessThresholds brighteningAmbientLuxIdle = - idleAmbientBrightnessThresholds.getBrighteningThresholds(); - BrightnessThresholds darkeningAmbientLuxIdle = - idleAmbientBrightnessThresholds.getDarkeningThresholds(); + /** + * 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; + } - if (brighteningAmbientLuxIdle != null - && brighteningAmbientLuxIdle.getMinimum() != null) { - mAmbientLuxBrighteningMinThresholdIdle = - brighteningAmbientLuxIdle.getMinimum().floatValue(); - } - if (darkeningAmbientLuxIdle != null && darkeningAmbientLuxIdle.getMinimum() != null) { - mAmbientLuxDarkeningMinThresholdIdle = - darkeningAmbientLuxIdle.getMinimum().floatValue(); + 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; } 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 9734601d65ae..ef14300ffefc 100644 --- a/services/core/java/com/android/server/display/DisplayPowerController.java +++ b/services/core/java/com/android/server/display/DisplayPowerController.java @@ -956,54 +956,78 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call com.android.internal.R.fraction.config_screenAutoBrightnessDozeScaleFactor, 1, 1); - int[] ambientBrighteningThresholds = resources.getIntArray( - com.android.internal.R.array.config_ambientBrighteningThresholds); - int[] ambientDarkeningThresholds = resources.getIntArray( - com.android.internal.R.array.config_ambientDarkeningThresholds); - int[] ambientThresholdLevels = resources.getIntArray( - com.android.internal.R.array.config_ambientThresholdLevels); + // 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 = new HysteresisLevels( ambientBrighteningThresholds, ambientDarkeningThresholds, - ambientThresholdLevels, ambientDarkeningMinThreshold, + ambientBrighteningLevels, ambientDarkeningLevels, ambientDarkeningMinThreshold, ambientBrighteningMinThreshold); - int[] screenBrighteningThresholds = resources.getIntArray( - com.android.internal.R.array.config_screenBrighteningThresholds); - int[] screenDarkeningThresholds = resources.getIntArray( - com.android.internal.R.array.config_screenDarkeningThresholds); - float[] screenThresholdLevels = BrightnessMappingStrategy.getFloatArray(resources - .obtainTypedArray(com.android.internal.R.array.config_screenThresholdLevels)); + // 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 = new HysteresisLevels( - screenBrighteningThresholds, screenDarkeningThresholds, screenThresholdLevels, - screenDarkeningMinThreshold, screenBrighteningMinThreshold); + screenBrighteningThresholds, screenDarkeningThresholds, + screenBrighteningLevels, screenDarkeningLevels, screenDarkeningMinThreshold, + screenBrighteningMinThreshold); - // Idle screen thresholds + // 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 = new HysteresisLevels( + ambientBrighteningThresholdsIdle, ambientDarkeningThresholdsIdle, + ambientBrighteningLevelsIdle, ambientDarkeningLevelsIdle, + ambientDarkeningMinThresholdIdle, ambientBrighteningMinThresholdIdle); + + // 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 = new HysteresisLevels( - screenBrighteningThresholds, screenDarkeningThresholds, screenThresholdLevels, + screenBrighteningThresholdsIdle, screenDarkeningThresholdsIdle, + screenBrighteningLevelsIdle, screenDarkeningLevelsIdle, screenDarkeningMinThresholdIdle, screenBrighteningMinThresholdIdle); - // Idle ambient thresholds - float ambientDarkeningMinThresholdIdle = - mDisplayDeviceConfig.getAmbientLuxDarkeningMinThresholdIdle(); - float ambientBrighteningMinThresholdIdle = - mDisplayDeviceConfig.getAmbientLuxBrighteningMinThresholdIdle(); - HysteresisLevels ambientBrightnessThresholdsIdle = new HysteresisLevels( - ambientBrighteningThresholds, ambientDarkeningThresholds, - ambientThresholdLevels, ambientDarkeningMinThresholdIdle, - ambientBrighteningMinThresholdIdle); - long brighteningLightDebounce = mDisplayDeviceConfig .getAutoBrightnessBrighteningLightDebounce(); long darkeningLightDebounce = mDisplayDeviceConfig diff --git a/services/core/java/com/android/server/display/HysteresisLevels.java b/services/core/java/com/android/server/display/HysteresisLevels.java index abf8fe3d3f17..faa4c3d2abc5 100644 --- a/services/core/java/com/android/server/display/HysteresisLevels.java +++ b/services/core/java/com/android/server/display/HysteresisLevels.java @@ -29,52 +29,38 @@ public class HysteresisLevels { private static final boolean DEBUG = false; - private final float[] mBrighteningThresholds; - private final float[] mDarkeningThresholds; - private final float[] mThresholdLevels; + 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 for ambient brightness. - * @param brighteningThresholds an array of brightening hysteresis constraint constants. - * @param darkeningThresholds an array of darkening hysteresis constraint constants. - * @param thresholdLevels a monotonically increasing array of threshold levels. - * @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. - */ - HysteresisLevels(int[] brighteningThresholds, int[] darkeningThresholds, - int[] thresholdLevels, float minDarkeningThreshold, float minBrighteningThreshold) { - if (brighteningThresholds.length != darkeningThresholds.length - || darkeningThresholds.length != thresholdLevels.length + 1) { - throw new IllegalArgumentException("Mismatch between hysteresis array lengths."); - } - mBrighteningThresholds = setArrayFormat(brighteningThresholds, 1000.0f); - mDarkeningThresholds = setArrayFormat(darkeningThresholds, 1000.0f); - mThresholdLevels = setArrayFormat(thresholdLevels, 1.0f); - mMinDarkening = minDarkeningThreshold; - mMinBrightening = minBrighteningThreshold; - } - - /** - * Creates a {@code HysteresisLevels} object for screen brightness. - * @param brighteningThresholds an array of brightening hysteresis constraint constants. - * @param darkeningThresholds an array of darkening hysteresis constraint constants. - * @param thresholdLevels a monotonically increasing array of threshold levels. + * 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 darkeningThresholdLevels 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. */ - HysteresisLevels(int[] brighteningThresholds, int[] darkeningThresholds, - float[] thresholdLevels, float minDarkeningThreshold, float minBrighteningThreshold) { - if (brighteningThresholds.length != darkeningThresholds.length - || darkeningThresholds.length != thresholdLevels.length + 1) { + 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."); } - mBrighteningThresholds = setArrayFormat(brighteningThresholds, 1000.0f); - mDarkeningThresholds = setArrayFormat(darkeningThresholds, 1000.0f); - mThresholdLevels = constraintInRangeIfNeeded(thresholdLevels); + mBrighteningThresholdsPercentages = + setArrayFormat(brighteningThresholdsPercentages, 100.0f); + mDarkeningThresholdsPercentages = + setArrayFormat(darkeningThresholdsPercentages, 100.0f); + mBrighteningThresholdLevels = setArrayFormat(brighteningThresholdLevels, 1.0f); + mDarkeningThresholdLevels = setArrayFormat(darkeningThresholdLevels, 1.0f); mMinDarkening = minDarkeningThreshold; mMinBrightening = minBrighteningThreshold; } @@ -83,7 +69,9 @@ public class HysteresisLevels { * Return the brightening hysteresis threshold for the given value level. */ public float getBrighteningThreshold(float value) { - final float brightConstant = getReferenceLevel(value, mBrighteningThresholds); + final float brightConstant = getReferenceLevel(value, + mBrighteningThresholdLevels, mBrighteningThresholdsPercentages); + float brightThreshold = value * (1.0f + brightConstant); if (DEBUG) { Slog.d(TAG, "bright hysteresis constant=" + brightConstant + ", threshold=" @@ -98,7 +86,8 @@ public class HysteresisLevels { * Return the darkening hysteresis threshold for the given value level. */ public float getDarkeningThreshold(float value) { - final float darkConstant = getReferenceLevel(value, mDarkeningThresholds); + final float darkConstant = getReferenceLevel(value, + mDarkeningThresholdLevels, mDarkeningThresholdsPercentages); float darkThreshold = value * (1.0f - darkConstant); if (DEBUG) { Slog.d(TAG, "dark hysteresis constant=: " + darkConstant + ", threshold=" @@ -111,60 +100,39 @@ public class HysteresisLevels { /** * Return the hysteresis constant for the closest threshold value from the given array. */ - private float getReferenceLevel(float value, float[] referenceLevels) { + 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 (mThresholdLevels.length > index && value >= mThresholdLevels[index]) { - ++index; + while (index < thresholdLevels.length - 1 && value >= thresholdLevels[index + 1]) { + index++; } - return referenceLevels[index]; + return thresholdPercentages[index]; } /** * Return a float array where each i-th element equals {@code configArray[i]/divideFactor}. */ - private float[] setArrayFormat(int[] configArray, float divideFactor) { + private float[] setArrayFormat(float[] configArray, float divideFactor) { float[] levelArray = new float[configArray.length]; for (int index = 0; levelArray.length > index; ++index) { - levelArray[index] = (float) configArray[index] / divideFactor; + levelArray[index] = configArray[index] / divideFactor; } return levelArray; } - /** - * 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) { - int configArraySize = configArray.length; - for (int index = 0; configArraySize > index; ++index) { - if (configArray[index] < minValueInclusive || configArray[index] > maxValueInclusive) { - return false; - } - } - return true; - } void dump(PrintWriter pw) { pw.println("HysteresisLevels"); - pw.println(" mBrighteningThresholds=" + Arrays.toString(mBrighteningThresholds)); - pw.println(" mDarkeningThresholds=" + Arrays.toString(mDarkeningThresholds)); - pw.println(" mThresholdLevels=" + Arrays.toString(mThresholdLevels)); + 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/xsd/display-device-config/display-device-config.xsd b/services/core/xsd/display-device-config/display-device-config.xsd index 267cff6652bb..4a51b831da57 100644 --- a/services/core/xsd/display-device-config/display-device-config.xsd +++ b/services/core/xsd/display-device-config/display-device-config.xsd @@ -351,6 +351,35 @@ <xs:annotation name="nonnull"/> <xs:annotation name="final"/> </xs:element> + <xs:sequence> + <!-- Thresholds as tenths of percent of current brightness level, at each level of + brightness --> + <xs:element name="brightnessThresholdPoints" type="thresholdPoints" maxOccurs="1" minOccurs="0"> + <xs:annotation name="final"/> + </xs:element> + </xs:sequence> + </xs:complexType> + + <xs:complexType name="thresholdPoints"> + <xs:sequence> + <xs:element type="thresholdPoint" name="brightnessThresholdPoint" maxOccurs="unbounded" minOccurs="1"> + <xs:annotation name="nonnull"/> + <xs:annotation name="final"/> + </xs:element> + </xs:sequence> + </xs:complexType> + + <xs:complexType name="thresholdPoint"> + <xs:sequence> + <xs:element type="nonNegativeDecimal" name="threshold"> + <xs:annotation name="nonnull"/> + <xs:annotation name="final"/> + </xs:element> + <xs:element type="nonNegativeDecimal" name="percentage"> + <xs:annotation name="nonnull"/> + <xs:annotation name="final"/> + </xs:element> + </xs:sequence> </xs:complexType> <xs:complexType name="autoBrightness"> diff --git a/services/core/xsd/display-device-config/schema/current.txt b/services/core/xsd/display-device-config/schema/current.txt index f8bff757f1ac..748ef4be9cc7 100644 --- a/services/core/xsd/display-device-config/schema/current.txt +++ b/services/core/xsd/display-device-config/schema/current.txt @@ -13,7 +13,9 @@ package com.android.server.display.config { public class BrightnessThresholds { ctor public BrightnessThresholds(); + method public final com.android.server.display.config.ThresholdPoints getBrightnessThresholdPoints(); method @NonNull public final java.math.BigDecimal getMinimum(); + method public final void setBrightnessThresholdPoints(com.android.server.display.config.ThresholdPoints); method public final void setMinimum(@NonNull java.math.BigDecimal); } @@ -204,6 +206,19 @@ package com.android.server.display.config { method public final void setBrightnessThrottlingMap(@NonNull com.android.server.display.config.BrightnessThrottlingMap); } + public class ThresholdPoint { + ctor public ThresholdPoint(); + method @NonNull public final java.math.BigDecimal getPercentage(); + method @NonNull public final java.math.BigDecimal getThreshold(); + method public final void setPercentage(@NonNull java.math.BigDecimal); + method public final void setThreshold(@NonNull java.math.BigDecimal); + } + + public class ThresholdPoints { + ctor public ThresholdPoints(); + method @NonNull public final java.util.List<com.android.server.display.config.ThresholdPoint> getBrightnessThresholdPoint(); + } + public class Thresholds { ctor public Thresholds(); method @NonNull public final com.android.server.display.config.BrightnessThresholds getBrighteningThresholds(); diff --git a/services/tests/servicestests/src/com/android/server/display/AutomaticBrightnessControllerTest.java b/services/tests/servicestests/src/com/android/server/display/AutomaticBrightnessControllerTest.java index 8280fc6c962f..4f2b613d7aed 100644 --- a/services/tests/servicestests/src/com/android/server/display/AutomaticBrightnessControllerTest.java +++ b/services/tests/servicestests/src/com/android/server/display/AutomaticBrightnessControllerTest.java @@ -422,13 +422,13 @@ public class AutomaticBrightnessControllerTest { @Test public void testHysteresisLevels() { - int[] ambientBrighteningThresholds = {100, 200}; - int[] ambientDarkeningThresholds = {400, 500}; - int[] ambientThresholdLevels = {500}; + float[] ambientBrighteningThresholds = {50, 100}; + float[] ambientDarkeningThresholds = {10, 20}; + float[] ambientThresholdLevels = {0, 500}; float ambientDarkeningMinChangeThreshold = 3.0f; float ambientBrighteningMinChangeThreshold = 1.5f; HysteresisLevels hysteresisLevels = new HysteresisLevels(ambientBrighteningThresholds, - ambientDarkeningThresholds, ambientThresholdLevels, + ambientDarkeningThresholds, ambientThresholdLevels, ambientThresholdLevels, ambientDarkeningMinChangeThreshold, ambientBrighteningMinChangeThreshold); // test low, activate minimum change thresholds. @@ -437,16 +437,17 @@ public class AutomaticBrightnessControllerTest { assertEquals(1f, hysteresisLevels.getDarkeningThreshold(4.0f), EPSILON); // test max - assertEquals(12000f, hysteresisLevels.getBrighteningThreshold(10000.0f), EPSILON); - assertEquals(5000f, hysteresisLevels.getDarkeningThreshold(10000.0f), EPSILON); + // epsilon is x2 here, since the next floating point value about 20,000 is 0.0019531 greater + assertEquals(20000f, hysteresisLevels.getBrighteningThreshold(10000.0f), EPSILON * 2); + assertEquals(8000f, hysteresisLevels.getDarkeningThreshold(10000.0f), EPSILON); // test just below threshold - assertEquals(548.9f, hysteresisLevels.getBrighteningThreshold(499f), EPSILON); - assertEquals(299.4f, hysteresisLevels.getDarkeningThreshold(499f), EPSILON); + assertEquals(748.5f, hysteresisLevels.getBrighteningThreshold(499f), EPSILON); + assertEquals(449.1f, hysteresisLevels.getDarkeningThreshold(499f), EPSILON); // test at (considered above) threshold - assertEquals(600f, hysteresisLevels.getBrighteningThreshold(500f), EPSILON); - assertEquals(250f, hysteresisLevels.getDarkeningThreshold(500f), EPSILON); + assertEquals(1000f, hysteresisLevels.getBrighteningThreshold(500f), EPSILON); + assertEquals(400f, hysteresisLevels.getDarkeningThreshold(500f), EPSILON); } @Test diff --git a/services/tests/servicestests/src/com/android/server/display/DisplayDeviceConfigTest.java b/services/tests/servicestests/src/com/android/server/display/DisplayDeviceConfigTest.java index 66420ad4572e..a719f526a1d8 100644 --- a/services/tests/servicestests/src/com/android/server/display/DisplayDeviceConfigTest.java +++ b/services/tests/servicestests/src/com/android/server/display/DisplayDeviceConfigTest.java @@ -32,6 +32,8 @@ import android.platform.test.annotations.Presubmit; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; +import com.android.internal.R; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -48,6 +50,9 @@ import java.nio.file.Path; @RunWith(AndroidJUnit4.class) public final class DisplayDeviceConfigTest { private DisplayDeviceConfig mDisplayDeviceConfig; + private static final float ZERO_DELTA = 0.0f; + private static final float SMALL_DELTA = 0.0001f; + @Mock private Context mContext; @@ -69,26 +74,74 @@ public final class DisplayDeviceConfigTest { assertEquals(mDisplayDeviceConfig.getAmbientHorizonShort(), 50); assertEquals(mDisplayDeviceConfig.getBrightnessRampDecreaseMaxMillis(), 3000); assertEquals(mDisplayDeviceConfig.getBrightnessRampIncreaseMaxMillis(), 2000); - assertEquals(mDisplayDeviceConfig.getAmbientLuxBrighteningMinThreshold(), 10.0f, 0.0f); - assertEquals(mDisplayDeviceConfig.getAmbientLuxDarkeningMinThreshold(), 2.0f, 0.0f); - assertEquals(mDisplayDeviceConfig.getBrightnessRampFastDecrease(), 0.01f, 0.0f); - assertEquals(mDisplayDeviceConfig.getBrightnessRampFastIncrease(), 0.02f, 0.0f); - assertEquals(mDisplayDeviceConfig.getBrightnessRampSlowIncrease(), 0.04f, 0.0f); - assertEquals(mDisplayDeviceConfig.getBrightnessRampSlowDecrease(), 0.03f, 0.0f); - assertEquals(mDisplayDeviceConfig.getBrightnessDefault(), 0.5f, 0.0f); + assertEquals(mDisplayDeviceConfig.getBrightnessRampFastDecrease(), 0.01f, ZERO_DELTA); + assertEquals(mDisplayDeviceConfig.getBrightnessRampFastIncrease(), 0.02f, ZERO_DELTA); + assertEquals(mDisplayDeviceConfig.getBrightnessRampSlowIncrease(), 0.04f, ZERO_DELTA); + assertEquals(mDisplayDeviceConfig.getBrightnessRampSlowDecrease(), 0.03f, ZERO_DELTA); + assertEquals(mDisplayDeviceConfig.getBrightnessDefault(), 0.5f, ZERO_DELTA); assertArrayEquals(mDisplayDeviceConfig.getBrightness(), new float[]{0.0f, 0.62f, 1.0f}, - 0.0f); - assertArrayEquals(mDisplayDeviceConfig.getNits(), new float[]{2.0f, 500.0f, 800.0f}, 0.0f); + ZERO_DELTA); + assertArrayEquals(mDisplayDeviceConfig.getNits(), new float[]{2.0f, 500.0f, 800.0f}, + ZERO_DELTA); assertArrayEquals(mDisplayDeviceConfig.getBacklight(), new float[]{0.0f, 0.62f, 1.0f}, - 0.0f); - assertEquals(mDisplayDeviceConfig.getScreenBrighteningMinThreshold(), 0.001, 0.000001f); - assertEquals(mDisplayDeviceConfig.getScreenDarkeningMinThreshold(), 0.002, 0.000001f); + ZERO_DELTA); assertEquals(mDisplayDeviceConfig.getAutoBrightnessBrighteningLightDebounce(), 2000); assertEquals(mDisplayDeviceConfig.getAutoBrightnessDarkeningLightDebounce(), 1000); assertArrayEquals(mDisplayDeviceConfig.getAutoBrightnessBrighteningLevelsLux(), new - float[]{0.0f, 50.0f, 80.0f}, 0.0f); + float[]{0.0f, 50.0f, 80.0f}, ZERO_DELTA); assertArrayEquals(mDisplayDeviceConfig.getAutoBrightnessBrighteningLevelsNits(), new - float[]{45.32f, 75.43f}, 0.0f); + float[]{45.32f, 75.43f}, 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); + + assertArrayEquals(new float[]{0, 0.10f, 0.20f}, + mDisplayDeviceConfig.getScreenBrighteningLevels(), ZERO_DELTA); + assertArrayEquals(new float[]{9, 10, 11}, + mDisplayDeviceConfig.getScreenBrighteningPercentages(), ZERO_DELTA); + assertArrayEquals(new float[]{0, 0.11f, 0.21f}, + mDisplayDeviceConfig.getScreenDarkeningLevels(), ZERO_DELTA); + assertArrayEquals(new float[]{11, 12, 13}, + mDisplayDeviceConfig.getScreenDarkeningPercentages(), ZERO_DELTA); + + assertArrayEquals(new float[]{0, 100, 200}, + mDisplayDeviceConfig.getAmbientBrighteningLevels(), ZERO_DELTA); + assertArrayEquals(new float[]{13, 14, 15}, + mDisplayDeviceConfig.getAmbientBrighteningPercentages(), ZERO_DELTA); + assertArrayEquals(new float[]{0, 300, 400}, + mDisplayDeviceConfig.getAmbientDarkeningLevels(), ZERO_DELTA); + assertArrayEquals(new float[]{15, 16, 17}, + mDisplayDeviceConfig.getAmbientDarkeningPercentages(), ZERO_DELTA); + + assertArrayEquals(new float[]{0, 0.12f, 0.22f}, + mDisplayDeviceConfig.getScreenBrighteningLevelsIdle(), ZERO_DELTA); + assertArrayEquals(new float[]{17, 18, 19}, + mDisplayDeviceConfig.getScreenBrighteningPercentagesIdle(), ZERO_DELTA); + assertArrayEquals(new float[]{0, 0.13f, 0.23f}, + mDisplayDeviceConfig.getScreenDarkeningLevelsIdle(), ZERO_DELTA); + assertArrayEquals(new float[]{19, 20, 21}, + mDisplayDeviceConfig.getScreenDarkeningPercentagesIdle(), ZERO_DELTA); + + assertArrayEquals(new float[]{0, 500, 600}, + mDisplayDeviceConfig.getAmbientBrighteningLevelsIdle(), ZERO_DELTA); + assertArrayEquals(new float[]{21, 22, 23}, + mDisplayDeviceConfig.getAmbientBrighteningPercentagesIdle(), ZERO_DELTA); + assertArrayEquals(new float[]{0, 700, 800}, + mDisplayDeviceConfig.getAmbientDarkeningLevelsIdle(), ZERO_DELTA); + assertArrayEquals(new float[]{23, 24, 25}, + mDisplayDeviceConfig.getAmbientDarkeningPercentagesIdle(), ZERO_DELTA); + + // Todo(brup): Add asserts for BrightnessThrottlingData, DensityMapping, // HighBrightnessModeData AmbientLightSensor, RefreshRateLimitations and ProximitySensor. } @@ -97,9 +150,60 @@ public final class DisplayDeviceConfigTest { public void testConfigValuesFromConfigResource() { setupDisplayDeviceConfigFromConfigResourceFile(); assertArrayEquals(mDisplayDeviceConfig.getAutoBrightnessBrighteningLevelsNits(), new - float[]{2.0f, 200.0f, 600.0f}, 0.0f); + float[]{2.0f, 200.0f, 600.0f}, ZERO_DELTA); assertArrayEquals(mDisplayDeviceConfig.getAutoBrightnessBrighteningLevelsLux(), new - float[]{0.0f, 0.0f, 110.0f, 500.0f}, 0.0f); + float[]{0.0f, 0.0f, 110.0f, 500.0f}, ZERO_DELTA); + + // 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, mDisplayDeviceConfig.getScreenBrighteningMinThreshold(), ZERO_DELTA); + assertEquals(0, mDisplayDeviceConfig.getScreenBrighteningMinThresholdIdle(), ZERO_DELTA); + assertEquals(0, mDisplayDeviceConfig.getScreenDarkeningMinThreshold(), ZERO_DELTA); + assertEquals(0, mDisplayDeviceConfig.getScreenDarkeningMinThresholdIdle(), 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); + assertArrayEquals(new float[]{0, 42 / 255f, 43 / 255f}, + mDisplayDeviceConfig.getScreenDarkeningLevels(), SMALL_DELTA); + assertArrayEquals(new float[]{37, 38, 39}, + mDisplayDeviceConfig.getScreenDarkeningPercentages(), ZERO_DELTA); + + assertArrayEquals(new float[]{0, 30, 31}, + mDisplayDeviceConfig.getAmbientBrighteningLevels(), ZERO_DELTA); + assertArrayEquals(new float[]{27, 28, 29}, + mDisplayDeviceConfig.getAmbientBrighteningPercentages(), ZERO_DELTA); + assertArrayEquals(new float[]{0, 30, 31}, + mDisplayDeviceConfig.getAmbientDarkeningLevels(), ZERO_DELTA); + assertArrayEquals(new float[]{29, 30, 31}, + mDisplayDeviceConfig.getAmbientDarkeningPercentages(), ZERO_DELTA); + + assertArrayEquals(new float[]{0, 42 / 255f, 43 / 255f}, + mDisplayDeviceConfig.getScreenBrighteningLevelsIdle(), SMALL_DELTA); + assertArrayEquals(new float[]{35, 36, 37}, + mDisplayDeviceConfig.getScreenBrighteningPercentagesIdle(), ZERO_DELTA); + assertArrayEquals(new float[]{0, 42 / 255f, 43 / 255f}, + mDisplayDeviceConfig.getScreenDarkeningLevelsIdle(), SMALL_DELTA); + assertArrayEquals(new float[]{37, 38, 39}, + mDisplayDeviceConfig.getScreenDarkeningPercentagesIdle(), ZERO_DELTA); + + assertArrayEquals(new float[]{0, 30, 31}, + mDisplayDeviceConfig.getAmbientBrighteningLevelsIdle(), ZERO_DELTA); + assertArrayEquals(new float[]{27, 28, 29}, + mDisplayDeviceConfig.getAmbientBrighteningPercentagesIdle(), ZERO_DELTA); + assertArrayEquals(new float[]{0, 30, 31}, + mDisplayDeviceConfig.getAmbientDarkeningLevelsIdle(), ZERO_DELTA); + assertArrayEquals(new float[]{29, 30, 31}, + mDisplayDeviceConfig.getAmbientDarkeningPercentagesIdle(), ZERO_DELTA); + // Todo(brup): Add asserts for BrightnessThrottlingData, DensityMapping, // HighBrightnessModeData AmbientLightSensor, RefreshRateLimitations and ProximitySensor. } @@ -154,11 +258,126 @@ public final class DisplayDeviceConfigTest { + "<ambientBrightnessChangeThresholds>\n" + "<brighteningThresholds>\n" + "<minimum>10</minimum>\n" + + "<brightnessThresholdPoints>\n" + + "<brightnessThresholdPoint>\n" + + "<threshold>0</threshold><percentage>13</percentage>\n" + + "</brightnessThresholdPoint>\n" + + "<brightnessThresholdPoint>\n" + + "<threshold>100</threshold><percentage>14</percentage>\n" + + "</brightnessThresholdPoint>\n" + + "<brightnessThresholdPoint>\n" + + "<threshold>200</threshold><percentage>15</percentage>\n" + + "</brightnessThresholdPoint>\n" + + "</brightnessThresholdPoints>\n" + "</brighteningThresholds>\n" + "<darkeningThresholds>\n" - + "<minimum>2</minimum>\n" + + "<minimum>30</minimum>\n" + + "<brightnessThresholdPoints>\n" + + "<brightnessThresholdPoint>\n" + + "<threshold>0</threshold><percentage>15</percentage>\n" + + "</brightnessThresholdPoint>\n" + + "<brightnessThresholdPoint>\n" + + "<threshold>300</threshold><percentage>16</percentage>\n" + + "</brightnessThresholdPoint>\n" + + "<brightnessThresholdPoint>\n" + + "<threshold>400</threshold><percentage>17</percentage>\n" + + "</brightnessThresholdPoint>\n" + + "</brightnessThresholdPoints>\n" + "</darkeningThresholds>\n" + "</ambientBrightnessChangeThresholds>\n" + + "<displayBrightnessChangeThresholds>\n" + + "<brighteningThresholds>\n" + + "<minimum>0.1</minimum>\n" + + "<brightnessThresholdPoints>\n" + + "<brightnessThresholdPoint>\n" + + "<threshold>0</threshold>\n" + + "<percentage>9</percentage>\n" + + "</brightnessThresholdPoint>\n" + + "<brightnessThresholdPoint>\n" + + "<threshold>0.10</threshold>\n" + + "<percentage>10</percentage>\n" + + "</brightnessThresholdPoint>\n" + + "<brightnessThresholdPoint>\n" + + "<threshold>0.20</threshold>\n" + + "<percentage>11</percentage>\n" + + "</brightnessThresholdPoint>\n" + + "</brightnessThresholdPoints>\n" + + "</brighteningThresholds>\n" + + "<darkeningThresholds>\n" + + "<minimum>0.3</minimum>\n" + + "<brightnessThresholdPoints>\n" + + "<brightnessThresholdPoint>\n" + + "<threshold>0</threshold><percentage>11</percentage>\n" + + "</brightnessThresholdPoint>\n" + + "<brightnessThresholdPoint>\n" + + "<threshold>0.11</threshold><percentage>12</percentage>\n" + + "</brightnessThresholdPoint>\n" + + "<brightnessThresholdPoint>\n" + + "<threshold>0.21</threshold><percentage>13</percentage>\n" + + "</brightnessThresholdPoint>\n" + + "</brightnessThresholdPoints>\n" + + "</darkeningThresholds>\n" + + "</displayBrightnessChangeThresholds>\n" + + "<ambientBrightnessChangeThresholdsIdle>\n" + + "<brighteningThresholds>\n" + + "<minimum>20</minimum>\n" + + "<brightnessThresholdPoints>\n" + + "<brightnessThresholdPoint>\n" + + "<threshold>0</threshold><percentage>21</percentage>\n" + + "</brightnessThresholdPoint>\n" + + "<brightnessThresholdPoint>\n" + + "<threshold>500</threshold><percentage>22</percentage>\n" + + "</brightnessThresholdPoint>\n" + + "<brightnessThresholdPoint>\n" + + "<threshold>600</threshold><percentage>23</percentage>\n" + + "</brightnessThresholdPoint>\n" + + "</brightnessThresholdPoints>\n" + + "</brighteningThresholds>\n" + + "<darkeningThresholds>\n" + + "<minimum>40</minimum>\n" + + "<brightnessThresholdPoints>\n" + + "<brightnessThresholdPoint>\n" + + "<threshold>0</threshold><percentage>23</percentage>\n" + + "</brightnessThresholdPoint>\n" + + "<brightnessThresholdPoint>\n" + + "<threshold>700</threshold><percentage>24</percentage>\n" + + "</brightnessThresholdPoint>\n" + + "<brightnessThresholdPoint>\n" + + "<threshold>800</threshold><percentage>25</percentage>\n" + + "</brightnessThresholdPoint>\n" + + "</brightnessThresholdPoints>\n" + + "</darkeningThresholds>\n" + + "</ambientBrightnessChangeThresholdsIdle>\n" + + "<displayBrightnessChangeThresholdsIdle>\n" + + "<brighteningThresholds>\n" + + "<minimum>0.2</minimum>\n" + + "<brightnessThresholdPoints>\n" + + "<brightnessThresholdPoint>\n" + + "<threshold>0</threshold><percentage>17</percentage>\n" + + "</brightnessThresholdPoint>\n" + + "<brightnessThresholdPoint>\n" + + "<threshold>0.12</threshold><percentage>18</percentage>\n" + + "</brightnessThresholdPoint>\n" + + "<brightnessThresholdPoint>\n" + + "<threshold>0.22</threshold><percentage>19</percentage>\n" + + "</brightnessThresholdPoint>\n" + + "</brightnessThresholdPoints>\n" + + "</brighteningThresholds>\n" + + "<darkeningThresholds>\n" + + "<minimum>0.4</minimum>\n" + + "<brightnessThresholdPoints>\n" + + "<brightnessThresholdPoint>\n" + + "<threshold>0</threshold><percentage>19</percentage>\n" + + "</brightnessThresholdPoint>\n" + + "<brightnessThresholdPoint>\n" + + "<threshold>0.13</threshold><percentage>20</percentage>\n" + + "</brightnessThresholdPoint>\n" + + "<brightnessThresholdPoint>\n" + + "<threshold>0.23</threshold><percentage>21</percentage>\n" + + "</brightnessThresholdPoint>\n" + + "</brightnessThresholdPoints>\n" + + "</darkeningThresholds>\n" + + "</displayBrightnessChangeThresholdsIdle>\n" + "<screenBrightnessRampFastDecrease>0.01</screenBrightnessRampFastDecrease> " + "<screenBrightnessRampFastIncrease>0.02</screenBrightnessRampFastIncrease> " + "<screenBrightnessRampSlowDecrease>0.03</screenBrightnessRampSlowDecrease>" @@ -171,18 +390,6 @@ public final class DisplayDeviceConfigTest { + "</screenBrightnessRampDecreaseMaxMillis>" + "<ambientLightHorizonLong>5000</ambientLightHorizonLong>\n" + "<ambientLightHorizonShort>50</ambientLightHorizonShort>\n" - + "<displayBrightnessChangeThresholds>" - + "<brighteningThresholds>" - + "<minimum>" - + "0.001" - + "</minimum>" - + "</brighteningThresholds>" - + "<darkeningThresholds>" - + "<minimum>" - + "0.002" - + "</minimum>" - + "</darkeningThresholds>" - + "</displayBrightnessChangeThresholds>" + "<screenBrightnessRampIncreaseMaxMillis>" + "2000" + "</screenBrightnessRampIncreaseMaxMillis>\n" @@ -241,8 +448,24 @@ public final class DisplayDeviceConfigTest { com.android.internal.R.array.config_autoBrightnessLevels)) .thenReturn(screenBrightnessLevelLux); - mDisplayDeviceConfig = DisplayDeviceConfig.create(mContext, true); + // Thresholds + // Config.xml requires the levels arrays to be of length N and the thresholds arrays to be + // of length N+1 + when(mResources.getIntArray(com.android.internal.R.array.config_ambientThresholdLevels)) + .thenReturn(new int[]{30, 31}); + when(mResources.getIntArray(com.android.internal.R.array.config_screenThresholdLevels)) + .thenReturn(new int[]{42, 43}); + when(mResources.getIntArray( + com.android.internal.R.array.config_ambientBrighteningThresholds)) + .thenReturn(new int[]{270, 280, 290}); + when(mResources.getIntArray(com.android.internal.R.array.config_ambientDarkeningThresholds)) + .thenReturn(new int[]{290, 300, 310}); + when(mResources.getIntArray(R.array.config_screenBrighteningThresholds)) + .thenReturn(new int[]{350, 360, 370}); + when(mResources.getIntArray(R.array.config_screenDarkeningThresholds)) + .thenReturn(new int[]{370, 380, 390}); + mDisplayDeviceConfig = DisplayDeviceConfig.create(mContext, true); } private TypedArray createFloatTypedArray(float[] vals) { |