summaryrefslogtreecommitdiff
path: root/core/java/android/view/DisplayAddress.java
diff options
context:
space:
mode:
authorMarin Shalamanov <shalamanov@google.com>2020-04-24 17:33:59 +0200
committerMarin Shalamanov <shalamanov@google.com>2020-04-27 22:11:29 +0200
commit41cb66fa00d112fe7a45e81a1ef14d69c4e70e3c (patch)
treeff03dac71c0dfd0604cf7502618fdf1a3bcee49f /core/java/android/view/DisplayAddress.java
parent793137aba170b3ba7bebd355b72256121b3f72f2 (diff)
Change the type of display port from byte to int
Using byte for display port is error prone since ports are in the range [0, 255] and bytes have the range [-128, 127]. This way we need to downcast from int to byte in order to write a value to display port and also we need to call Byte.toUnsignedInt every time we want to consume it. Test: m services Bug: 153334857 Change-Id: I4dce87c0a411c5d447f62cc5564eb4b8a8fb75f0
Diffstat (limited to 'core/java/android/view/DisplayAddress.java')
-rw-r--r--core/java/android/view/DisplayAddress.java19
1 files changed, 11 insertions, 8 deletions
diff --git a/core/java/android/view/DisplayAddress.java b/core/java/android/view/DisplayAddress.java
index e0d9a4dd1df0..92f1adcd928b 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));
}