[RESTRICT AUTOMERGE] Add relative address to DeviceProductInfo.

This CL adds a field relativeAddress to DeviceProductInfo so it can
be surfaced in the framework. For HDMI connections the field is
populated with the physical address.

Bug: 147994746
Test: atest DisplayIdentificationTest
Change-Id: I2711407aa1be079df8086e233ee3f0cf90ba1741
diff --git a/libs/ui/include/ui/DeviceProductInfo.h b/libs/ui/include/ui/DeviceProductInfo.h
index c396e73..af00342 100644
--- a/libs/ui/include/ui/DeviceProductInfo.h
+++ b/libs/ui/include/ui/DeviceProductInfo.h
@@ -31,6 +31,10 @@
 // product information about the intermediate device.
 struct DeviceProductInfo {
     static constexpr size_t TEXT_BUFFER_SIZE = 20;
+    static constexpr size_t RELATIVE_ADDRESS_SIZE = 4;
+
+    using RelativeAddress = std::array<uint8_t, RELATIVE_ADDRESS_SIZE>;
+    static constexpr RelativeAddress NO_RELATIVE_ADDRESS = {0xff, 0xff, 0xff, 0xff};
 
     struct ModelYear {
         uint32_t year;
@@ -54,6 +58,11 @@
 
     using ManufactureOrModelDate = std::variant<ModelYear, ManufactureYear, ManufactureWeekAndYear>;
     ManufactureOrModelDate manufactureOrModelDate;
+
+    // Relative address in the display network. Unavailable address is indicated
+    // by all elements equal to 255.
+    // For example, for HDMI connected device this will be the physical address.
+    RelativeAddress relativeAddress;
 };
 
 } // namespace android
diff --git a/services/surfaceflinger/DisplayHardware/DisplayIdentification.cpp b/services/surfaceflinger/DisplayHardware/DisplayIdentification.cpp
index b6d904f..4dfc743 100644
--- a/services/surfaceflinger/DisplayHardware/DisplayIdentification.cpp
+++ b/services/surfaceflinger/DisplayHardware/DisplayIdentification.cpp
@@ -96,6 +96,12 @@
         info.manufactureOrModelDate = date;
     }
 
+    if (edid.cea861Block && edid.cea861Block->hdmiVendorDataBlock) {
+        const auto& address = edid.cea861Block->hdmiVendorDataBlock->physicalAddress;
+        info.relativeAddress = {address.a, address.b, address.c, address.d};
+    } else {
+        info.relativeAddress = DeviceProductInfo::NO_RELATIVE_ADDRESS;
+    }
     return info;
 }
 
