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

Commit c51b3b73 authored by Christine Franks's avatar Christine Franks Committed by Android (Google) Code Review
Browse files

Merge "Add stronger DWB when docked and idle"

parents a2128eea aeacb569
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1014,6 +1014,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                mAutomaticBrightnessController.switchToInteractiveScreenBrightnessMode();
            }
        }
        if (mDisplayWhiteBalanceController != null) {
            mDisplayWhiteBalanceController.setStrongModeEnabled(isIdle);
        }
    }

    private final Animator.AnimatorListener mAnimatorListener = new Animator.AnimatorListener() {
+72 −34
Original line number Diff line number Diff line
@@ -44,26 +44,18 @@ public class DisplayWhiteBalanceController implements
        AmbientSensor.AmbientBrightnessSensor.Callbacks,
        AmbientSensor.AmbientColorTemperatureSensor.Callbacks {

    protected static final String TAG = "DisplayWhiteBalanceController";
    protected boolean mLoggingEnabled;
    private static final String TAG = "DisplayWhiteBalanceController";
    private boolean mLoggingEnabled;

    private boolean mEnabled;

    // To decouple the DisplayPowerController from the DisplayWhiteBalanceController, the DPC
    // implements Callbacks and passes itself to the DWBC so it can call back into it without
    // knowing about it.
    private Callbacks mCallbacks;

    private AmbientSensor.AmbientBrightnessSensor mBrightnessSensor;
    private final ColorDisplayServiceInternal mColorDisplayServiceInternal;

    private final AmbientSensor.AmbientBrightnessSensor mBrightnessSensor;
    @VisibleForTesting
    AmbientFilter mBrightnessFilter;
    private AmbientSensor.AmbientColorTemperatureSensor mColorTemperatureSensor;

    private final AmbientSensor.AmbientColorTemperatureSensor mColorTemperatureSensor;
    @VisibleForTesting
    AmbientFilter mColorTemperatureFilter;
    private DisplayWhiteBalanceThrottler mThrottler;

    private final DisplayWhiteBalanceThrottler mThrottler;
    // In low brightness conditions the ALS readings are more noisy and produce
    // high errors. This default is introduced to provide a fixed display color
    // temperature when sensor readings become unreliable.
@@ -74,16 +66,12 @@ public class DisplayWhiteBalanceController implements
    private final float mHighLightAmbientColorTemperature;

    private float mAmbientColorTemperature;

    @VisibleForTesting
    float mPendingAmbientColorTemperature;
    private float mLastAmbientColorTemperature;

    private ColorDisplayServiceInternal mColorDisplayServiceInternal;

    // The most recent ambient color temperature values are kept for debugging purposes.
    private static final int HISTORY_SIZE = 50;
    private History mAmbientColorTemperatureHistory;
    private final History mAmbientColorTemperatureHistory;

    // Override the ambient color temperature for debugging purposes.
    private float mAmbientColorTemperatureOverride;
@@ -91,6 +79,10 @@ public class DisplayWhiteBalanceController implements
    // A piecewise linear relationship between ambient and display color temperatures.
    private Spline.LinearSpline mAmbientToDisplayColorTemperatureSpline;

    // A piecewise linear relationship between ambient and display color temperatures, with a
    // stronger change between the two sets of values.
    private Spline.LinearSpline mStrongAmbientToDisplayColorTemperatureSpline;

    // In very low or very high brightness conditions Display White Balance should
    // be to set to a default instead of using mAmbientToDisplayColorTemperatureSpline.
    // However, setting Display White Balance based on thresholds can cause the
@@ -109,6 +101,17 @@ public class DisplayWhiteBalanceController implements
    private float mLatestLowLightBias;
    private float mLatestHighLightBias;

    private boolean mEnabled;

    // Whether a higher-strength adjustment should be applied; this must be enabled in addition to
    // mEnabled in order to be applied.
    private boolean mStrongModeEnabled;

    // To decouple the DisplayPowerController from the DisplayWhiteBalanceController, the DPC
    // implements Callbacks and passes itself to the DWBC so it can call back into it without
    // knowing about it.
    private Callbacks mDisplayPowerControllerCallbacks;

    /**
     * @param brightnessSensor
     *      The sensor used to detect changes in the ambient brightness.
@@ -159,16 +162,18 @@ public class DisplayWhiteBalanceController implements
            @NonNull AmbientSensor.AmbientColorTemperatureSensor colorTemperatureSensor,
            @NonNull AmbientFilter colorTemperatureFilter,
            @NonNull DisplayWhiteBalanceThrottler throttler,
            float[] lowLightAmbientBrightnesses, float[] lowLightAmbientBiases,
            float[] lowLightAmbientBrightnesses,
            float[] lowLightAmbientBiases,
            float lowLightAmbientColorTemperature,
            float[] highLightAmbientBrightnesses, float[] highLightAmbientBiases,
            float[] highLightAmbientBrightnesses,
            float[] highLightAmbientBiases,
            float highLightAmbientColorTemperature,
            float[] ambientColorTemperatures, float[] displayColorTemperatures) {
            float[] ambientColorTemperatures,
            float[] displayColorTemperatures,
            float[] strongAmbientColorTemperatures,
            float[] strongDisplayColorTemperatures) {
        validateArguments(brightnessSensor, brightnessFilter, colorTemperatureSensor,
                colorTemperatureFilter, throttler);
        mLoggingEnabled = false;
        mEnabled = false;
        mCallbacks = null;
        mBrightnessSensor = brightnessSensor;
        mBrightnessFilter = brightnessFilter;
        mColorTemperatureSensor = colorTemperatureSensor;
@@ -179,7 +184,7 @@ public class DisplayWhiteBalanceController implements
        mAmbientColorTemperature = -1.0f;
        mPendingAmbientColorTemperature = -1.0f;
        mLastAmbientColorTemperature = -1.0f;
        mAmbientColorTemperatureHistory = new History(HISTORY_SIZE);
        mAmbientColorTemperatureHistory = new History(/* size= */ 50);
        mAmbientColorTemperatureOverride = -1.0f;

        try {
@@ -235,6 +240,13 @@ public class DisplayWhiteBalanceController implements
            mAmbientToDisplayColorTemperatureSpline = null;
        }

        try {
            mStrongAmbientToDisplayColorTemperatureSpline = new Spline.LinearSpline(
                    strongAmbientColorTemperatures, strongDisplayColorTemperatures);
        } catch (Exception e) {
            Slog.e(TAG, "Failed to create strong ambient to display color temperature spline", e);
        }

        mColorDisplayServiceInternal = LocalServices.getService(ColorDisplayServiceInternal.class);
    }

