diff --git a/core/java/android/hardware/display/DisplayViewport.java b/core/java/android/hardware/display/DisplayViewport.java index 5adf948de348f..d2c2824d7cf8c 100644 --- a/core/java/android/hardware/display/DisplayViewport.java +++ b/core/java/android/hardware/display/DisplayViewport.java @@ -24,6 +24,7 @@ import android.graphics.Rect; import android.text.TextUtils; import java.lang.annotation.Retention; +import java.util.Objects; /** * Describes how the pixels of physical display device reflects the content of @@ -73,7 +74,7 @@ public final class DisplayViewport { public String uniqueId; // The physical port that the associated display device is connected to. - public @Nullable Byte physicalPort; + public @Nullable Integer physicalPort; public @ViewportType int type; @@ -118,7 +119,7 @@ public final class DisplayViewport { && deviceWidth == other.deviceWidth && deviceHeight == other.deviceHeight && TextUtils.equals(uniqueId, other.uniqueId) - && physicalPort == other.physicalPort + && Objects.equals(physicalPort, other.physicalPort) && type == other.type; } @@ -144,12 +145,11 @@ public final class DisplayViewport { // For debugging purposes. @Override public String toString() { - final Integer port = physicalPort == null ? null : Byte.toUnsignedInt(physicalPort); return "DisplayViewport{type=" + typeToString(type) + ", valid=" + valid + ", displayId=" + displayId + ", uniqueId='" + uniqueId + "'" - + ", physicalPort=" + port + + ", physicalPort=" + physicalPort + ", orientation=" + orientation + ", logicalFrame=" + logicalFrame + ", physicalFrame=" + physicalFrame diff --git a/core/java/android/view/DisplayAddress.java b/core/java/android/view/DisplayAddress.java index e0d9a4dd1df05..92f1adcd928b7 100644 --- a/core/java/android/view/DisplayAddress.java +++ b/core/java/android/view/DisplayAddress.java @@ -43,12 +43,12 @@ public abstract class DisplayAddress implements Parcelable { /** * 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 port A port in the range [0, 255]. * @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) { + public static Physical fromPortAndModel(int port, Long model) { return new Physical(port, model); } @@ -92,10 +92,10 @@ public abstract class DisplayAddress implements Parcelable { /** * Physical port to which the display is connected. * - * @return A port in the range [0, 255] interpreted as signed. + * @return A port in the range [0, 255]. */ - public byte getPort() { - return (byte) mPhysicalDisplayId; + public int getPort() { + return (int) (mPhysicalDisplayId & 0xFF); } /** @@ -118,7 +118,7 @@ public abstract class DisplayAddress implements Parcelable { @Override public String toString() { final StringBuilder builder = new StringBuilder("{") - .append("port=").append(Byte.toUnsignedInt(getPort())); + .append("port=").append(getPort()); final Long model = getModel(); if (model != null) { @@ -142,8 +142,11 @@ public abstract class DisplayAddress implements Parcelable { mPhysicalDisplayId = physicalDisplayId; } - private Physical(byte port, Long model) { - mPhysicalDisplayId = Byte.toUnsignedLong(port) + private Physical(int port, Long model) { + if (port < 0 || port > 255) { + throw new IllegalArgumentException("The port should be in the interval [0, 255]"); + } + mPhysicalDisplayId = Integer.toUnsignedLong(port) | (model == null ? UNKNOWN_MODEL : (model << MODEL_SHIFT)); } diff --git a/core/jni/android_hardware_display_DisplayViewport.cpp b/core/jni/android_hardware_display_DisplayViewport.cpp index e74aafe61e004..ed3e71996a8ed 100644 --- a/core/jni/android_hardware_display_DisplayViewport.cpp +++ b/core/jni/android_hardware_display_DisplayViewport.cpp @@ -55,8 +55,8 @@ static struct { status_t android_hardware_display_DisplayViewport_toNative(JNIEnv* env, jobject viewportObj, DisplayViewport* viewport) { - static const jclass byteClass = FindClassOrDie(env, "java/lang/Byte"); - static const jmethodID byteValue = env->GetMethodID(byteClass, "byteValue", "()B"); + static const jclass intClass = FindClassOrDie(env, "java/lang/Integer"); + static const jmethodID byteValue = env->GetMethodID(intClass, "byteValue", "()B"); viewport->displayId = env->GetIntField(viewportObj, gDisplayViewportClassInfo.displayId); viewport->orientation = env->GetIntField(viewportObj, gDisplayViewportClassInfo.orientation); @@ -122,8 +122,8 @@ int register_android_hardware_display_DisplayViewport(JNIEnv* env) { gDisplayViewportClassInfo.uniqueId = GetFieldIDOrDie(env, gDisplayViewportClassInfo.clazz, "uniqueId", "Ljava/lang/String;"); - gDisplayViewportClassInfo.physicalPort = GetFieldIDOrDie(env, - gDisplayViewportClassInfo.clazz, "physicalPort", "Ljava/lang/Byte;"); + gDisplayViewportClassInfo.physicalPort = GetFieldIDOrDie(env, gDisplayViewportClassInfo.clazz, + "physicalPort", "Ljava/lang/Integer;"); gDisplayViewportClassInfo.type = GetFieldIDOrDie(env, gDisplayViewportClassInfo.clazz, "type", "I"); diff --git a/services/core/java/com/android/server/display/LocalDisplayAdapter.java b/services/core/java/com/android/server/display/LocalDisplayAdapter.java index 6132467103a9c..1e830e3436fc0 100644 --- a/services/core/java/com/android/server/display/LocalDisplayAdapter.java +++ b/services/core/java/com/android/server/display/LocalDisplayAdapter.java @@ -987,7 +987,7 @@ final class LocalDisplayAdapter extends DisplayAdapter { int[] ports = res.getIntArray( com.android.internal.R.array.config_localPrivateDisplayPorts); if (ports != null) { - int port = Byte.toUnsignedInt(physicalAddress.getPort()); + int port = physicalAddress.getPort(); for (int p : ports) { if (p == port) { return true; diff --git a/services/core/java/com/android/server/wm/DisplayWindowSettings.java b/services/core/java/com/android/server/wm/DisplayWindowSettings.java index 470a02e5bd449..df7c07055e87b 100644 --- a/services/core/java/com/android/server/wm/DisplayWindowSettings.java +++ b/services/core/java/com/android/server/wm/DisplayWindowSettings.java @@ -642,8 +642,7 @@ class DisplayWindowSettings { if (mIdentifier == IDENTIFIER_PORT && displayInfo.address != null) { // Config suggests using port as identifier for physical displays. if (displayInfo.address instanceof DisplayAddress.Physical) { - byte port = ((DisplayAddress.Physical) displayInfo.address).getPort(); - return "port:" + Byte.toUnsignedInt(port); + return "port:" + ((DisplayAddress.Physical) displayInfo.address).getPort(); } } return displayInfo.uniqueId; diff --git a/services/tests/mockingservicestests/src/com/android/server/display/LocalDisplayAdapterTest.java b/services/tests/mockingservicestests/src/com/android/server/display/LocalDisplayAdapterTest.java index 6d15302193726..e208cd7d4e591 100644 --- a/services/tests/mockingservicestests/src/com/android/server/display/LocalDisplayAdapterTest.java +++ b/services/tests/mockingservicestests/src/com/android/server/display/LocalDisplayAdapterTest.java @@ -161,7 +161,7 @@ public class LocalDisplayAdapterTest { DisplayDeviceInfo info, int expectedPort, boolean shouldBePrivate) { final DisplayAddress.Physical address = (DisplayAddress.Physical) info.address; assertNotNull(address); - assertEquals((byte) expectedPort, address.getPort()); + assertEquals(expectedPort, address.getPort()); assertEquals(DISPLAY_MODEL, address.getModel()); assertEquals(shouldBePrivate, (info.flags & DisplayDeviceInfo.FLAG_PRIVATE) != 0); } @@ -254,7 +254,7 @@ public class LocalDisplayAdapterTest { int expectedDensityDpi) { final DisplayAddress.Physical physical = (DisplayAddress.Physical) info.address; assertNotNull(physical); - assertEquals((byte) expectedPort, physical.getPort()); + assertEquals(expectedPort, physical.getPort()); assertEquals(expectedXdpi, info.xDpi, 0.01); assertEquals(expectedYDpi, info.yDpi, 0.01); assertEquals(expectedDensityDpi, info.densityDpi); @@ -323,7 +323,7 @@ public class LocalDisplayAdapterTest { } private static DisplayAddress.Physical createDisplayAddress(int port) { - return DisplayAddress.fromPortAndModel((byte) port, DISPLAY_MODEL); + return DisplayAddress.fromPortAndModel(port, DISPLAY_MODEL); } private static SurfaceControl.DisplayInfo createFakeDisplayInfo() { diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayWindowSettingsTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayWindowSettingsTests.java index 856641228d806..11c02c26ca97e 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayWindowSettingsTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayWindowSettingsTests.java @@ -80,7 +80,7 @@ import java.nio.charset.StandardCharsets; @RunWith(WindowTestRunner.class) public class DisplayWindowSettingsTests extends WindowTestsBase { - private static final byte DISPLAY_PORT = (byte) 0xFF; + private static final int DISPLAY_PORT = 0xFF; private static final long DISPLAY_MODEL = 0xEEEEEEEEL; private static final File TEST_FOLDER = getInstrumentation().getTargetContext().getCacheDir(); @@ -486,7 +486,7 @@ public class DisplayWindowSettingsTests extends WindowTestsBase { DisplayAddress.fromPortAndModel(DISPLAY_PORT, DISPLAY_MODEL); mPrimaryDisplay.getDisplayInfo().address = displayAddress; - final String displayIdentifier = "port:" + Byte.toUnsignedInt(DISPLAY_PORT); + final String displayIdentifier = "port:" + DISPLAY_PORT; prepareDisplaySettings(displayIdentifier, true /* usePortAsId */); readAndAssertDisplaySettings(mPrimaryDisplay); @@ -537,7 +537,7 @@ public class DisplayWindowSettingsTests extends WindowTestsBase { assertTrue(mStorage.wasWriteSuccessful()); // Verify that settings were stored correctly. - assertEquals("Attribute value must be stored", "port:" + Byte.toUnsignedInt(DISPLAY_PORT), + assertEquals("Attribute value must be stored", "port:" + DISPLAY_PORT, getStoredDisplayAttributeValue("name")); assertEquals("Attribute value must be stored", "true", getStoredDisplayAttributeValue("shouldShowSystemDecors"));