diff options
author | Rupesh Bansal <brup@google.com> | 2022-10-19 16:10:14 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2022-10-19 16:10:14 +0000 |
commit | fdc5610e4ba69f5b80ee37eb936e744036693432 (patch) | |
tree | a085f71e0adb01af2a55e409c02de40f6e37771b | |
parent | 270337f9610b357e6282e4aadb440161b1ab10ed (diff) | |
parent | 54a69e7a3b3268bbe50bd12ede542ab42ac4d8fe (diff) | |
download | base-fdc5610e4ba69f5b80ee37eb936e744036693432.tar.gz |
Merge "Making the config_screenThresholdLevels a float array to fix the issue where it was always greater than all possible brightness values"
3 files changed, 62 insertions, 5 deletions
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 6f83ab169b5f..689620c13918 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -1649,6 +1649,11 @@ darkening hysteresis constraint value is the n-th element of config_screenDarkeningThresholds. + Historically, it has been assumed that this will be an integer array with values in the + range of [0, 255]. However, it is now assumed to be a float array with values in the + range of [0, 1]. To accommodate both the possibilities, we internally check the scale on + which the thresholds are defined, and calibrate it accordingly. + The (zero-based) index is calculated as follows: (MAX is the largest index of the array) condition calculated index value < level[0] 0 diff --git a/services/core/java/com/android/server/display/DisplayPowerController.java b/services/core/java/com/android/server/display/DisplayPowerController.java index 070acd0b6183..1514750aff66 100644 --- a/services/core/java/com/android/server/display/DisplayPowerController.java +++ b/services/core/java/com/android/server/display/DisplayPowerController.java @@ -975,8 +975,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call com.android.internal.R.array.config_screenBrighteningThresholds); int[] screenDarkeningThresholds = resources.getIntArray( com.android.internal.R.array.config_screenDarkeningThresholds); - int[] screenThresholdLevels = resources.getIntArray( - com.android.internal.R.array.config_screenThresholdLevels); + float[] screenThresholdLevels = BrightnessMappingStrategy.getFloatArray(resources + .obtainTypedArray(com.android.internal.R.array.config_screenThresholdLevels)); float screenDarkeningMinThreshold = mDisplayDeviceConfig.getScreenDarkeningMinThreshold(); float screenBrighteningMinThreshold = diff --git a/services/core/java/com/android/server/display/HysteresisLevels.java b/services/core/java/com/android/server/display/HysteresisLevels.java index 7a932ce6d7cf..232495ed3640 100644 --- a/services/core/java/com/android/server/display/HysteresisLevels.java +++ b/services/core/java/com/android/server/display/HysteresisLevels.java @@ -39,8 +39,7 @@ public class HysteresisLevels { private final float mMinBrightening; /** - * Creates a {@code HysteresisLevels} object with the given equal-length - * integer arrays. + * 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. @@ -62,6 +61,28 @@ public class HysteresisLevels { } /** + * 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. + * @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) { + throw new IllegalArgumentException("Mismatch between hysteresis array lengths."); + } + mBrighteningThresholds = setArrayFormat(brighteningThresholds, 1000.0f); + mDarkeningThresholds = setArrayFormat(darkeningThresholds, 1000.0f); + mThresholdLevels = constraintInRangeIfNeeded(thresholdLevels); + mMinDarkening = minDarkeningThreshold; + mMinBrightening = minBrighteningThreshold; + } + + /** * Return the brightening hysteresis threshold for the given value level. */ public float getBrighteningThreshold(float value) { @@ -107,11 +128,42 @@ public class HysteresisLevels { private float[] setArrayFormat(int[] 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] = (float) 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)); |