Loading core/java/android/hardware/display/DisplayViewport.java +5 −2 Original line number Original line Diff line number Diff line Loading @@ -134,7 +134,9 @@ public final class DisplayViewport { result += prime * result + deviceWidth; result += prime * result + deviceWidth; result += prime * result + deviceHeight; result += prime * result + deviceHeight; result += prime * result + uniqueId.hashCode(); result += prime * result + uniqueId.hashCode(); result += prime * result + physicalPort; if (physicalPort != null) { result += prime * result + physicalPort.hashCode(); } result += prime * result + type; result += prime * result + type; return result; return result; } } Loading @@ -142,11 +144,12 @@ public final class DisplayViewport { // For debugging purposes. // For debugging purposes. @Override @Override public String toString() { public String toString() { final Integer port = physicalPort == null ? null : Byte.toUnsignedInt(physicalPort); return "DisplayViewport{type=" + typeToString(type) return "DisplayViewport{type=" + typeToString(type) + ", valid=" + valid + ", valid=" + valid + ", displayId=" + displayId + ", displayId=" + displayId + ", uniqueId='" + uniqueId + "'" + ", uniqueId='" + uniqueId + "'" + ", physicalPort=" + physicalPort + ", physicalPort=" + port + ", orientation=" + orientation + ", orientation=" + orientation + ", logicalFrame=" + logicalFrame + ", logicalFrame=" + logicalFrame + ", physicalFrame=" + physicalFrame + ", physicalFrame=" + physicalFrame Loading core/java/android/view/DisplayAddress.java +31 −3 Original line number Original line Diff line number Diff line Loading @@ -40,6 +40,18 @@ public abstract class DisplayAddress implements Parcelable { return new Physical(physicalDisplayId); return new Physical(physicalDisplayId); } } /** * Creates an address for a physical display given its port and model. * * @param port A port in the range [0, 255] interpreted as signed. * @param model A positive integer, or {@code null} if the model cannot be identified. * @return The {@link Physical} address. */ @NonNull public static Physical fromPortAndModel(byte port, Long model) { return new Physical(port, model); } /** /** * Creates an address for a network display given its MAC address. * Creates an address for a network display given its MAC address. * * Loading @@ -64,12 +76,23 @@ public abstract class DisplayAddress implements Parcelable { public static final class Physical extends DisplayAddress { public static final class Physical extends DisplayAddress { private static final long UNKNOWN_MODEL = 0; private static final long UNKNOWN_MODEL = 0; private static final int MODEL_SHIFT = 8; private static final int MODEL_SHIFT = 8; private static final int PORT_MASK = 0xFF; private final long mPhysicalDisplayId; private final long mPhysicalDisplayId; /** * Stable display ID combining port and model. * * @return An ID in the range [0, 2^64) interpreted as signed. * @see SurfaceControl#getPhysicalDisplayIds */ public long getPhysicalDisplayId() { return mPhysicalDisplayId; } /** /** * Physical port to which the display is connected. * Physical port to which the display is connected. * * @return A port in the range [0, 255] interpreted as signed. */ */ public byte getPort() { public byte getPort() { return (byte) mPhysicalDisplayId; return (byte) mPhysicalDisplayId; Loading @@ -78,7 +101,7 @@ public abstract class DisplayAddress implements Parcelable { /** /** * Model identifier unique across manufacturers. * Model identifier unique across manufacturers. * * * @return The model ID, or {@code null} if the model cannot be identified. * @return A positive integer, or {@code null} if the model cannot be identified. */ */ @Nullable @Nullable public Long getModel() { public Long getModel() { Loading @@ -95,7 +118,7 @@ public abstract class DisplayAddress implements Parcelable { @Override @Override public String toString() { public String toString() { final StringBuilder builder = new StringBuilder("{") final StringBuilder builder = new StringBuilder("{") .append("port=").append(getPort() & PORT_MASK); .append("port=").append(Byte.toUnsignedInt(getPort())); final Long model = getModel(); final Long model = getModel(); if (model != null) { if (model != null) { Loading @@ -119,6 +142,11 @@ public abstract class DisplayAddress implements Parcelable { mPhysicalDisplayId = physicalDisplayId; mPhysicalDisplayId = physicalDisplayId; } } private Physical(byte port, Long model) { mPhysicalDisplayId = Byte.toUnsignedLong(port) | (model == null ? UNKNOWN_MODEL : (model << MODEL_SHIFT)); } public static final @NonNull Parcelable.Creator<Physical> CREATOR = public static final @NonNull Parcelable.Creator<Physical> CREATOR = new Parcelable.Creator<Physical>() { new Parcelable.Creator<Physical>() { @Override @Override Loading services/core/java/com/android/server/display/LocalDisplayAdapter.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -848,7 +848,7 @@ final class LocalDisplayAdapter extends DisplayAdapter { int[] ports = res.getIntArray( int[] ports = res.getIntArray( com.android.internal.R.array.config_localPrivateDisplayPorts); com.android.internal.R.array.config_localPrivateDisplayPorts); if (ports != null) { if (ports != null) { int port = physicalAddress.getPort(); int port = Byte.toUnsignedInt(physicalAddress.getPort()); for (int p : ports) { for (int p : ports) { if (p == port) { if (p == port) { return true; return true; Loading services/core/java/com/android/server/wm/DisplayWindowSettings.java +2 −1 Original line number Original line Diff line number Diff line Loading @@ -642,7 +642,8 @@ class DisplayWindowSettings { if (mIdentifier == IDENTIFIER_PORT && displayInfo.address != null) { if (mIdentifier == IDENTIFIER_PORT && displayInfo.address != null) { // Config suggests using port as identifier for physical displays. // Config suggests using port as identifier for physical displays. if (displayInfo.address instanceof DisplayAddress.Physical) { if (displayInfo.address instanceof DisplayAddress.Physical) { return "port:" + ((DisplayAddress.Physical) displayInfo.address).getPort(); byte port = ((DisplayAddress.Physical) displayInfo.address).getPort(); return "port:" + Byte.toUnsignedInt(port); } } } } return displayInfo.uniqueId; return displayInfo.uniqueId; Loading services/tests/mockingservicestests/src/com/android/server/display/LocalDisplayAdapterTest.java +38 −41 Original line number Original line Diff line number Diff line Loading @@ -53,9 +53,12 @@ import java.util.LinkedList; @SmallTest @SmallTest @RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class) public class LocalDisplayAdapterTest { public class LocalDisplayAdapterTest { private static final long HANDLER_WAIT_MS = 100; private static final Long DISPLAY_MODEL = Long.valueOf(0xAAAAAAAAL); private static final int PORT_A = 0; private static final int PORT_B = 0x80; private static final int PORT_C = 0xFF; private static final int PHYSICAL_DISPLAY_ID_MODEL_SHIFT = 8; private static final long HANDLER_WAIT_MS = 100; private StaticMockitoSession mMockitoSession; private StaticMockitoSession mMockitoSession; Loading @@ -74,7 +77,7 @@ public class LocalDisplayAdapterTest { private TestListener mListener = new TestListener(); private TestListener mListener = new TestListener(); private LinkedList<Long> mDisplayIds = new LinkedList<>(); private LinkedList<DisplayAddress.Physical> mAddresses = new LinkedList<>(); @Before @Before public void setUp() throws Exception { public void setUp() throws Exception { Loading Loading @@ -106,30 +109,22 @@ public class LocalDisplayAdapterTest { */ */ @Test @Test public void testPrivateDisplay() throws Exception { public void testPrivateDisplay() throws Exception { // needs default one always setUpDisplay(new DisplayConfig(createDisplayAddress(PORT_A), createDummyDisplayInfo())); final long displayId0 = 0; setUpDisplay(new DisplayConfig(createDisplayAddress(PORT_B), createDummyDisplayInfo())); setUpDisplay(new DisplayConfig(displayId0, createDummyDisplayInfo())); setUpDisplay(new DisplayConfig(createDisplayAddress(PORT_C), createDummyDisplayInfo())); final long displayId1 = 1; setUpDisplay(new DisplayConfig(displayId1, createDummyDisplayInfo())); final long displayId2 = 2; setUpDisplay(new DisplayConfig(displayId2, createDummyDisplayInfo())); updateAvailableDisplays(); updateAvailableDisplays(); // display 1 should be marked as private while display 2 is not. doReturn(new int[]{ PORT_B }).when(mMockedResources) doReturn(new int[]{(int) displayId1}).when(mMockedResources) .getIntArray(com.android.internal.R.array.config_localPrivateDisplayPorts); .getIntArray(com.android.internal.R.array.config_localPrivateDisplayPorts); mAdapter.registerLocked(); mAdapter.registerLocked(); waitForHandlerToComplete(mHandler, HANDLER_WAIT_MS); waitForHandlerToComplete(mHandler, HANDLER_WAIT_MS); // This should be public // This should be public assertDisplay(mListener.addedDisplays.get(0).getDisplayDeviceInfoLocked(), displayId0, assertDisplay(mListener.addedDisplays.get(0).getDisplayDeviceInfoLocked(), PORT_A, false); false); // This should be private // This should be private assertDisplay(mListener.addedDisplays.get(1).getDisplayDeviceInfoLocked(), displayId1, assertDisplay(mListener.addedDisplays.get(1).getDisplayDeviceInfoLocked(), PORT_B, true); true); // This should be public // This should be public assertDisplay(mListener.addedDisplays.get(2).getDisplayDeviceInfoLocked(), displayId2, assertDisplay(mListener.addedDisplays.get(2).getDisplayDeviceInfoLocked(), PORT_C, false); false); } } /** /** Loading @@ -137,11 +132,8 @@ public class LocalDisplayAdapterTest { */ */ @Test @Test public void testPublicDisplaysForNoConfigLocalPrivateDisplayPorts() throws Exception { public void testPublicDisplaysForNoConfigLocalPrivateDisplayPorts() throws Exception { // needs default one always setUpDisplay(new DisplayConfig(createDisplayAddress(PORT_A), createDummyDisplayInfo())); final long displayId0 = 0; setUpDisplay(new DisplayConfig(createDisplayAddress(PORT_C), createDummyDisplayInfo())); setUpDisplay(new DisplayConfig(displayId0, createDummyDisplayInfo())); final long displayId1 = 1; setUpDisplay(new DisplayConfig(displayId1, createDummyDisplayInfo())); updateAvailableDisplays(); updateAvailableDisplays(); // config_localPrivateDisplayPorts is null // config_localPrivateDisplayPorts is null mAdapter.registerLocked(); mAdapter.registerLocked(); Loading @@ -149,35 +141,36 @@ public class LocalDisplayAdapterTest { waitForHandlerToComplete(mHandler, HANDLER_WAIT_MS); waitForHandlerToComplete(mHandler, HANDLER_WAIT_MS); // This should be public // This should be public assertDisplay(mListener.addedDisplays.get(0).getDisplayDeviceInfoLocked(), displayId0, assertDisplay(mListener.addedDisplays.get(0).getDisplayDeviceInfoLocked(), PORT_A, false); false); // This should be public // This should be public assertDisplay(mListener.addedDisplays.get(1).getDisplayDeviceInfoLocked(), displayId1, assertDisplay(mListener.addedDisplays.get(1).getDisplayDeviceInfoLocked(), PORT_C, false); false); } } private void assertDisplay(DisplayDeviceInfo info, long expectedPort, boolean shouldBePrivate) { private static void assertDisplay( DisplayAddress.Physical physical = (DisplayAddress.Physical) info.address; DisplayDeviceInfo info, int expectedPort, boolean shouldBePrivate) { assertNotNull(physical); final DisplayAddress.Physical address = (DisplayAddress.Physical) info.address; assertEquals(expectedPort, physical.getPort()); assertNotNull(address); assertEquals((byte) expectedPort, address.getPort()); assertEquals(DISPLAY_MODEL, address.getModel()); assertEquals(shouldBePrivate, (info.flags & DisplayDeviceInfo.FLAG_PRIVATE) != 0); assertEquals(shouldBePrivate, (info.flags & DisplayDeviceInfo.FLAG_PRIVATE) != 0); } } private class DisplayConfig { private class DisplayConfig { public final long displayId; public final DisplayAddress.Physical address; public final IBinder displayToken = new Binder(); public final IBinder displayToken = new Binder(); public final SurfaceControl.PhysicalDisplayInfo displayInfo; public final SurfaceControl.PhysicalDisplayInfo displayInfo; private DisplayConfig(long displayId, SurfaceControl.PhysicalDisplayInfo displayInfo) { private DisplayConfig( this.displayId = displayId | (0x1 << PHYSICAL_DISPLAY_ID_MODEL_SHIFT); DisplayAddress.Physical address, SurfaceControl.PhysicalDisplayInfo displayInfo) { this.address = address; this.displayInfo = displayInfo; this.displayInfo = displayInfo; } } } } private void setUpDisplay(DisplayConfig config) { private void setUpDisplay(DisplayConfig config) { mDisplayIds.add(config.displayId); mAddresses.add(config.address); doReturn(config.displayToken).when( doReturn(config.displayToken).when(() -> () -> SurfaceControl.getPhysicalDisplayToken(config.displayId)); SurfaceControl.getPhysicalDisplayToken(config.address.getPhysicalDisplayId())); doReturn(new SurfaceControl.PhysicalDisplayInfo[]{ doReturn(new SurfaceControl.PhysicalDisplayInfo[]{ config.displayInfo config.displayInfo }).when(() -> SurfaceControl.getDisplayConfigs(config.displayToken)); }).when(() -> SurfaceControl.getDisplayConfigs(config.displayToken)); Loading @@ -192,16 +185,20 @@ public class LocalDisplayAdapterTest { } } private void updateAvailableDisplays() { private void updateAvailableDisplays() { long[] ids = new long[mDisplayIds.size()]; long[] ids = new long[mAddresses.size()]; int i = 0; int i = 0; for (long id : mDisplayIds) { for (DisplayAddress.Physical address : mAddresses) { ids[i] = id; ids[i] = address.getPhysicalDisplayId(); i++; i++; } } doReturn(ids).when(() -> SurfaceControl.getPhysicalDisplayIds()); doReturn(ids).when(() -> SurfaceControl.getPhysicalDisplayIds()); } } private SurfaceControl.PhysicalDisplayInfo createDummyDisplayInfo() { private static DisplayAddress.Physical createDisplayAddress(int port) { return DisplayAddress.fromPortAndModel((byte) port, DISPLAY_MODEL); } private static SurfaceControl.PhysicalDisplayInfo createDummyDisplayInfo() { SurfaceControl.PhysicalDisplayInfo info = new SurfaceControl.PhysicalDisplayInfo(); SurfaceControl.PhysicalDisplayInfo info = new SurfaceControl.PhysicalDisplayInfo(); info.density = 100; info.density = 100; info.xDpi = 100; info.xDpi = 100; Loading Loading
core/java/android/hardware/display/DisplayViewport.java +5 −2 Original line number Original line Diff line number Diff line Loading @@ -134,7 +134,9 @@ public final class DisplayViewport { result += prime * result + deviceWidth; result += prime * result + deviceWidth; result += prime * result + deviceHeight; result += prime * result + deviceHeight; result += prime * result + uniqueId.hashCode(); result += prime * result + uniqueId.hashCode(); result += prime * result + physicalPort; if (physicalPort != null) { result += prime * result + physicalPort.hashCode(); } result += prime * result + type; result += prime * result + type; return result; return result; } } Loading @@ -142,11 +144,12 @@ public final class DisplayViewport { // For debugging purposes. // For debugging purposes. @Override @Override public String toString() { public String toString() { final Integer port = physicalPort == null ? null : Byte.toUnsignedInt(physicalPort); return "DisplayViewport{type=" + typeToString(type) return "DisplayViewport{type=" + typeToString(type) + ", valid=" + valid + ", valid=" + valid + ", displayId=" + displayId + ", displayId=" + displayId + ", uniqueId='" + uniqueId + "'" + ", uniqueId='" + uniqueId + "'" + ", physicalPort=" + physicalPort + ", physicalPort=" + port + ", orientation=" + orientation + ", orientation=" + orientation + ", logicalFrame=" + logicalFrame + ", logicalFrame=" + logicalFrame + ", physicalFrame=" + physicalFrame + ", physicalFrame=" + physicalFrame Loading
core/java/android/view/DisplayAddress.java +31 −3 Original line number Original line Diff line number Diff line Loading @@ -40,6 +40,18 @@ public abstract class DisplayAddress implements Parcelable { return new Physical(physicalDisplayId); return new Physical(physicalDisplayId); } } /** * Creates an address for a physical display given its port and model. * * @param port A port in the range [0, 255] interpreted as signed. * @param model A positive integer, or {@code null} if the model cannot be identified. * @return The {@link Physical} address. */ @NonNull public static Physical fromPortAndModel(byte port, Long model) { return new Physical(port, model); } /** /** * Creates an address for a network display given its MAC address. * Creates an address for a network display given its MAC address. * * Loading @@ -64,12 +76,23 @@ public abstract class DisplayAddress implements Parcelable { public static final class Physical extends DisplayAddress { public static final class Physical extends DisplayAddress { private static final long UNKNOWN_MODEL = 0; private static final long UNKNOWN_MODEL = 0; private static final int MODEL_SHIFT = 8; private static final int MODEL_SHIFT = 8; private static final int PORT_MASK = 0xFF; private final long mPhysicalDisplayId; private final long mPhysicalDisplayId; /** * Stable display ID combining port and model. * * @return An ID in the range [0, 2^64) interpreted as signed. * @see SurfaceControl#getPhysicalDisplayIds */ public long getPhysicalDisplayId() { return mPhysicalDisplayId; } /** /** * Physical port to which the display is connected. * Physical port to which the display is connected. * * @return A port in the range [0, 255] interpreted as signed. */ */ public byte getPort() { public byte getPort() { return (byte) mPhysicalDisplayId; return (byte) mPhysicalDisplayId; Loading @@ -78,7 +101,7 @@ public abstract class DisplayAddress implements Parcelable { /** /** * Model identifier unique across manufacturers. * Model identifier unique across manufacturers. * * * @return The model ID, or {@code null} if the model cannot be identified. * @return A positive integer, or {@code null} if the model cannot be identified. */ */ @Nullable @Nullable public Long getModel() { public Long getModel() { Loading @@ -95,7 +118,7 @@ public abstract class DisplayAddress implements Parcelable { @Override @Override public String toString() { public String toString() { final StringBuilder builder = new StringBuilder("{") final StringBuilder builder = new StringBuilder("{") .append("port=").append(getPort() & PORT_MASK); .append("port=").append(Byte.toUnsignedInt(getPort())); final Long model = getModel(); final Long model = getModel(); if (model != null) { if (model != null) { Loading @@ -119,6 +142,11 @@ public abstract class DisplayAddress implements Parcelable { mPhysicalDisplayId = physicalDisplayId; mPhysicalDisplayId = physicalDisplayId; } } private Physical(byte port, Long model) { mPhysicalDisplayId = Byte.toUnsignedLong(port) | (model == null ? UNKNOWN_MODEL : (model << MODEL_SHIFT)); } public static final @NonNull Parcelable.Creator<Physical> CREATOR = public static final @NonNull Parcelable.Creator<Physical> CREATOR = new Parcelable.Creator<Physical>() { new Parcelable.Creator<Physical>() { @Override @Override Loading
services/core/java/com/android/server/display/LocalDisplayAdapter.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -848,7 +848,7 @@ final class LocalDisplayAdapter extends DisplayAdapter { int[] ports = res.getIntArray( int[] ports = res.getIntArray( com.android.internal.R.array.config_localPrivateDisplayPorts); com.android.internal.R.array.config_localPrivateDisplayPorts); if (ports != null) { if (ports != null) { int port = physicalAddress.getPort(); int port = Byte.toUnsignedInt(physicalAddress.getPort()); for (int p : ports) { for (int p : ports) { if (p == port) { if (p == port) { return true; return true; Loading
services/core/java/com/android/server/wm/DisplayWindowSettings.java +2 −1 Original line number Original line Diff line number Diff line Loading @@ -642,7 +642,8 @@ class DisplayWindowSettings { if (mIdentifier == IDENTIFIER_PORT && displayInfo.address != null) { if (mIdentifier == IDENTIFIER_PORT && displayInfo.address != null) { // Config suggests using port as identifier for physical displays. // Config suggests using port as identifier for physical displays. if (displayInfo.address instanceof DisplayAddress.Physical) { if (displayInfo.address instanceof DisplayAddress.Physical) { return "port:" + ((DisplayAddress.Physical) displayInfo.address).getPort(); byte port = ((DisplayAddress.Physical) displayInfo.address).getPort(); return "port:" + Byte.toUnsignedInt(port); } } } } return displayInfo.uniqueId; return displayInfo.uniqueId; Loading
services/tests/mockingservicestests/src/com/android/server/display/LocalDisplayAdapterTest.java +38 −41 Original line number Original line Diff line number Diff line Loading @@ -53,9 +53,12 @@ import java.util.LinkedList; @SmallTest @SmallTest @RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class) public class LocalDisplayAdapterTest { public class LocalDisplayAdapterTest { private static final long HANDLER_WAIT_MS = 100; private static final Long DISPLAY_MODEL = Long.valueOf(0xAAAAAAAAL); private static final int PORT_A = 0; private static final int PORT_B = 0x80; private static final int PORT_C = 0xFF; private static final int PHYSICAL_DISPLAY_ID_MODEL_SHIFT = 8; private static final long HANDLER_WAIT_MS = 100; private StaticMockitoSession mMockitoSession; private StaticMockitoSession mMockitoSession; Loading @@ -74,7 +77,7 @@ public class LocalDisplayAdapterTest { private TestListener mListener = new TestListener(); private TestListener mListener = new TestListener(); private LinkedList<Long> mDisplayIds = new LinkedList<>(); private LinkedList<DisplayAddress.Physical> mAddresses = new LinkedList<>(); @Before @Before public void setUp() throws Exception { public void setUp() throws Exception { Loading Loading @@ -106,30 +109,22 @@ public class LocalDisplayAdapterTest { */ */ @Test @Test public void testPrivateDisplay() throws Exception { public void testPrivateDisplay() throws Exception { // needs default one always setUpDisplay(new DisplayConfig(createDisplayAddress(PORT_A), createDummyDisplayInfo())); final long displayId0 = 0; setUpDisplay(new DisplayConfig(createDisplayAddress(PORT_B), createDummyDisplayInfo())); setUpDisplay(new DisplayConfig(displayId0, createDummyDisplayInfo())); setUpDisplay(new DisplayConfig(createDisplayAddress(PORT_C), createDummyDisplayInfo())); final long displayId1 = 1; setUpDisplay(new DisplayConfig(displayId1, createDummyDisplayInfo())); final long displayId2 = 2; setUpDisplay(new DisplayConfig(displayId2, createDummyDisplayInfo())); updateAvailableDisplays(); updateAvailableDisplays(); // display 1 should be marked as private while display 2 is not. doReturn(new int[]{ PORT_B }).when(mMockedResources) doReturn(new int[]{(int) displayId1}).when(mMockedResources) .getIntArray(com.android.internal.R.array.config_localPrivateDisplayPorts); .getIntArray(com.android.internal.R.array.config_localPrivateDisplayPorts); mAdapter.registerLocked(); mAdapter.registerLocked(); waitForHandlerToComplete(mHandler, HANDLER_WAIT_MS); waitForHandlerToComplete(mHandler, HANDLER_WAIT_MS); // This should be public // This should be public assertDisplay(mListener.addedDisplays.get(0).getDisplayDeviceInfoLocked(), displayId0, assertDisplay(mListener.addedDisplays.get(0).getDisplayDeviceInfoLocked(), PORT_A, false); false); // This should be private // This should be private assertDisplay(mListener.addedDisplays.get(1).getDisplayDeviceInfoLocked(), displayId1, assertDisplay(mListener.addedDisplays.get(1).getDisplayDeviceInfoLocked(), PORT_B, true); true); // This should be public // This should be public assertDisplay(mListener.addedDisplays.get(2).getDisplayDeviceInfoLocked(), displayId2, assertDisplay(mListener.addedDisplays.get(2).getDisplayDeviceInfoLocked(), PORT_C, false); false); } } /** /** Loading @@ -137,11 +132,8 @@ public class LocalDisplayAdapterTest { */ */ @Test @Test public void testPublicDisplaysForNoConfigLocalPrivateDisplayPorts() throws Exception { public void testPublicDisplaysForNoConfigLocalPrivateDisplayPorts() throws Exception { // needs default one always setUpDisplay(new DisplayConfig(createDisplayAddress(PORT_A), createDummyDisplayInfo())); final long displayId0 = 0; setUpDisplay(new DisplayConfig(createDisplayAddress(PORT_C), createDummyDisplayInfo())); setUpDisplay(new DisplayConfig(displayId0, createDummyDisplayInfo())); final long displayId1 = 1; setUpDisplay(new DisplayConfig(displayId1, createDummyDisplayInfo())); updateAvailableDisplays(); updateAvailableDisplays(); // config_localPrivateDisplayPorts is null // config_localPrivateDisplayPorts is null mAdapter.registerLocked(); mAdapter.registerLocked(); Loading @@ -149,35 +141,36 @@ public class LocalDisplayAdapterTest { waitForHandlerToComplete(mHandler, HANDLER_WAIT_MS); waitForHandlerToComplete(mHandler, HANDLER_WAIT_MS); // This should be public // This should be public assertDisplay(mListener.addedDisplays.get(0).getDisplayDeviceInfoLocked(), displayId0, assertDisplay(mListener.addedDisplays.get(0).getDisplayDeviceInfoLocked(), PORT_A, false); false); // This should be public // This should be public assertDisplay(mListener.addedDisplays.get(1).getDisplayDeviceInfoLocked(), displayId1, assertDisplay(mListener.addedDisplays.get(1).getDisplayDeviceInfoLocked(), PORT_C, false); false); } } private void assertDisplay(DisplayDeviceInfo info, long expectedPort, boolean shouldBePrivate) { private static void assertDisplay( DisplayAddress.Physical physical = (DisplayAddress.Physical) info.address; DisplayDeviceInfo info, int expectedPort, boolean shouldBePrivate) { assertNotNull(physical); final DisplayAddress.Physical address = (DisplayAddress.Physical) info.address; assertEquals(expectedPort, physical.getPort()); assertNotNull(address); assertEquals((byte) expectedPort, address.getPort()); assertEquals(DISPLAY_MODEL, address.getModel()); assertEquals(shouldBePrivate, (info.flags & DisplayDeviceInfo.FLAG_PRIVATE) != 0); assertEquals(shouldBePrivate, (info.flags & DisplayDeviceInfo.FLAG_PRIVATE) != 0); } } private class DisplayConfig { private class DisplayConfig { public final long displayId; public final DisplayAddress.Physical address; public final IBinder displayToken = new Binder(); public final IBinder displayToken = new Binder(); public final SurfaceControl.PhysicalDisplayInfo displayInfo; public final SurfaceControl.PhysicalDisplayInfo displayInfo; private DisplayConfig(long displayId, SurfaceControl.PhysicalDisplayInfo displayInfo) { private DisplayConfig( this.displayId = displayId | (0x1 << PHYSICAL_DISPLAY_ID_MODEL_SHIFT); DisplayAddress.Physical address, SurfaceControl.PhysicalDisplayInfo displayInfo) { this.address = address; this.displayInfo = displayInfo; this.displayInfo = displayInfo; } } } } private void setUpDisplay(DisplayConfig config) { private void setUpDisplay(DisplayConfig config) { mDisplayIds.add(config.displayId); mAddresses.add(config.address); doReturn(config.displayToken).when( doReturn(config.displayToken).when(() -> () -> SurfaceControl.getPhysicalDisplayToken(config.displayId)); SurfaceControl.getPhysicalDisplayToken(config.address.getPhysicalDisplayId())); doReturn(new SurfaceControl.PhysicalDisplayInfo[]{ doReturn(new SurfaceControl.PhysicalDisplayInfo[]{ config.displayInfo config.displayInfo }).when(() -> SurfaceControl.getDisplayConfigs(config.displayToken)); }).when(() -> SurfaceControl.getDisplayConfigs(config.displayToken)); Loading @@ -192,16 +185,20 @@ public class LocalDisplayAdapterTest { } } private void updateAvailableDisplays() { private void updateAvailableDisplays() { long[] ids = new long[mDisplayIds.size()]; long[] ids = new long[mAddresses.size()]; int i = 0; int i = 0; for (long id : mDisplayIds) { for (DisplayAddress.Physical address : mAddresses) { ids[i] = id; ids[i] = address.getPhysicalDisplayId(); i++; i++; } } doReturn(ids).when(() -> SurfaceControl.getPhysicalDisplayIds()); doReturn(ids).when(() -> SurfaceControl.getPhysicalDisplayIds()); } } private SurfaceControl.PhysicalDisplayInfo createDummyDisplayInfo() { private static DisplayAddress.Physical createDisplayAddress(int port) { return DisplayAddress.fromPortAndModel((byte) port, DISPLAY_MODEL); } private static SurfaceControl.PhysicalDisplayInfo createDummyDisplayInfo() { SurfaceControl.PhysicalDisplayInfo info = new SurfaceControl.PhysicalDisplayInfo(); SurfaceControl.PhysicalDisplayInfo info = new SurfaceControl.PhysicalDisplayInfo(); info.density = 100; info.density = 100; info.xDpi = 100; info.xDpi = 100; Loading