From ebf4bdac942e9bea0b89f00f7b0c281fc8c048ce Mon Sep 17 00:00:00 2001 From: Thomas Makin Date: Fri, 27 Oct 2023 00:31:42 -0500 Subject: CEC: correct frameworks physicalAddress parsing The HIDL interface defines physical address as a uint16_t, but Java does not utilize unsigned types, so it represents this value as a standard 32-bit signed integer type. However, it extends the MSB to the full 32-bits instead of padding with zeroes, causing large values to be read as negative, crashing the service when HdmiPortInfo builder asserts >=0. This also clarifies a related comment likely sourced from the same incorrect assumption about how the parsing behaves. Co-authored-by: Thomas Makin Co-authored-by: Aaron Kling Change-Id: If101cf5a725315d75ea5315d4cf42c8d55fb7bec --- services/core/java/com/android/server/hdmi/HdmiCecController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/hdmi/HdmiCecController.java b/services/core/java/com/android/server/hdmi/HdmiCecController.java index 9087354dee40..3f89f236dfc3 100644 --- a/services/core/java/com/android/server/hdmi/HdmiCecController.java +++ b/services/core/java/com/android/server/hdmi/HdmiCecController.java @@ -347,7 +347,7 @@ final class HdmiCecController { * {@link HdmiCecNetwork} only. * * @return CEC physical address of the device. The range of success address - * is between 0x0000 and 0xFFFF. If failed it returns -1 + * is between 0x0000 and 0xFFFE. If failed it returns INVALID_PHYSICAL_ADDRESS. */ @ServiceThreadOnly int getPhysicalAddress() { @@ -1299,7 +1299,7 @@ final class HdmiCecController { hdmiPortInfo[i] = new HdmiPortInfo.Builder( portInfo.portId, portInfo.type, - portInfo.physicalAddress) + Short.toUnsignedInt(portInfo.physicalAddress)) .setCecSupported(portInfo.cecSupported) .setMhlSupported(false) .setArcSupported(portInfo.arcSupported) @@ -1496,7 +1496,7 @@ final class HdmiCecController { hdmiPortInfo[i] = new HdmiPortInfo.Builder( portInfo.portId, portInfo.type, - portInfo.physicalAddress) + Short.toUnsignedInt(portInfo.physicalAddress)) .setCecSupported(portInfo.cecSupported) .setMhlSupported(false) .setArcSupported(portInfo.arcSupported) -- cgit v1.2.3-59-g8ed1b