Making the config_screenThresholdLevels a float array to fix the

issue where it was always greater than all possible brightness values

config_screenThresholdLevels is an integer array, which is internally compared with brightness in [0.0f,1.0f] to get the right index on which the brightening and darkening thresholds are to be applied. This means no matter what we have in the array, it will always be the first index that will win, and we will always apply the first brightening and darkening thresholds. To keep the settings backward compatible, we still accept the integer array for this threshold, and divide those thresholds with the scale range(255).

Bug: 245746705
Test: Manual
Test: adb shell dumpsys display | grep HysteresisLevels -A 5
Change-Id: I177d7a1aa48bdfb3385780f0eee7af689755efb4
This commit is contained in:
Rupesh Bansal
2022-09-12 10:27:44 +00:00
parent 9a54da6d23
commit 8d81aca23a
3 changed files with 64 additions and 7 deletions

View File

@@ -1662,13 +1662,18 @@
darkening hysteresis constraint value is the n-th element of darkening hysteresis constraint value is the n-th element of
config_screenDarkeningThresholds. 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) The (zero-based) index is calculated as follows: (MAX is the largest index of the array)
condition calculated index condition calculated index
value < level[0] 0 value < level[0] 0
level[n] <= value < level[n+1] n+1 level[n] <= value < level[n+1] n+1
level[MAX] <= value MAX+1 --> level[MAX] <= value MAX+1 -->
<integer-array name="config_screenThresholdLevels"> <array name="config_screenThresholdLevels">
</integer-array> </array>
<!-- Array of hysteresis constraint values for brightening, represented as tenths of a <!-- Array of hysteresis constraint values for brightening, represented as tenths of a
percent. The length of this array is assumed to be one greater than percent. The length of this array is assumed to be one greater than

View File

@@ -975,8 +975,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
com.android.internal.R.array.config_screenBrighteningThresholds); com.android.internal.R.array.config_screenBrighteningThresholds);
int[] screenDarkeningThresholds = resources.getIntArray( int[] screenDarkeningThresholds = resources.getIntArray(
com.android.internal.R.array.config_screenDarkeningThresholds); com.android.internal.R.array.config_screenDarkeningThresholds);
int[] screenThresholdLevels = resources.getIntArray( float[] screenThresholdLevels = BrightnessMappingStrategy.getFloatArray(resources
com.android.internal.R.array.config_screenThresholdLevels); .obtainTypedArray(com.android.internal.R.array.config_screenThresholdLevels));
float screenDarkeningMinThreshold = float screenDarkeningMinThreshold =
mDisplayDeviceConfig.getScreenDarkeningMinThreshold(); mDisplayDeviceConfig.getScreenDarkeningMinThreshold();
float screenBrighteningMinThreshold = float screenBrighteningMinThreshold =

View File

@@ -36,8 +36,7 @@ public class HysteresisLevels {
private final float mMinBrightening; private final float mMinBrightening;
/** /**
* Creates a {@code HysteresisLevels} object with the given equal-length * Creates a {@code HysteresisLevels} object for ambient brightness.
* integer arrays.
* @param brighteningThresholds an array of brightening hysteresis constraint constants. * @param brighteningThresholds an array of brightening hysteresis constraint constants.
* @param darkeningThresholds an array of darkening hysteresis constraint constants. * @param darkeningThresholds an array of darkening hysteresis constraint constants.
* @param thresholdLevels a monotonically increasing array of threshold levels. * @param thresholdLevels a monotonically increasing array of threshold levels.
@@ -58,6 +57,28 @@ public class HysteresisLevels {
mMinBrightening = minBrighteningThreshold; 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.
* @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. * Return the brightening hysteresis threshold for the given value level.
*/ */
@@ -109,6 +130,37 @@ public class HysteresisLevels {
return levelArray; 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) { void dump(PrintWriter pw) {
pw.println("HysteresisLevels"); pw.println("HysteresisLevels");
pw.println(" mBrighteningThresholds=" + Arrays.toString(mBrighteningThresholds)); pw.println(" mBrighteningThresholds=" + Arrays.toString(mBrighteningThresholds));