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

Commit c5f0d146 authored by Christine Franks's avatar Christine Franks
Browse files

Validate vendor display color modes

Bug: 128607042
Test: atest FrameworksServicesTests:ColorDisplayServiceTest

Change-Id: I78dca7eeb9d4855007b5616b444b2b715860bed1
parent 73f13178
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -162,6 +162,20 @@ public final class ColorDisplayManager {
     */
    public static final int COLOR_MODE_AUTOMATIC = 3;

    /**
     * Display color mode range reserved for vendor customizations by the RenderIntent definition in
     * hardware/interfaces/graphics/common/1.1/types.hal. These are NOT directly related to (but ARE
     * mutually exclusive with) the {@link ColorMode} constants, but ARE directly related (and ARE
     * mutually exclusive with) the DISPLAY_COLOR_* constants in DisplayTransformManager.
     *
     * @hide
     */
    public static final int VENDOR_COLOR_MODE_RANGE_MIN = 256; // 0x100
    /**
     * @hide
     */
    public static final int VENDOR_COLOR_MODE_RANGE_MAX = 511; // 0x1ff

    private final ColorDisplayManagerInternal mManager;
    private MetricsLogger mMetricsLogger;

+19 −4
Original line number Diff line number Diff line
@@ -3455,10 +3455,25 @@ public final class Settings {
         */
        public static final String DISPLAY_COLOR_MODE = "display_color_mode";
        private static final Validator DISPLAY_COLOR_MODE_VALIDATOR =
                new SettingsValidators.InclusiveIntegerRangeValidator(
                        ColorDisplayManager.COLOR_MODE_NATURAL,
                        ColorDisplayManager.COLOR_MODE_AUTOMATIC);
        private static final Validator DISPLAY_COLOR_MODE_VALIDATOR = new Validator() {
            @Override
            public boolean validate(@Nullable String value) {
                // Assume the actual validation that this device can properly handle this kind of
                // color mode further down in ColorDisplayManager / ColorDisplayService.
                try {
                    final int setting = Integer.parseInt(value);
                    final boolean isInFrameworkRange =
                            setting >= ColorDisplayManager.COLOR_MODE_NATURAL
                                    && setting <= ColorDisplayManager.COLOR_MODE_AUTOMATIC;
                    final boolean isInVendorRange =
                            setting >= ColorDisplayManager.VENDOR_COLOR_MODE_RANGE_MIN
                                    && setting <= ColorDisplayManager.VENDOR_COLOR_MODE_RANGE_MAX;
                    return isInFrameworkRange || isInVendorRange;
                } catch (NumberFormatException | NullPointerException e) {
                    return false;
                }
            }
        };
        /**
         * The user selected peak refresh rate in frames per second.
+2 −7
Original line number Diff line number Diff line
@@ -89,12 +89,6 @@ public class DisplayTransformManager {
    private static final int DISPLAY_COLOR_MANAGED = 0;
    private static final int DISPLAY_COLOR_UNMANAGED = 1;
    private static final int DISPLAY_COLOR_ENHANCED = 2;
    /**
     * Display color mode range reserved for vendor customizations by the RenderIntent definition in
     * hardware/interfaces/graphics/common/1.1/types.hal.
     */
    private static final int VENDOR_MODE_RANGE_MIN = 256; // 0x100
    private static final int VENDOR_MODE_RANGE_MAX = 511; // 0x1ff

    /**
     * Map of level -> color transformation matrix.
@@ -270,7 +264,8 @@ public class DisplayTransformManager {
        } else if (colorMode == ColorDisplayManager.COLOR_MODE_AUTOMATIC) {
            applySaturation(COLOR_SATURATION_NATURAL);
            setDisplayColor(DISPLAY_COLOR_ENHANCED);
        } else if (colorMode >= VENDOR_MODE_RANGE_MIN && colorMode <= VENDOR_MODE_RANGE_MAX) {
        } else if (colorMode >= ColorDisplayManager.VENDOR_COLOR_MODE_RANGE_MIN
                && colorMode <= ColorDisplayManager.VENDOR_COLOR_MODE_RANGE_MAX) {
            applySaturation(COLOR_SATURATION_NATURAL);
            setDisplayColor(colorMode);
        }