Merge "Remove 0 param BrightnessConfiguration.Builder constructor"
This commit is contained in:
@@ -140,13 +140,6 @@ public final class BrightnessConfiguration implements Parcelable {
|
||||
private float[] mCurveNits;
|
||||
private String mDescription;
|
||||
|
||||
/**
|
||||
* STOPSHIP remove when app has stopped using this.
|
||||
* @hide
|
||||
*/
|
||||
public Builder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the builder with the control points for the brightness curve.
|
||||
*
|
||||
@@ -159,24 +152,6 @@ public final class BrightnessConfiguration implements Parcelable {
|
||||
* @throws IllegalArgumentException if the nit levels are not monotonically increasing.
|
||||
*/
|
||||
public Builder(float[] lux, float[] nits) {
|
||||
setCurve(lux, nits);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the control points for the brightness curve.
|
||||
*
|
||||
* Brightness curves must have strictly increasing ambient brightness values in lux and
|
||||
* monotonically increasing display brightness values in nits. In addition, the initial
|
||||
* control point must be 0 lux.
|
||||
*
|
||||
* @throws IllegalArgumentException if the initial control point is not at 0 lux.
|
||||
* @throws IllegalArgumentException if the lux levels are not strictly increasing.
|
||||
* @throws IllegalArgumentException if the nit levels are not monotonically increasing.
|
||||
*
|
||||
* STOPSHIP remove when app has stopped using this.
|
||||
* @hide
|
||||
*/
|
||||
public Builder setCurve(float[] lux, float[] nits) {
|
||||
Preconditions.checkNotNull(lux);
|
||||
Preconditions.checkNotNull(nits);
|
||||
if (lux.length == 0 || nits.length == 0) {
|
||||
@@ -190,11 +165,10 @@ public final class BrightnessConfiguration implements Parcelable {
|
||||
}
|
||||
Preconditions.checkArrayElementsInRange(lux, 0, Float.MAX_VALUE, "lux");
|
||||
Preconditions.checkArrayElementsInRange(nits, 0, Float.MAX_VALUE, "nits");
|
||||
checkMonotonic(lux, true/*strictly increasing*/, "lux");
|
||||
checkMonotonic(lux, true /*strictly increasing*/, "lux");
|
||||
checkMonotonic(nits, false /*strictly increasing*/, "nits");
|
||||
mCurveLux = lux;
|
||||
mCurveNits = nits;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -48,8 +48,8 @@ public class BrightnessConfigurationTest {
|
||||
|
||||
@Test
|
||||
public void testSetCurveIsUnmodified() {
|
||||
BrightnessConfiguration.Builder builder = new BrightnessConfiguration.Builder();
|
||||
builder.setCurve(LUX_LEVELS, NITS_LEVELS);
|
||||
BrightnessConfiguration.Builder builder = new BrightnessConfiguration.Builder(
|
||||
LUX_LEVELS, NITS_LEVELS);
|
||||
BrightnessConfiguration config = builder.build();
|
||||
Pair<float[], float[]> curve = config.getCurve();
|
||||
assertArrayEquals(LUX_LEVELS, curve.first, "lux");
|
||||
@@ -58,45 +58,33 @@ public class BrightnessConfigurationTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testCurveMustHaveZeroLuxPoint() {
|
||||
BrightnessConfiguration.Builder builder = new BrightnessConfiguration.Builder();
|
||||
float[] lux = Arrays.copyOf(LUX_LEVELS, LUX_LEVELS.length);
|
||||
lux[0] = 1f;
|
||||
builder.setCurve(lux, NITS_LEVELS);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testCurveMustBeSet() {
|
||||
BrightnessConfiguration.Builder builder = new BrightnessConfiguration.Builder();
|
||||
builder.build();
|
||||
new BrightnessConfiguration.Builder(lux, NITS_LEVELS);
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testCurveMustNotHaveNullArrays() {
|
||||
BrightnessConfiguration.Builder builder = new BrightnessConfiguration.Builder();
|
||||
builder.setCurve(null, null);
|
||||
new BrightnessConfiguration.Builder(null, null);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testCurveMustNotHaveEmptyArrays() {
|
||||
BrightnessConfiguration.Builder builder = new BrightnessConfiguration.Builder();
|
||||
builder.setCurve(new float[0], new float[0]);
|
||||
new BrightnessConfiguration.Builder(new float[0], new float[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCurveMustNotHaveArraysOfDifferentLengths() {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
BrightnessConfiguration.Builder builder = new BrightnessConfiguration.Builder();
|
||||
float[] lux = Arrays.copyOf(LUX_LEVELS, LUX_LEVELS.length + 1);
|
||||
lux[lux.length - 1] = lux[lux.length - 2] + 1;
|
||||
boolean exceptionThrown = false;
|
||||
builder.setCurve(lux, NITS_LEVELS);
|
||||
new BrightnessConfiguration.Builder(lux, NITS_LEVELS);
|
||||
});
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
BrightnessConfiguration.Builder builder = new BrightnessConfiguration.Builder();
|
||||
float[] nits = Arrays.copyOf(NITS_LEVELS, NITS_LEVELS.length + 1);
|
||||
nits[nits.length - 1] = nits[nits.length - 2] + 1;
|
||||
builder.setCurve(LUX_LEVELS, nits);
|
||||
new BrightnessConfiguration.Builder(LUX_LEVELS, nits);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -105,23 +93,21 @@ public class BrightnessConfigurationTest {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
float[] lux = Arrays.copyOf(LUX_LEVELS, LUX_LEVELS.length);
|
||||
lux[lux.length - 1] = Float.NaN;
|
||||
BrightnessConfiguration.Builder builder = new BrightnessConfiguration.Builder();
|
||||
builder.setCurve(lux, NITS_LEVELS);
|
||||
new BrightnessConfiguration.Builder(lux, NITS_LEVELS);
|
||||
});
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
float[] nits = Arrays.copyOf(NITS_LEVELS, NITS_LEVELS.length);
|
||||
nits[nits.length - 1] = Float.NaN;
|
||||
BrightnessConfiguration.Builder builder = new BrightnessConfiguration.Builder();
|
||||
builder.setCurve(LUX_LEVELS, nits);
|
||||
new BrightnessConfiguration.Builder(LUX_LEVELS, nits);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testParceledConfigIsEquivalent() {
|
||||
BrightnessConfiguration.Builder builder = new BrightnessConfiguration.Builder();
|
||||
builder.setCurve(LUX_LEVELS, NITS_LEVELS);
|
||||
BrightnessConfiguration.Builder builder =
|
||||
new BrightnessConfiguration.Builder(LUX_LEVELS, NITS_LEVELS);
|
||||
BrightnessConfiguration config = builder.build();
|
||||
Parcel p = Parcel.obtain();
|
||||
p.writeParcelable(config, 0 /*flags*/);
|
||||
@@ -133,12 +119,11 @@ public class BrightnessConfigurationTest {
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
BrightnessConfiguration.Builder builder = new BrightnessConfiguration.Builder();
|
||||
builder.setCurve(LUX_LEVELS, NITS_LEVELS);
|
||||
BrightnessConfiguration.Builder builder =
|
||||
new BrightnessConfiguration.Builder(LUX_LEVELS, NITS_LEVELS);
|
||||
BrightnessConfiguration baseConfig = builder.build();
|
||||
|
||||
builder = new BrightnessConfiguration.Builder();
|
||||
builder.setCurve(LUX_LEVELS, NITS_LEVELS);
|
||||
builder = new BrightnessConfiguration.Builder(LUX_LEVELS, NITS_LEVELS);
|
||||
BrightnessConfiguration identicalConfig = builder.build();
|
||||
assertEquals(baseConfig, identicalConfig);
|
||||
assertEquals("hashCodes must be equal for identical configs",
|
||||
@@ -146,15 +131,13 @@ public class BrightnessConfigurationTest {
|
||||
|
||||
float[] lux = Arrays.copyOf(LUX_LEVELS, LUX_LEVELS.length);
|
||||
lux[lux.length - 1] = lux[lux.length - 1] * 2;
|
||||
builder = new BrightnessConfiguration.Builder();
|
||||
builder.setCurve(lux, NITS_LEVELS);
|
||||
builder = new BrightnessConfiguration.Builder(lux, NITS_LEVELS);
|
||||
BrightnessConfiguration luxDifferConfig = builder.build();
|
||||
assertNotEquals(baseConfig, luxDifferConfig);
|
||||
|
||||
float[] nits = Arrays.copyOf(NITS_LEVELS, NITS_LEVELS.length);
|
||||
nits[nits.length - 1] = nits[nits.length - 1] * 2;
|
||||
builder = new BrightnessConfiguration.Builder();
|
||||
builder.setCurve(LUX_LEVELS, nits);
|
||||
builder = new BrightnessConfiguration.Builder(LUX_LEVELS, nits);
|
||||
BrightnessConfiguration nitsDifferConfig = builder.build();
|
||||
assertNotEquals(baseConfig, nitsDifferConfig);
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ import android.util.Pair;
|
||||
import android.util.Slog;
|
||||
import android.util.Spline;
|
||||
|
||||
import com.android.internal.util.Preconditions;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.util.Preconditions;
|
||||
import com.android.server.display.utils.Plog;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
@@ -77,8 +77,8 @@ public abstract class BrightnessMappingStrategy {
|
||||
Slog.w(TAG, "Screen brightness mapping does not cover whole range of available " +
|
||||
"backlight values, autobrightness functionality may be impaired.");
|
||||
}
|
||||
BrightnessConfiguration.Builder builder = new BrightnessConfiguration.Builder();
|
||||
builder.setCurve(luxLevels, brightnessLevelsNits);
|
||||
BrightnessConfiguration.Builder builder = new BrightnessConfiguration.Builder(
|
||||
luxLevels, brightnessLevelsNits);
|
||||
return new PhysicalMappingStrategy(builder.build(), nitsRange, backlightRange,
|
||||
autoBrightnessAdjustmentMaxGamma);
|
||||
} else if (isValidMapping(luxLevels, brightnessLevelsBacklight)) {
|
||||
|
||||
@@ -152,8 +152,7 @@ public class BrightnessMappingStrategyTest {
|
||||
final float[] lux = { 0f, 1f };
|
||||
final float[] nits = { 0, PowerManager.BRIGHTNESS_ON };
|
||||
|
||||
BrightnessConfiguration config = new BrightnessConfiguration.Builder()
|
||||
.setCurve(lux, nits)
|
||||
BrightnessConfiguration config = new BrightnessConfiguration.Builder(lux, nits)
|
||||
.build();
|
||||
strategy.setBrightnessConfiguration(config);
|
||||
assertNotEquals(1.0f, strategy.getBrightness(1f), 0.01 /*tolerance*/);
|
||||
@@ -214,8 +213,7 @@ public class BrightnessMappingStrategyTest {
|
||||
DISPLAY_RANGE_NITS[DISPLAY_RANGE_NITS.length - 1]
|
||||
};
|
||||
|
||||
BrightnessConfiguration config = new BrightnessConfiguration.Builder()
|
||||
.setCurve(lux, nits)
|
||||
BrightnessConfiguration config = new BrightnessConfiguration.Builder(lux, nits)
|
||||
.build();
|
||||
strategy.setBrightnessConfiguration(config);
|
||||
assertEquals(1.0f, strategy.getBrightness(1f), 0.01 /*tolerance*/);
|
||||
|
||||
Reference in New Issue
Block a user