diff --git a/services/surfaceflinger/DisplayHardware/DisplayIdentification.h b/services/surfaceflinger/DisplayHardware/DisplayIdentification.h
index fc2f72e..9e6c549 100644
--- a/services/surfaceflinger/DisplayHardware/DisplayIdentification.h
+++ b/services/surfaceflinger/DisplayHardware/DisplayIdentification.h
@@ -70,7 +70,7 @@
 };
 
 struct HdmiVendorDataBlock {
-    std::optional<HdmiPhysicalAddress> physicalAddress;
+    HdmiPhysicalAddress physicalAddress;
 };
 
 struct Cea861ExtensionBlock : ExtensionBlock {
diff --git a/services/surfaceflinger/tests/unittests/DisplayIdentificationTest.cpp b/services/surfaceflinger/tests/unittests/DisplayIdentificationTest.cpp
index cc11aa9..2a0e913 100644
--- a/services/surfaceflinger/tests/unittests/DisplayIdentificationTest.cpp
+++ b/services/surfaceflinger/tests/unittests/DisplayIdentificationTest.cpp
@@ -209,12 +209,11 @@
     EXPECT_EQ(41, edid->manufactureWeek);
     ASSERT_TRUE(edid->cea861Block);
     ASSERT_TRUE(edid->cea861Block->hdmiVendorDataBlock);
-    ASSERT_TRUE(edid->cea861Block->hdmiVendorDataBlock->physicalAddress);
     auto physicalAddress = edid->cea861Block->hdmiVendorDataBlock->physicalAddress;
-    EXPECT_EQ(2, physicalAddress->a);
-    EXPECT_EQ(0, physicalAddress->b);
-    EXPECT_EQ(0, physicalAddress->c);
-    EXPECT_EQ(0, physicalAddress->d);
+    EXPECT_EQ(2, physicalAddress.a);
+    EXPECT_EQ(0, physicalAddress.b);
+    EXPECT_EQ(0, physicalAddress.c);
+    EXPECT_EQ(0, physicalAddress.d);
 
     edid = parseEdid(getPanasonicTvEdid());
     ASSERT_TRUE(edid);
@@ -227,12 +226,11 @@
     EXPECT_EQ(0, edid->manufactureWeek);
     ASSERT_TRUE(edid->cea861Block);
     ASSERT_TRUE(edid->cea861Block->hdmiVendorDataBlock);
-    ASSERT_TRUE(edid->cea861Block->hdmiVendorDataBlock->physicalAddress);
     physicalAddress = edid->cea861Block->hdmiVendorDataBlock->physicalAddress;
-    EXPECT_EQ(2, physicalAddress->a);
-    EXPECT_EQ(0, physicalAddress->b);
-    EXPECT_EQ(0, physicalAddress->c);
-    EXPECT_EQ(0, physicalAddress->d);
+    EXPECT_EQ(2, physicalAddress.a);
+    EXPECT_EQ(0, physicalAddress.b);
+    EXPECT_EQ(0, physicalAddress.c);
+    EXPECT_EQ(0, physicalAddress.d);
 
     edid = parseEdid(getHisenseTvEdid());
     ASSERT_TRUE(edid);
@@ -245,12 +243,11 @@
     EXPECT_EQ(18, edid->manufactureWeek);
     ASSERT_TRUE(edid->cea861Block);
     ASSERT_TRUE(edid->cea861Block->hdmiVendorDataBlock);
-    ASSERT_TRUE(edid->cea861Block->hdmiVendorDataBlock->physicalAddress);
     physicalAddress = edid->cea861Block->hdmiVendorDataBlock->physicalAddress;
-    EXPECT_EQ(1, physicalAddress->a);
-    EXPECT_EQ(2, physicalAddress->b);
-    EXPECT_EQ(3, physicalAddress->c);
-    EXPECT_EQ(4, physicalAddress->d);
+    EXPECT_EQ(1, physicalAddress.a);
+    EXPECT_EQ(2, physicalAddress.b);
+    EXPECT_EQ(3, physicalAddress.c);
+    EXPECT_EQ(4, physicalAddress.d);
 
     edid = parseEdid(getCtlDisplayEdid());
     ASSERT_TRUE(edid);
@@ -315,6 +312,7 @@
     using ManufactureYear = DeviceProductInfo::ManufactureYear;
     using ManufactureWeekAndYear = DeviceProductInfo::ManufactureWeekAndYear;
     using ModelYear = DeviceProductInfo::ModelYear;
+    using RelativeAddress = DeviceProductInfo::RelativeAddress;
 
     {
         const auto displayIdInfo = parseDisplayIdentificationData(0, getInternalEdid());
@@ -326,6 +324,7 @@
         EXPECT_STREQ("12610", info.productId.data());
         ASSERT_TRUE(std::holds_alternative<ManufactureYear>(info.manufactureOrModelDate));
         EXPECT_EQ(2011, std::get<ManufactureYear>(info.manufactureOrModelDate).year);
+        EXPECT_EQ(DeviceProductInfo::NO_RELATIVE_ADDRESS, info.relativeAddress);
     }
     {
         const auto displayIdInfo = parseDisplayIdentificationData(0, getExternalEdid());
@@ -339,6 +338,7 @@
         const auto& date = std::get<ManufactureWeekAndYear>(info.manufactureOrModelDate);
         EXPECT_EQ(2012, date.year);
         EXPECT_EQ(2, date.week);
+        EXPECT_EQ(DeviceProductInfo::NO_RELATIVE_ADDRESS, info.relativeAddress);
     }
     {
         const auto displayIdInfo = parseDisplayIdentificationData(0, getExternalEedid());
@@ -352,6 +352,7 @@
         const auto& date = std::get<ManufactureWeekAndYear>(info.manufactureOrModelDate);
         EXPECT_EQ(2011, date.year);
         EXPECT_EQ(41, date.week);
+        EXPECT_EQ((RelativeAddress{{2, 0, 0, 0}}), info.relativeAddress);
     }
     {
         const auto displayIdInfo = parseDisplayIdentificationData(0, getPanasonicTvEdid());
@@ -364,6 +365,7 @@
         ASSERT_TRUE(std::holds_alternative<ManufactureYear>(info.manufactureOrModelDate));
         const auto& date = std::get<ManufactureYear>(info.manufactureOrModelDate);
         EXPECT_EQ(2019, date.year);
+        EXPECT_EQ((RelativeAddress{{2, 0, 0, 0}}), info.relativeAddress);
     }
     {
         const auto displayIdInfo = parseDisplayIdentificationData(0, getHisenseTvEdid());
@@ -377,6 +379,7 @@
         const auto& date = std::get<ManufactureWeekAndYear>(info.manufactureOrModelDate);
         EXPECT_EQ(2019, date.year);
         EXPECT_EQ(18, date.week);
+        EXPECT_EQ((RelativeAddress{{1, 2, 3, 4}}), info.relativeAddress);
     }
     {
         const auto displayIdInfo = parseDisplayIdentificationData(0, getCtlDisplayEdid());
@@ -388,6 +391,7 @@
         EXPECT_STREQ("9373", info.productId.data());
         ASSERT_TRUE(std::holds_alternative<ModelYear>(info.manufactureOrModelDate));
         EXPECT_EQ(2013, std::get<ModelYear>(info.manufactureOrModelDate).year);
+        EXPECT_EQ(DeviceProductInfo::NO_RELATIVE_ADDRESS, info.relativeAddress);
     }
 }