@@ -254,6 +266,19 @@ public class DisplayWhiteBalanceController implements
        }
    }

    /**
     * Enable/disable the stronger adjustment option.
     *
     * @param enabled whether the stronger adjustment option should be turned on
     */
    public void setStrongModeEnabled(boolean enabled) {
        mStrongModeEnabled = enabled;
        if (mEnabled) {
            updateAmbientColorTemperature();
            updateDisplayColorTemperature();
        }
    }

    /**
     * Set an object to call back to when the display color temperature should be updated.
     *
@@ -263,10 +288,10 @@ public class DisplayWhiteBalanceController implements
     * @return Whether the method succeeded or not.
     */
    public boolean setCallbacks(Callbacks callbacks) {
        if (mCallbacks == callbacks) {
        if (mDisplayPowerControllerCallbacks == callbacks) {
            return false;
        }
        mCallbacks = callbacks;
        mDisplayPowerControllerCallbacks = callbacks;
        return true;
    }

@@ -321,7 +346,7 @@ public class DisplayWhiteBalanceController implements
        writer.println("DisplayWhiteBalanceController");
        writer.println("  mLoggingEnabled=" + mLoggingEnabled);
        writer.println("  mEnabled=" + mEnabled);
        writer.println("  mCallbacks=" + mCallbacks);
        writer.println("  mDisplayPowerControllerCallbacks=" + mDisplayPowerControllerCallbacks);
        mBrightnessSensor.dump(writer);
        mBrightnessFilter.dump(writer);
        mColorTemperatureSensor.dump(writer);
@@ -336,6 +361,8 @@ public class DisplayWhiteBalanceController implements
        writer.println("  mAmbientColorTemperatureOverride=" + mAmbientColorTemperatureOverride);
        writer.println("  mAmbientToDisplayColorTemperatureSpline="
                + mAmbientToDisplayColorTemperatureSpline);
        writer.println("  mStrongAmbientToDisplayColorTemperatureSpline="
                + mStrongAmbientToDisplayColorTemperatureSpline);
        writer.println("  mLowLightAmbientBrightnessToBiasSpline="
                + mLowLightAmbientBrightnessToBiasSpline);
        writer.println("  mHighLightAmbientBrightnessToBiasSpline="
@@ -364,9 +391,20 @@ public class DisplayWhiteBalanceController implements
        float ambientColorTemperature = mColorTemperatureFilter.getEstimate(time);
        mLatestAmbientColorTemperature = ambientColorTemperature;

        if (mAmbientToDisplayColorTemperatureSpline != null && ambientColorTemperature != -1.0f) {
        if (mStrongModeEnabled) {
            if (mStrongAmbientToDisplayColorTemperatureSpline != null
                    && ambientColorTemperature != -1.0f) {
                ambientColorTemperature =
                mAmbientToDisplayColorTemperatureSpline.interpolate(ambientColorTemperature);
                        mStrongAmbientToDisplayColorTemperatureSpline.interpolate(
                                ambientColorTemperature);
            }
        } else {
            if (mAmbientToDisplayColorTemperatureSpline != null
                    && ambientColorTemperature != -1.0f) {
                ambientColorTemperature =
                        mAmbientToDisplayColorTemperatureSpline.interpolate(
                                ambientColorTemperature);
            }
        }

        float ambientBrightness = mBrightnessFilter.getEstimate(time);
@@ -409,8 +447,8 @@ public class DisplayWhiteBalanceController implements
            Slog.d(TAG, "pending ambient color temperature: " + ambientColorTemperature);
        }
        mPendingAmbientColorTemperature = ambientColorTemperature;
        if (mCallbacks != null) {
            mCallbacks.updateWhiteBalance();
        if (mDisplayPowerControllerCallbacks != null) {
            mDisplayPowerControllerCallbacks.updateWhiteBalance();
        }
    }

+9 −2
Original line number Diff line number Diff line
@@ -87,15 +87,22 @@ public class DisplayWhiteBalanceFactory {
                .config_displayWhiteBalanceHighLightAmbientColorTemperature);
        final float[] ambientColorTemperatures = getFloatArray(resources,
                com.android.internal.R.array.config_displayWhiteBalanceAmbientColorTemperatures);
        final float[] displayColorTempeartures = getFloatArray(resources,
        final float[] displayColorTemperatures = getFloatArray(resources,
                com.android.internal.R.array.config_displayWhiteBalanceDisplayColorTemperatures);
        final float[] strongAmbientColorTemperatures = getFloatArray(resources,
                com.android.internal.R.array
                .config_displayWhiteBalanceStrongAmbientColorTemperatures);
        final float[] strongDisplayColorTemperatures = getFloatArray(resources,
                com.android.internal.R.array
                .config_displayWhiteBalanceStrongDisplayColorTemperatures);
        final DisplayWhiteBalanceController controller = new DisplayWhiteBalanceController(
                brightnessSensor, brightnessFilter, colorTemperatureSensor, colorTemperatureFilter,
                throttler, displayWhiteBalanceLowLightAmbientBrightnesses,
                displayWhiteBalanceLowLightAmbientBiases, lowLightAmbientColorTemperature,
                displayWhiteBalanceHighLightAmbientBrightnesses,
                displayWhiteBalanceHighLightAmbientBiases, highLightAmbientColorTemperature,
                ambientColorTemperatures, displayColorTempeartures);
                ambientColorTemperatures, displayColorTemperatures, strongAmbientColorTemperatures,
                strongDisplayColorTemperatures);
        brightnessSensor.setCallbacks(controller);
        colorTemperatureSensor.setCallbacks(controller);
        return controller;
+55 −0
Original line number Diff line number Diff line
@@ -59,6 +59,8 @@ import java.util.List;

@RunWith(JUnit4.class)
public final class AmbientLuxTest {

    private static final float ALLOWED_ERROR_DELTA = 0.001f;
    private static final int AMBIENT_COLOR_TYPE = 20705;
    private static final String AMBIENT_COLOR_TYPE_STR = "colorSensoryDensoryDoc";
    private static final float LOW_LIGHT_AMBIENT_COLOR_TEMPERATURE = 5432.1f;
@@ -78,6 +80,8 @@ public final class AmbientLuxTest {
    @Mock private TypedArray mHighLightBiases;
    @Mock private TypedArray mAmbientColorTemperatures;
    @Mock private TypedArray mDisplayColorTemperatures;
    @Mock private TypedArray mStrongAmbientColorTemperatures;
    @Mock private TypedArray mStrongDisplayColorTemperatures;
    @Mock private ColorDisplayService.ColorDisplayServiceInternal mColorDisplayServiceInternalMock;

    @Before
@@ -110,6 +114,12 @@ public final class AmbientLuxTest {
        when(mResourcesSpy.obtainTypedArray(
                R.array.config_displayWhiteBalanceDisplayColorTemperatures))
                .thenReturn(mDisplayColorTemperatures);
        when(mResourcesSpy.obtainTypedArray(
                R.array.config_displayWhiteBalanceStrongAmbientColorTemperatures))
                .thenReturn(mStrongAmbientColorTemperatures);
        when(mResourcesSpy.obtainTypedArray(
                R.array.config_displayWhiteBalanceStrongDisplayColorTemperatures))
                .thenReturn(mStrongDisplayColorTemperatures);

        when(mResourcesSpy.obtainTypedArray(
                R.array.config_displayWhiteBalanceLowLightAmbientBrightnesses))
@@ -374,6 +384,43 @@ public final class AmbientLuxTest {
            }
    }

    @Test
    public void testStrongMode() {
        final float lowerBrightness = 10.0f;
        final float upperBrightness = 50.0f;
        setBrightnesses(lowerBrightness, upperBrightness);
        setBiases(0.0f, 1.0f);
        final int ambientColorTempLow = 6000;
        final int ambientColorTempHigh = 8000;
        final int displayColorTempLow = 6400;
        final int displayColorTempHigh = 7400;
        setStrongAmbientColorTemperatures(ambientColorTempLow, ambientColorTempHigh);
        setStrongDisplayColorTemperatures(displayColorTempLow, displayColorTempHigh);

        DisplayWhiteBalanceController controller =
                DisplayWhiteBalanceFactory.create(mHandler, mSensorManagerMock, mResourcesSpy);
        controller.setStrongModeEnabled(true);
        controller.mBrightnessFilter = spy(new AmbientFilterStubber());

        for (float ambientTempFraction = 0.0f; ambientTempFraction <= 1.0f;
                ambientTempFraction += 0.1f) {
            final float ambientTemp =
                    (ambientColorTempHigh - ambientColorTempLow) * ambientTempFraction
                            + ambientColorTempLow;
            setEstimatedColorTemperature(controller, ambientTemp);
            for (float brightnessFraction = 0.0f; brightnessFraction <= 1.0f;
                    brightnessFraction += 0.1f) {
                setEstimatedBrightnessAndUpdate(controller,
                        mix(lowerBrightness, upperBrightness, brightnessFraction));
                assertEquals(controller.mPendingAmbientColorTemperature,
                        mix(LOW_LIGHT_AMBIENT_COLOR_TEMPERATURE,
                                mix(displayColorTempLow, displayColorTempHigh, ambientTempFraction),
                                brightnessFraction),
                        ALLOWED_ERROR_DELTA);
            }
        }
    }

    @Test
    public void testLowLight_DefaultAmbient() throws Exception {
        final float lowerBrightness = 10.0f;
@@ -486,6 +533,14 @@ public final class AmbientLuxTest {
        setFloatArrayResource(mDisplayColorTemperatures, vals);
    }

    private void setStrongAmbientColorTemperatures(float... vals) {
        setFloatArrayResource(mStrongAmbientColorTemperatures, vals);
    }

    private void setStrongDisplayColorTemperatures(float... vals) {
        setFloatArrayResource(mStrongDisplayColorTemperatures, vals);
    }

    private void setFloatArrayResource(TypedArray array, float[] vals) {
        when(array.length()).thenReturn(vals.length);
        for (int i = 0; i < vals.length; i++) {