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

Commit 6c5a8c31 authored by Marc Kassis's avatar Marc Kassis Committed by Automerger Merge Worker
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 am: 037b13c9

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22648883



Change-Id: Ife709c856ae80d0d3a8cfbe194c2bb152170e6c1
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents ab14461b 037b13c9
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;