Merge "Clean-up brightness configuration."
This commit is contained in:
committed by
Android (Google) Code Review
commit
d93d206cfe
@@ -222,8 +222,6 @@ public abstract class BrightnessMappingStrategy {
|
||||
|
||||
@Override
|
||||
public boolean setBrightnessConfiguration(@Nullable BrightnessConfiguration config) {
|
||||
Slog.e(TAG,
|
||||
"setBrightnessConfiguration called on device without display information.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -260,13 +260,6 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
|
||||
private long mScreenOnBlockStartRealTime;
|
||||
private long mScreenOffBlockStartRealTime;
|
||||
|
||||
// The last brightness that was set by the user and not temporary. Set to -1 when a brightness
|
||||
// has yet to be recorded.
|
||||
private int mLastBrightness;
|
||||
// The last auto brightness adjustment that was set by the user and not temporary. Set to
|
||||
// Float.NaN when an auto-brightness adjustment hasn't been recorded yet.
|
||||
private float mLastAutoBrightnessAdjustment;
|
||||
|
||||
// Screen state we reported to policy. Must be one of REPORTED_TO_POLICY_SCREEN_* fields.
|
||||
private int mReportedScreenStateToPolicy;
|
||||
|
||||
@@ -299,14 +292,18 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
|
||||
@Nullable
|
||||
private BrightnessMappingStrategy mBrightnessMapper;
|
||||
|
||||
// The default brightness configuration. Used for whenever we don't have a valid brightness
|
||||
// configuration set. This is typically seen with users that don't have a brightness
|
||||
// configuration that's different from the default.
|
||||
private BrightnessConfiguration mDefaultBrightnessConfiguration;
|
||||
|
||||
// The current brightness configuration.
|
||||
@Nullable
|
||||
private BrightnessConfiguration mBrightnessConfiguration;
|
||||
|
||||
// The last brightness that was set by the user and not temporary. Set to -1 when a brightness
|
||||
// has yet to be recorded.
|
||||
private int mLastBrightness;
|
||||
|
||||
// The last auto brightness adjustment that was set by the user and not temporary. Set to
|
||||
// Float.NaN when an auto-brightness adjustment hasn't been recorded yet.
|
||||
private float mLastAutoBrightnessAdjustment;
|
||||
|
||||
// Animators.
|
||||
private ObjectAnimator mColorFadeOnAnimator;
|
||||
private ObjectAnimator mColorFadeOffAnimator;
|
||||
@@ -1488,8 +1485,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
|
||||
}
|
||||
break;
|
||||
case MSG_CONFIGURE_BRIGHTNESS:
|
||||
BrightnessConfiguration c = (BrightnessConfiguration) msg.obj;
|
||||
mBrightnessConfiguration = c != null ? c : mDefaultBrightnessConfiguration;
|
||||
mBrightnessConfiguration = (BrightnessConfiguration)msg.obj;
|
||||
updatePowerState();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -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 static org.mockito.Mockito.when;
|
||||
|
||||
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,11 +113,40 @@ public class BrightnessMappingStrategyTest {
|
||||
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,
|
||||
@@ -142,10 +173,36 @@ public class BrightnessMappingStrategyTest {
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user