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

Commit 088bfc8d authored by Chia-I Wu's avatar Chia-I Wu Committed by Android (Google) Code Review
Browse files

Merge "Fix night light and COLOR_MODE_AUTOMATIC" into pi-dev

parents 065df1d7 9ec9ea72
Loading
Loading
Loading
Loading
+7 −8
Original line number Diff line number Diff line
@@ -189,7 +189,7 @@ public final class ColorDisplayService extends SystemService
        mController = new ColorDisplayController(getContext(), mCurrentUser);
        mController.setListener(this);

        setCoefficientMatrix(getContext(), DisplayTransformManager.isNativeModeEnabled());
        setCoefficientMatrix(getContext(), DisplayTransformManager.needsLinearColorMatrix());

        // Prepare color transformation matrix.
        setMatrix(mController.getColorTemperature(), mMatrixNight);
@@ -293,7 +293,7 @@ public final class ColorDisplayService extends SystemService
            mColorMatrixAnimator.cancel();
        }

        setCoefficientMatrix(getContext(), DisplayTransformManager.isColorModeNative(mode));
        setCoefficientMatrix(getContext(), DisplayTransformManager.needsLinearColorMatrix(mode));
        setMatrix(mController.getColorTemperature(), mMatrixNight);

        final DisplayTransformManager dtm = getLocalService(DisplayTransformManager.class);
@@ -306,13 +306,12 @@ public final class ColorDisplayService extends SystemService
    }

    /**
     * Set coefficients based on native mode. Use DisplayTransformManager#isNativeModeEnabled while
     * setting is stable; when setting is changing, pass native mode selection directly.
     * Set coefficients based on whether the color matrix is linear or not.
     */
    private void setCoefficientMatrix(Context context, boolean isNative) {
        final String[] coefficients = context.getResources().getStringArray(isNative
                ? R.array.config_nightDisplayColorTemperatureCoefficientsNative
                : R.array.config_nightDisplayColorTemperatureCoefficients);
    private void setCoefficientMatrix(Context context, boolean needsLinear) {
        final String[] coefficients = context.getResources().getStringArray(needsLinear
                ? R.array.config_nightDisplayColorTemperatureCoefficients
                : R.array.config_nightDisplayColorTemperatureCoefficientsNative);
        for (int i = 0; i < 9 && i < coefficients.length; i++) {
            mColorTempCoefficients[i] = Float.parseFloat(coefficients[i]);
        }
+7 −9
Original line number Diff line number Diff line
@@ -231,21 +231,19 @@ public class DisplayTransformManager {
    }

    /**
     * Return true when colors are stretched from the working color space to the
     * native color space.
     * Return true when the color matrix works in linear space.
     */
    public static boolean isNativeModeEnabled() {
    public static boolean needsLinearColorMatrix() {
        return SystemProperties.getInt(PERSISTENT_PROPERTY_DISPLAY_COLOR,
                DISPLAY_COLOR_MANAGED) != DISPLAY_COLOR_MANAGED;
                DISPLAY_COLOR_UNMANAGED) != DISPLAY_COLOR_UNMANAGED;
    }

    /**
     * Return true when the specified colorMode stretches colors from the
     * working color space to the native color space.
     * Return true when the specified colorMode requires the color matrix to
     * work in linear space.
     */
    public static boolean isColorModeNative(int colorMode) {
        return !(colorMode == ColorDisplayController.COLOR_MODE_NATURAL ||
                 colorMode == ColorDisplayController.COLOR_MODE_BOOSTED);
    public static boolean needsLinearColorMatrix(int colorMode) {
        return colorMode != ColorDisplayController.COLOR_MODE_SATURATED;
    }

    public boolean setColorMode(int colorMode, float[] nightDisplayMatrix) {