Clean-up brightness configuration.
Remove unused default config since that's now stored in the mapping
strategy and eliminate erroneous error logging on devices that don't
support brightness configurations.
Fixes: 71527790
Test: atest com.android.server.display.BrightnessMappingStrategyTest
Change-Id: I9b2eeb5270200af8b59e4374e1afc9fd9447a73f
diff --git a/services/tests/servicestests/src/com/android/server/display/BrightnessMappingStrategyTest.java b/services/tests/servicestests/src/com/android/server/display/BrightnessMappingStrategyTest.java
index 5105f4e..9e7ef65 100644
--- a/services/tests/servicestests/src/com/android/server/display/BrightnessMappingStrategyTest.java
+++ b/services/tests/servicestests/src/com/android/server/display/BrightnessMappingStrategyTest.java
@@ -17,6 +17,7 @@
package com.android.server.display;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -27,6 +28,7 @@
import android.content.res.Resources;
import android.content.res.TypedArray;
+import android.hardware.display.BrightnessConfiguration;
import android.os.PowerManager;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
@@ -111,12 +113,41 @@
final float lux = (LUX_LEVELS[i - 1] + LUX_LEVELS[i]) / 2;
final float backlight = simple.getBrightness(lux) * PowerManager.BRIGHTNESS_ON;
assertTrue("Desired brightness should be between adjacent control points.",
- backlight > DISPLAY_LEVELS_BACKLIGHT[i-1]
+ backlight > DISPLAY_LEVELS_BACKLIGHT[i - 1]
&& backlight < DISPLAY_LEVELS_BACKLIGHT[i]);
}
}
@Test
+ public void testSimpleStrategyIgnoresNewConfiguration() {
+ Resources res = createResources(LUX_LEVELS, DISPLAY_LEVELS_BACKLIGHT);
+ BrightnessMappingStrategy strategy = BrightnessMappingStrategy.create(res);
+
+ final int N = LUX_LEVELS.length;
+ final float[] lux = { 0f, 1f };
+ final float[] nits = { 0, PowerManager.BRIGHTNESS_ON };
+
+ BrightnessConfiguration config = new BrightnessConfiguration.Builder()
+ .setCurve(lux, nits)
+ .build();
+ strategy.setBrightnessConfiguration(config);
+ assertNotEquals(1.0f, strategy.getBrightness(1f), 0.01 /*tolerance*/);
+ }
+
+ @Test
+ public void testSimpleStrategyIgnoresNullConfiguration() {
+ Resources res = createResources(LUX_LEVELS, DISPLAY_LEVELS_BACKLIGHT);
+ BrightnessMappingStrategy strategy = BrightnessMappingStrategy.create(res);
+
+ strategy.setBrightnessConfiguration(null);
+ final int N = DISPLAY_LEVELS_BACKLIGHT.length;
+ final float expectedBrightness =
+ (float) DISPLAY_LEVELS_BACKLIGHT[N - 1] / PowerManager.BRIGHTNESS_ON;
+ assertEquals(expectedBrightness,
+ strategy.getBrightness(LUX_LEVELS[N - 1]), 0.01 /*tolerance*/);
+ }
+
+ @Test
public void testPhysicalStrategyMappingAtControlPoints() {
Resources res = createResources(LUX_LEVELS, DISPLAY_LEVELS_NITS,
DISPLAY_RANGE_NITS, BACKLIGHT_RANGE);
@@ -142,11 +173,37 @@
final float backlight = physical.getBrightness(lux) * PowerManager.BRIGHTNESS_ON;
final float nits = backlightToBrightness.interpolate(backlight);
assertTrue("Desired brightness should be between adjacent control points.",
- nits > DISPLAY_LEVELS_NITS[i-1] && nits < DISPLAY_LEVELS_NITS[i]);
+ nits > DISPLAY_LEVELS_NITS[i - 1] && nits < DISPLAY_LEVELS_NITS[i]);
}
}
@Test
+ public void testPhysicalStrategyUsesNewConfigurations() {
+ Resources res = createResources(LUX_LEVELS, DISPLAY_LEVELS_NITS,
+ DISPLAY_RANGE_NITS, BACKLIGHT_RANGE);
+ BrightnessMappingStrategy strategy = BrightnessMappingStrategy.create(res);
+
+ final float[] lux = { 0f, 1f };
+ final float[] nits = {
+ DISPLAY_RANGE_NITS[0],
+ DISPLAY_RANGE_NITS[DISPLAY_RANGE_NITS.length - 1]
+ };
+
+ BrightnessConfiguration config = new BrightnessConfiguration.Builder()
+ .setCurve(lux, nits)
+ .build();
+ strategy.setBrightnessConfiguration(config);
+ assertEquals(1.0f, strategy.getBrightness(1f), 0.01 /*tolerance*/);
+
+ // Check that null returns us to the default configuration.
+ strategy.setBrightnessConfiguration(null);
+ final int N = DISPLAY_LEVELS_NITS.length;
+ final float expectedBrightness = DISPLAY_LEVELS_NITS[N - 1] / DISPLAY_RANGE_NITS[1];
+ assertEquals(expectedBrightness,
+ strategy.getBrightness(LUX_LEVELS[N - 1]), 0.01f /*tolerance*/);
+ }
+
+ @Test
public void testDefaultStrategyIsPhysical() {
Resources res = createResources(LUX_LEVELS, DISPLAY_LEVELS_BACKLIGHT,
DISPLAY_LEVELS_NITS, DISPLAY_RANGE_NITS, BACKLIGHT_RANGE);