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

Commit 037b13c9 authored by Marc Kassis's avatar Marc Kassis Committed by Android (Google) Code Review
Browse files

Merge "Return copies of private array members in Display.java to protect them...

Merge "Return copies of private array members in Display.java to protect them from being modified from the outside." into udc-dev
parents 5665fbf9 dc403705
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -2188,7 +2188,7 @@ public final class Display {
         */
        @NonNull
        public float[] getAlternativeRefreshRates() {
            return mAlternativeRefreshRates;
            return Arrays.copyOf(mAlternativeRefreshRates, mAlternativeRefreshRates.length);
        }

        /**
@@ -2197,7 +2197,7 @@ public final class Display {
        @NonNull
        @HdrCapabilities.HdrType
        public int[] getSupportedHdrTypes() {
            return mSupportedHdrTypes;
            return Arrays.copyOf(mSupportedHdrTypes, mSupportedHdrTypes.length);
        }

        /**
@@ -2497,8 +2497,10 @@ public final class Display {
         * @deprecated use {@link Display#getMode()}
         * and {@link Mode#getSupportedHdrTypes()} instead
         */
        public @HdrType int[] getSupportedHdrTypes() {
            return mSupportedHdrTypes;
        @Deprecated
        @HdrType
        public int[] getSupportedHdrTypes() {
            return Arrays.copyOf(mSupportedHdrTypes, mSupportedHdrTypes.length);
        }
        /**
         * Returns the desired content max luminance data in cd/m2 for this display.
+30 −0
Original line number Diff line number Diff line
@@ -460,6 +460,36 @@ public class DisplayTest {
        assertArrayEquals(sortedHdrTypes, displayMode.getSupportedHdrTypes());
    }

    @Test
    public void testGetSupportedHdrTypesReturnsCopy() {
        int[] hdrTypes = new int[]{1, 2, 3};
        Display.Mode displayMode = new Display.Mode(0, 0, 0, 0, new float[0], hdrTypes);

        int[] hdrTypesCopy = displayMode.getSupportedHdrTypes();
        hdrTypesCopy[0] = 0;
        assertArrayEquals(hdrTypes, displayMode.getSupportedHdrTypes());
    }

    @Test
    public void testGetAlternativeRefreshRatesReturnsCopy() {
        float[] alternativeRates = new float[]{1.0f, 2.0f};
        Display.Mode displayMode = new Display.Mode(0, 0, 0, 0, alternativeRates, new int[0]);

        float[] alternativeRatesCopy = displayMode.getAlternativeRefreshRates();
        alternativeRatesCopy[0] = 0.0f;
        assertArrayEquals(alternativeRates, displayMode.getAlternativeRefreshRates(), 0.0f);
    }

    @Test
    public void testHdrCapabilitiesGetSupportedHdrTypesReturnsCopy() {
        int[] hdrTypes = new int[]{1, 2, 3};
        Display.HdrCapabilities hdrCapabilities = new Display.HdrCapabilities(hdrTypes, 0, 0, 0);

        int[] hdrTypesCopy = hdrCapabilities.getSupportedHdrTypes();
        hdrTypesCopy[0] = 0;
        assertArrayEquals(hdrTypes, hdrCapabilities.getSupportedHdrTypes());
    }

    // Given rotated display dimensions, calculate the letterboxed app bounds.
    private static Rect buildAppBounds(int displayWidth, int displayHeight) {
        final int midWidth = displayWidth / 2;