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

Commit 0f6d2380 authored by Oleg Petšjonkin's avatar Oleg Petšjonkin Committed by Automerger Merge Worker
Browse files

Merge "Making Layout.Display immutable" into udc-dev am: 608fa1fd

parents f81ef47f 608fa1fd
Loading
Loading
Loading
Loading
+15 −12
Original line number Diff line number Diff line
@@ -121,24 +121,17 @@ class DeviceStateToLayoutMap {
                final Layout layout = createLayout(state);
                for (com.android.server.display.config.layout.Display d: l.getDisplay()) {
                    assert layout != null;
                    Layout.Display display = layout.createDisplayLocked(
                    int position = getPosition(d.getPosition());
                    layout.createDisplayLocked(
                            DisplayAddress.fromPhysicalDisplayId(d.getAddress().longValue()),
                            d.isDefaultDisplay(),
                            d.isEnabled(),
                            d.getDisplayGroup(),
                            mIdProducer,
                            position,
                            leadDisplayId,
                            d.getBrightnessThrottlingMapId(),
                            leadDisplayId);

                    if (FRONT_STRING.equals(d.getPosition())) {
                        display.setPosition(POSITION_FRONT);
                    } else if (REAR_STRING.equals(d.getPosition())) {
                        display.setPosition(POSITION_REAR);
                    } else {
                        display.setPosition(POSITION_UNKNOWN);
                    }
                    display.setRefreshRateZoneId(d.getRefreshRateZoneId());
                    display.setRefreshRateThermalThrottlingMapId(
                            d.getRefreshRateZoneId(),
                            d.getRefreshRateThermalThrottlingMapId());
                }
            }
@@ -148,6 +141,16 @@ class DeviceStateToLayoutMap {
        }
    }

    private int getPosition(@NonNull String position) {
        int positionInt = POSITION_UNKNOWN;
        if (FRONT_STRING.equals(position)) {
            positionInt = POSITION_FRONT;
        } else if (REAR_STRING.equals(position)) {
            positionInt = POSITION_REAR;
        }
        return positionInt;
    }

    private Layout createLayout(int state) {
        if (mLayoutMap.contains(state)) {
            Slog.e(TAG, "Attempted to create a second layout for state " + state);
+2 −9
Original line number Diff line number Diff line
@@ -18,8 +18,6 @@ package com.android.server.display;

import static android.view.Display.DEFAULT_DISPLAY;

import static com.android.server.display.layout.Layout.NO_LEAD_DISPLAY;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
@@ -646,10 +644,7 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
                if ((nextDeviceInfo.flags
                        & DisplayDeviceInfo.FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY) != 0
                        && !nextDeviceInfo.address.equals(deviceInfo.address)) {
                    layout.createDisplayLocked(nextDeviceInfo.address,
                            /* isDefault= */ true, /* isEnabled= */ true,
                            Layout.DEFAULT_DISPLAY_GROUP_NAME, mIdProducer,
                            /* brightnessThrottlingMapId= */ null, DEFAULT_DISPLAY);
                    layout.createDefaultDisplayLocked(nextDeviceInfo.address, mIdProducer);
                    applyLayoutLocked();
                    return;
                }
@@ -1110,9 +1105,7 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
            return;
        }
        final DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
        layout.createDisplayLocked(info.address, /* isDefault= */ true, /* isEnabled= */ true,
                Layout.DEFAULT_DISPLAY_GROUP_NAME, mIdProducer,
                /* brightnessThrottlingMapId= */ null, NO_LEAD_DISPLAY);
        layout.createDefaultDisplayLocked(info.address, mIdProducer);
    }

    private int assignLayerStackLocked(int displayId) {
+32 −74
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ public class Layout {
    public static final String DEFAULT_DISPLAY_GROUP_NAME = "";

    private static final String TAG = "Layout";
    private static int sNextNonDefaultDisplayId = DEFAULT_DISPLAY + 1;

    // Lead display Id is set to this if this is not a follower display, and therefore
    // has no lead.
@@ -47,13 +46,6 @@ public class Layout {

    private final List<Display> mDisplays = new ArrayList<>(2);

    /**
     *  @return The default display ID, or a new unique one to use.
     */
    public static int assignDisplayIdLocked(boolean isDefault) {
        return isDefault ? DEFAULT_DISPLAY : sNextNonDefaultDisplayId++;
    }

    @Override
    public String toString() {
        return mDisplays.toString();
@@ -76,25 +68,17 @@ public class Layout {
    }

    /**
     * Creates a simple 1:1 LogicalDisplay mapping for the specified DisplayDevice.
     * Creates the default 1:1 LogicalDisplay mapping for the specified DisplayDevice.
     *
     * @param address Address of the device.
     * @param isDefault Indicates if the device is meant to be the default display.
     * @param isEnabled Indicates if this display is usable and can be switched on
     * @param displayGroupName Name of the display group to which the display is assigned.
     * @param idProducer Produces the logical display id.
     * @param brightnessThrottlingMapId Name of which throttling policy should be used.
     * @param leadDisplayId Display that this one follows (-1 if none).
     * @exception IllegalArgumentException When a default display owns a display group other than
     *            DEFAULT_DISPLAY_GROUP.
     * @return The new Display.
     */
    public Display createDisplayLocked(
            @NonNull DisplayAddress address, boolean isDefault, boolean isEnabled,
            String displayGroupName, DisplayIdProducer idProducer, String brightnessThrottlingMapId,
            int leadDisplayId) {
        return createDisplayLocked(address, isDefault, isEnabled, displayGroupName, idProducer,
                brightnessThrottlingMapId, POSITION_UNKNOWN, leadDisplayId);
    public void createDefaultDisplayLocked(@NonNull DisplayAddress address,
            DisplayIdProducer idProducer) {
        createDisplayLocked(address, /* isDefault= */ true, /* isEnabled= */ true,
                DEFAULT_DISPLAY_GROUP_NAME, idProducer, POSITION_UNKNOWN,
                NO_LEAD_DISPLAY, /* brightnessThrottlingMapId= */ null,
                /* refreshRateZoneId= */ null, /* refreshRateThermalThrottlingMapId= */ null);
    }

    /**
@@ -105,26 +89,30 @@ public class Layout {
     * @param isEnabled Indicates if this display is usable and can be switched on
     * @param displayGroupName Name of the display group to which the display is assigned.
     * @param idProducer Produces the logical display id.
     * @param brightnessThrottlingMapId Name of which throttling policy should be used.
     * @param position Indicates the position this display is facing in this layout.
     * @param leadDisplayId Display that this one follows (-1 if none).
     * @param brightnessThrottlingMapId Name of which brightness throttling policy should be used.
     * @param refreshRateZoneId Layout limited refresh rate zone name.
     * @param refreshRateThermalThrottlingMapId Name of which refresh rate throttling
     *                                          policy should be used.

     * @exception IllegalArgumentException When a default display owns a display group other than
     *            DEFAULT_DISPLAY_GROUP.
     * @return The new Display.
     */
    public Display createDisplayLocked(
    public void createDisplayLocked(
            @NonNull DisplayAddress address, boolean isDefault, boolean isEnabled,
            String displayGroupName, DisplayIdProducer idProducer, String brightnessThrottlingMapId,
            int position, int leadDisplayId) {
            String displayGroupName, DisplayIdProducer idProducer, int position, int leadDisplayId,
            String brightnessThrottlingMapId, @Nullable String refreshRateZoneId,
            @Nullable String refreshRateThermalThrottlingMapId) {
        if (contains(address)) {
            Slog.w(TAG, "Attempting to add second definition for display-device: " + address);
            return null;
            return;
        }

        // See if we're dealing with the "default" display
        if (isDefault && getById(DEFAULT_DISPLAY) != null) {
            Slog.w(TAG, "Ignoring attempt to add a second default display: " + address);
            return null;
            return;
        }

        // Assign a logical display ID and create the new display.
@@ -138,11 +126,13 @@ public class Layout {
            throw new IllegalArgumentException("Default display should own DEFAULT_DISPLAY_GROUP");
        }
        final int logicalDisplayId = idProducer.getId(isDefault);
        leadDisplayId = isDefault ? NO_LEAD_DISPLAY : leadDisplayId;

        final Display display = new Display(address, logicalDisplayId, isEnabled, displayGroupName,
                brightnessThrottlingMapId, position, leadDisplayId);
                brightnessThrottlingMapId, position, leadDisplayId, refreshRateZoneId,
                refreshRateThermalThrottlingMapId);

        mDisplays.add(display);
        return display;
    }

    /**
@@ -242,7 +232,7 @@ public class Layout {
        // {@link DeviceStateToLayoutMap.POSITION_FRONT} or
        // {@link DeviceStateToLayoutMap.POSITION_REAR}.
        // {@link DeviceStateToLayoutMap.POSITION_UNKNOWN} is unspecified.
        private int mPosition;
        private final int mPosition;

        // The ID of the brightness throttling map that should be used. This can change e.g. in
        // concurrent displays mode in which a stricter brightness throttling policy might need to
@@ -251,33 +241,30 @@ public class Layout {
        private final String mBrightnessThrottlingMapId;

        // The ID of the lead display that this display will follow in a layout. -1 means no lead.
        private int mLeadDisplayId;
        private final int mLeadDisplayId;

        // Refresh rate zone id for specific layout
        @Nullable
        private String mRefreshRateZoneId;
        private final String mRefreshRateZoneId;

        @Nullable
        private String mRefreshRateThermalThrottlingMapId;
        private final String mRefreshRateThermalThrottlingMapId;

        Display(@NonNull DisplayAddress address, int logicalDisplayId, boolean isEnabled,
        private Display(@NonNull DisplayAddress address, int logicalDisplayId, boolean isEnabled,
                @NonNull String displayGroupName, String brightnessThrottlingMapId, int position,
                int leadDisplayId) {
                int leadDisplayId, @Nullable String refreshRateZoneId,
                @Nullable String refreshRateThermalThrottlingMapId) {
            mAddress = address;
            mLogicalDisplayId = logicalDisplayId;
            mIsEnabled = isEnabled;
            mDisplayGroupName = displayGroupName;
            mPosition = position;
            mBrightnessThrottlingMapId = brightnessThrottlingMapId;

            if (leadDisplayId == mLogicalDisplayId) {
                mLeadDisplayId = NO_LEAD_DISPLAY;
            } else {
            mRefreshRateZoneId = refreshRateZoneId;
            mRefreshRateThermalThrottlingMapId = refreshRateThermalThrottlingMapId;
            mLeadDisplayId = leadDisplayId;
        }

        }

        @Override
        public String toString() {
            return "{"
@@ -345,23 +332,11 @@ public class Layout {
            return mDisplayGroupName;
        }

        public void setRefreshRateZoneId(@Nullable String refreshRateZoneId) {
            mRefreshRateZoneId = refreshRateZoneId;
        }

        @Nullable
        public String getRefreshRateZoneId() {
            return mRefreshRateZoneId;
        }

        /**
         * Sets the position that this display is facing.
         * @param position the display is facing.
         */
        public void setPosition(int position) {
            mPosition = position;
        }

        /**
         * @return The ID of the brightness throttling map that this display should use.
         */
@@ -370,7 +345,6 @@ public class Layout {
        }

        /**
         *
         * @return the position that this display is facing.
         */
        public int getPosition() {
@@ -378,28 +352,12 @@ public class Layout {
        }

        /**
         * Set the display that this display should follow certain properties of, for example,
         * brightness
         * @param displayId of the lead display.
         */
        public void setLeadDisplay(int displayId) {
            if (displayId != mLogicalDisplayId) {
                mLeadDisplayId = displayId;
            }
        }

        /**
         *
         * @return logical displayId of the display that this one follows.
         */
        public int getLeadDisplayId() {
            return mLeadDisplayId;
        }

        public void setRefreshRateThermalThrottlingMapId(String refreshRateThermalThrottlingMapId) {
            mRefreshRateThermalThrottlingMapId = refreshRateThermalThrottlingMapId;
        }

        public String getRefreshRateThermalThrottlingMapId() {
            return mRefreshRateThermalThrottlingMapId;
        }
+66 −76
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.display;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import android.view.Display;
import android.view.DisplayAddress;
@@ -63,26 +64,10 @@ public class DeviceStateToLayoutMapTest {
        Layout configLayout = mDeviceStateToLayoutMap.get(0);

        Layout testLayout = new Layout();
        testLayout.createDisplayLocked(
                DisplayAddress.fromPhysicalDisplayId(123456L), /* isDefault= */ true,
                /* isEnabled= */ true, /* displayGroup= */ null, mDisplayIdProducerMock,
                /* brightnessThrottlingMapId= */ null,
                /* leadDisplayId= */ Display.DEFAULT_DISPLAY);
        testLayout.createDisplayLocked(
                DisplayAddress.fromPhysicalDisplayId(78910L), /* isDefault= */ false,
                /* isEnabled= */ false, /* displayGroup= */ null, mDisplayIdProducerMock,
                /* brightnessThrottlingMapId= */ null,
                /* leadDisplayId= */ Display.DEFAULT_DISPLAY);
        testLayout.createDisplayLocked(
                DisplayAddress.fromPhysicalDisplayId(98765L), /* isDefault= */ false,
                /* isEnabled= */ true, "group1", mDisplayIdProducerMock,
                /* brightnessThrottlingMapId= */ null,
                /* leadDisplayId= */ Display.DEFAULT_DISPLAY);
        testLayout.createDisplayLocked(
                DisplayAddress.fromPhysicalDisplayId(786L), /* isDefault= */ false,
                /* isEnabled= */ false, "group2", mDisplayIdProducerMock,
                /* brightnessThrottlingMapId= */ null,
                /* leadDisplayId= */ Display.DEFAULT_DISPLAY);
        createDefaultDisplay(testLayout, 123456L);
        createNonDefaultDisplay(testLayout, 78910L, /* enabled= */ false, /* group= */ null);
        createNonDefaultDisplay(testLayout, 98765L, /* enabled= */ true, /* group= */ "group1");
        createNonDefaultDisplay(testLayout, 786L, /* enabled= */ false, /* group= */ "group2");

        assertEquals(testLayout, configLayout);
    }
@@ -92,41 +77,18 @@ public class DeviceStateToLayoutMapTest {
        Layout configLayout = mDeviceStateToLayoutMap.get(1);

        Layout testLayout = new Layout();
        testLayout.createDisplayLocked(
                DisplayAddress.fromPhysicalDisplayId(78910L), /* isDefault= */ true,
                /* isEnabled= */ true, /* displayGroup= */ null, mDisplayIdProducerMock,
                /* brightnessThrottlingMapId= */ null,
                /* leadDisplayId= */ Display.DEFAULT_DISPLAY);
        testLayout.createDisplayLocked(
                DisplayAddress.fromPhysicalDisplayId(123456L), /* isDefault= */ false,
                /* isEnabled= */ false, /* displayGroup= */ null, mDisplayIdProducerMock,
                /* brightnessThrottlingMapId= */ null,
                /* leadDisplayId= */ Display.DEFAULT_DISPLAY);
        createDefaultDisplay(testLayout, 78910L);
        createNonDefaultDisplay(testLayout, 123456L, /* enabled= */ false, /* group= */ null);

        assertEquals(testLayout, configLayout);
    }

    @Test
    public void testConcurrentState() {
    public void testBrightnessThrottlingMapId() {
        Layout configLayout = mDeviceStateToLayoutMap.get(2);

        Layout testLayout = new Layout();

        Layout.Display display1 = testLayout.createDisplayLocked(
                DisplayAddress.fromPhysicalDisplayId(345L), /* isDefault= */ true,
                /* isEnabled= */ true, /* displayGroup= */ null, mDisplayIdProducerMock,
                /* brightnessThrottlingMapId= */ "concurrent",
                /* leadDisplayId= */ Display.DEFAULT_DISPLAY);
        display1.setPosition(Layout.Display.POSITION_FRONT);

        Layout.Display display2 = testLayout.createDisplayLocked(
                DisplayAddress.fromPhysicalDisplayId(678L), /* isDefault= */ false,
                /* isEnabled= */ true, /* displayGroup= */ null, mDisplayIdProducerMock,
                /* brightnessThrottlingMapId= */ "concurrent",
                /* leadDisplayId= */ Display.DEFAULT_DISPLAY);
        display2.setPosition(Layout.Display.POSITION_REAR);

        assertEquals(testLayout, configLayout);
        assertEquals("concurrent1", configLayout.getAt(0).getBrightnessThrottlingMapId());
        assertEquals("concurrent2", configLayout.getAt(1).getBrightnessThrottlingMapId());
    }

    @Test
@@ -141,38 +103,33 @@ public class DeviceStateToLayoutMapTest {
    public void testRefreshRateZoneId() {
        Layout configLayout = mDeviceStateToLayoutMap.get(3);

        Layout testLayout = new Layout();
        Layout.Display display1 = testLayout.createDisplayLocked(
                DisplayAddress.fromPhysicalDisplayId(345L), /* isDefault= */ true,
                /* isEnabled= */ true, /* displayGroup= */ null, mDisplayIdProducerMock,
                /* brightnessThrottlingMapId= */ null,
                /* leadDisplayId= */ Display.DEFAULT_DISPLAY);
        display1.setRefreshRateZoneId("test1");
        testLayout.createDisplayLocked(
                DisplayAddress.fromPhysicalDisplayId(678L), /* isDefault= */ false,
                /* isEnabled= */ true, /* displayGroup= */ null, mDisplayIdProducerMock,
                /* brightnessThrottlingMapId= */ null,
                /* leadDisplayId= */ Display.DEFAULT_DISPLAY);

        assertEquals(testLayout, configLayout);
        assertEquals("test1", configLayout.getAt(0).getRefreshRateZoneId());
        assertNull(configLayout.getAt(1).getRefreshRateZoneId());
    }

    @Test
    public void testRefreshRateThermalThrottlingMapId() {
        Layout configLayout = mDeviceStateToLayoutMap.get(4);

        assertEquals("test2", configLayout.getAt(0).getRefreshRateThermalThrottlingMapId());
        assertNull(configLayout.getAt(1).getRefreshRateThermalThrottlingMapId());
    }

    @Test
    public void testWholeStateConfig() {
        Layout configLayout = mDeviceStateToLayoutMap.get(99);

        Layout testLayout = new Layout();
        Layout.Display display1 = testLayout.createDisplayLocked(
                DisplayAddress.fromPhysicalDisplayId(345L), /* isDefault= */ true,
                /* isEnabled= */ true, /* displayGroup= */ null, mDisplayIdProducerMock,
                /* brightnessThrottlingMapId= */ null,
                /* leadDisplayId= */ Display.DEFAULT_DISPLAY);
        display1.setRefreshRateThermalThrottlingMapId("test2");
        testLayout.createDisplayLocked(
                DisplayAddress.fromPhysicalDisplayId(678L), /* isDefault= */ false,
                /* isEnabled= */ true, /* displayGroup= */ null, mDisplayIdProducerMock,
                /* brightnessThrottlingMapId= */ null,
                /* leadDisplayId= */ Display.DEFAULT_DISPLAY);
        testLayout.createDisplayLocked(DisplayAddress.fromPhysicalDisplayId(345L),
                /* isDefault= */ true, /* isEnabled= */ true, /* displayGroupName= */ null,
                mDisplayIdProducerMock,  Layout.Display.POSITION_FRONT, Display.DEFAULT_DISPLAY,
                /* brightnessThrottlingMapId= */ "brightness1",
                /* refreshRateZoneId= */ "zone1", /* refreshRateThermalThrottlingMapId= */ "rr1");
        testLayout.createDisplayLocked(DisplayAddress.fromPhysicalDisplayId(678L),
                /* isDefault= */ false, /* isEnabled= */ false, /* displayGroupName= */ "group1",
                mDisplayIdProducerMock, Layout.Display.POSITION_REAR, Display.DEFAULT_DISPLAY,
                /* brightnessThrottlingMapId= */ "brightness2",
                /* refreshRateZoneId= */ "zone2", /* refreshRateThermalThrottlingMapId= */ "rr2");

        assertEquals(testLayout, configLayout);
    }
@@ -181,6 +138,18 @@ public class DeviceStateToLayoutMapTest {
    // Helper Methods //
    ////////////////////

    private void createDefaultDisplay(Layout layout, long id) {
        layout.createDefaultDisplayLocked(DisplayAddress.fromPhysicalDisplayId(id),
                mDisplayIdProducerMock);
    }

    private void createNonDefaultDisplay(Layout layout, long id, boolean enabled, String group) {
        layout.createDisplayLocked(DisplayAddress.fromPhysicalDisplayId(id), /* isDefault= */ false,
                enabled, group, mDisplayIdProducerMock, Layout.Display.POSITION_UNKNOWN,
                Display.DEFAULT_DISPLAY, /* brightnessThrottlingMapId= */ null,
                /* refreshRateZoneId= */ null, /* refreshRateThermalThrottlingMapId= */ null);
    }

    private void setupDeviceStateToLayoutMap() throws IOException {
        Path tempFile = Files.createTempFile("device_state_layout_map", ".tmp");
        Files.write(tempFile, getContent().getBytes(StandardCharsets.UTF_8));
@@ -222,12 +191,12 @@ public class DeviceStateToLayoutMapTest {
                +      "<display enabled=\"true\" defaultDisplay=\"true\">\n"
                +        "<address>345</address>\n"
                +        "<position>front</position>\n"
                +        "<brightnessThrottlingMapId>concurrent</brightnessThrottlingMapId>\n"
                +        "<brightnessThrottlingMapId>concurrent1</brightnessThrottlingMapId>\n"
                +      "</display>\n"
                +      "<display enabled=\"true\">\n"
                +        "<address>678</address>\n"
                +        "<position>rear</position>\n"
                +        "<brightnessThrottlingMapId>concurrent</brightnessThrottlingMapId>\n"
                +        "<brightnessThrottlingMapId>concurrent2</brightnessThrottlingMapId>\n"
                +      "</display>\n"
                +    "</layout>\n"

@@ -254,6 +223,27 @@ public class DeviceStateToLayoutMapTest {
                +        "<address>678</address>\n"
                +      "</display>\n"
                +    "</layout>\n"
                +    "<layout>\n"
                +      "<state>99</state> \n"
                +      "<display enabled=\"true\" defaultDisplay=\"true\" "
                +                                          "refreshRateZoneId=\"zone1\">\n"
                +         "<address>345</address>\n"
                +         "<position>front</position>\n"
                +         "<brightnessThrottlingMapId>brightness1</brightnessThrottlingMapId>\n"
                +         "<refreshRateThermalThrottlingMapId>"
                +           "rr1"
                +         "</refreshRateThermalThrottlingMapId>"
                +       "</display>\n"
                +       "<display enabled=\"false\" displayGroup=\"group1\" "
                +                                           "refreshRateZoneId=\"zone2\">\n"
                +         "<address>678</address>\n"
                +         "<position>rear</position>\n"
                +         "<brightnessThrottlingMapId>brightness2</brightnessThrottlingMapId>\n"
                +         "<refreshRateThermalThrottlingMapId>"
                +           "rr2"
                +         "</refreshRateThermalThrottlingMapId>"
                +       "</display>\n"
                +     "</layout>\n"
                +   "</layouts>\n";
    }
}
+58 −102

File changed.

Preview size limit exceeded, changes collapsed.