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

Commit f7e1084c authored by Pierre Barbier de Reuille's avatar Pierre Barbier de Reuille
Browse files

Update the name of the external display

The external display will now take their name from the EDID provided.

The display device config still has precedence over the EDID, so OEMs
can specify the name to be shown in case the external display is part of
the package. If the EDID does not have a valid name, `HDMI Screen` will
continue to be used.

Fix: 413699683
Test: Manual
Test: atest LocalDisplayAdapterTest
Flag: EXEMPT (bug fix)
Change-Id: I05a698810b0b6b963f1aaddf349c17b7b84761e9
parent 921f2de4
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -848,7 +848,10 @@ final class LocalDisplayAdapter extends DisplayAdapter {
                    mInfo.type = Display.TYPE_EXTERNAL;
                    mInfo.touch = DisplayDeviceInfo.TOUCH_EXTERNAL;
                    mInfo.flags |= DisplayDeviceInfo.FLAG_PRESENTATION;
                    if (mInfo.name == null) {
                    if (mInfo.name == null && mStaticDisplayInfo.deviceProductInfo != null) {
                        mInfo.name = mStaticDisplayInfo.deviceProductInfo.getName();
                    }
                    if (mInfo.name == null || mInfo.name.isBlank()) {
                        mInfo.name = getContext().getResources().getString(
                                R.string.display_manager_hdmi_display_name);
                    }
+56 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.display;

import static android.hardware.display.DeviceProductInfo.CONNECTION_TO_SINK_DIRECT;

import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
@@ -42,6 +44,7 @@ import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.hardware.display.DeviceProductInfo;
import android.hardware.display.DisplayManagerInternal.DisplayOffloader;
import android.os.Binder;
import android.os.Handler;
@@ -1655,6 +1658,59 @@ public class LocalDisplayAdapterTest {
        assertFalse(allowsContentModeSwitch && shouldShowSystemDecorations);
    }

    @Test
    public void testExternalDisplayName_fromEDID() throws Exception {
        FakeDisplay display = new FakeDisplay(PORT_A);
        String displayName = "Display Name";
        display.info.deviceProductInfo = new DeviceProductInfo(displayName, "Manufacturer",
                "ProductId", 2025, CONNECTION_TO_SINK_DIRECT);
        setUpDisplay(display);
        updateAvailableDisplays();

        mAdapter.registerLocked();
        waitForHandlerToComplete(mHandler, HANDLER_WAIT_MS);

        DisplayDevice displayDevice = mListener.addedDisplays.get(0);
        assertEquals(displayName, displayDevice.getNameLocked());
    }

    @Test
    public void testExternalDisplayName_emptyEDIDName_fallback() throws Exception {
        FakeDisplay display = new FakeDisplay(PORT_A);
        String displayName = "Fallback Name";
        doReturn(displayName).when(mMockedResources).getString(
                eq(R.string.display_manager_hdmi_display_name));
        display.info.deviceProductInfo = new DeviceProductInfo("  ", "Manufacturer",
                "ProductId", 2025, CONNECTION_TO_SINK_DIRECT);
        setUpDisplay(display);
        updateAvailableDisplays();

        mAdapter.registerLocked();
        waitForHandlerToComplete(mHandler, HANDLER_WAIT_MS);

        DisplayDevice displayDevice = mListener.addedDisplays.get(0);
        assertEquals(displayName, displayDevice.getNameLocked());
    }

    @Test
    public void testExternalDisplayName_fromDisplayConfig() throws Exception {
        String displayName = "DisplayConfig name";
        doReturn(displayName).when(mMockDisplayDeviceConfig).getName();
        FakeDisplay display = new FakeDisplay(PORT_A);
        doReturn(displayName).when(mMockedResources).getString(
                eq(R.string.display_manager_hdmi_display_name));
        display.info.deviceProductInfo = new DeviceProductInfo("EDID name", "Manufacturer",
                "ProductId", 2025, CONNECTION_TO_SINK_DIRECT);
        setUpDisplay(display);
        updateAvailableDisplays();

        mAdapter.registerLocked();
        waitForHandlerToComplete(mHandler, HANDLER_WAIT_MS);

        DisplayDevice displayDevice = mListener.addedDisplays.get(0);
        assertEquals(displayName, displayDevice.getNameLocked());
    }

    private void initDisplayOffloadSession() {
        when(mDisplayOffloader.startOffload()).thenReturn(true);
        when(mDisplayOffloader.allowAutoBrightnessInDoze()).thenReturn(true);