Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d93d206c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Clean-up brightness configuration."

parents ab4c1eaa d5df361a
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -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;
        }

+10 −14
Original line number Diff line number Diff line
@@ -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;
            }
+59 −2
Original line number Diff line number Diff line
@@ -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;
@@ -116,6 +118,35 @@ public class BrightnessMappingStrategyTest {
        }
    }

    @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,
@@ -146,6 +177,32 @@ public class BrightnessMappingStrategyTest {
        }
    }

    @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,