Skip to content

Commit f9854d2

Browse files
committed
SF: Hash and cache descriptor block serial number
More EDID fields are required as a part of migrating to EDID-based display IDs. This CL parses the device's serial number from the serial number descriptor bloc, (depicted by the FF marker), hashes it using a stable hash, and serves it as a part of the Edid struct. Later, amongst others, this value will be used to fabricate a unique display ID that is based on the display's EDID. See: 1. EDID spec: https://glenwing.github.io/docs/VESA-EEDID-A2.pdf 2. https://en.wikipedia.org/wiki/Extended_Display_Identification_Data#Structure,_version_1.4 Flag: com.android.graphics.surfaceflinger.flags.stable_edid_ids Bug: 378923759 Test: DisplayIdentification_test Change-Id: If9c9358b0d0850337496740d15419fd0ed330a02
1 parent c37c904 commit f9854d2

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

libs/ui/DisplayIdentification.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ std::optional<Edid> parseEdid(const DisplayIdentificationData& edid) {
249249
view = view.subspan(kDescriptorOffset);
250250

251251
std::string_view displayName;
252-
std::string_view serialNumber;
252+
std::string_view descriptorBlockSerialNumber;
253+
std::optional<uint64_t> hashedDescriptorBlockSNOpt = std::nullopt;
253254
std::string_view asciiText;
254255
ui::Size preferredDTDPixelSize;
255256
ui::Size preferredDTDPhysicalSize;
@@ -274,7 +275,10 @@ std::optional<Edid> parseEdid(const DisplayIdentificationData& edid) {
274275
asciiText = parseEdidText(descriptor);
275276
break;
276277
case 0xff:
277-
serialNumber = parseEdidText(descriptor);
278+
descriptorBlockSerialNumber = parseEdidText(descriptor);
279+
hashedDescriptorBlockSNOpt = descriptorBlockSerialNumber.empty()
280+
? std::nullopt
281+
: ftl::stable_hash(descriptorBlockSerialNumber);
278282
break;
279283
}
280284
} else if (isDetailedTimingDescriptor(view)) {
@@ -315,7 +319,7 @@ std::optional<Edid> parseEdid(const DisplayIdentificationData& edid) {
315319

316320
if (modelString.empty()) {
317321
ALOGW("Invalid EDID: falling back to serial number due to missing display name.");
318-
modelString = serialNumber;
322+
modelString = descriptorBlockSerialNumber;
319323
}
320324
if (modelString.empty()) {
321325
ALOGW("Invalid EDID: falling back to ASCII text due to missing serial number.");
@@ -369,6 +373,7 @@ std::optional<Edid> parseEdid(const DisplayIdentificationData& edid) {
369373
.manufacturerId = manufacturerId,
370374
.productId = productId,
371375
.hashedBlockZeroSerialNumberOpt = hashedBlockZeroSNOpt,
376+
.hashedDescriptorBlockSerialNumberOpt = hashedDescriptorBlockSNOpt,
372377
.pnpId = *pnpId,
373378
.modelHash = modelHash,
374379
.displayName = displayName,

libs/ui/include/ui/DisplayIdentification.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ struct Edid {
7070
uint16_t manufacturerId;
7171
uint16_t productId;
7272
std::optional<uint64_t> hashedBlockZeroSerialNumberOpt;
73+
std::optional<uint64_t> hashedDescriptorBlockSerialNumberOpt;
7374
PnpId pnpId;
7475
uint32_t modelHash;
7576
std::string_view displayName;

libs/ui/tests/DisplayIdentification_test.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ TEST(DisplayIdentificationTest, parseEdid) {
193193
EXPECT_EQ(12610, edid->productId);
194194
EXPECT_TRUE(edid->hashedBlockZeroSerialNumberOpt.has_value());
195195
EXPECT_EQ(ftl::stable_hash("12345678"), edid->hashedBlockZeroSerialNumberOpt.value());
196+
EXPECT_FALSE(edid->hashedDescriptorBlockSerialNumberOpt.has_value());
196197
EXPECT_EQ(21, edid->manufactureOrModelYear);
197198
EXPECT_EQ(0, edid->manufactureWeek);
198199
EXPECT_EQ(26, edid->physicalSizeInCm.width);
@@ -213,6 +214,8 @@ TEST(DisplayIdentificationTest, parseEdid) {
213214
EXPECT_EQ(10348, edid->productId);
214215
EXPECT_TRUE(edid->hashedBlockZeroSerialNumberOpt.has_value());
215216
EXPECT_EQ(ftl::stable_hash("16843009"), edid->hashedBlockZeroSerialNumberOpt.value());
217+
EXPECT_TRUE(edid->hashedDescriptorBlockSerialNumberOpt.has_value());
218+
EXPECT_EQ(ftl::stable_hash("CN4202137Q"), edid->hashedDescriptorBlockSerialNumberOpt.value());
216219
EXPECT_EQ(22, edid->manufactureOrModelYear);
217220
EXPECT_EQ(2, edid->manufactureWeek);
218221
EXPECT_EQ(64, edid->physicalSizeInCm.width);
@@ -233,6 +236,7 @@ TEST(DisplayIdentificationTest, parseEdid) {
233236
EXPECT_EQ(2302, edid->productId);
234237
EXPECT_TRUE(edid->hashedBlockZeroSerialNumberOpt.has_value());
235238
EXPECT_EQ(ftl::stable_hash("87654321"), edid->hashedBlockZeroSerialNumberOpt.value());
239+
EXPECT_FALSE(edid->hashedDescriptorBlockSerialNumberOpt.has_value());
236240
EXPECT_EQ(21, edid->manufactureOrModelYear);
237241
EXPECT_EQ(41, edid->manufactureWeek);
238242
EXPECT_EQ(16, edid->physicalSizeInCm.width);
@@ -259,6 +263,7 @@ TEST(DisplayIdentificationTest, parseEdid) {
259263
EXPECT_EQ(41622, edid->productId);
260264
EXPECT_TRUE(edid->hashedBlockZeroSerialNumberOpt.has_value());
261265
EXPECT_EQ(ftl::stable_hash("16843009"), edid->hashedBlockZeroSerialNumberOpt.value());
266+
EXPECT_FALSE(edid->hashedDescriptorBlockSerialNumberOpt.has_value());
262267
EXPECT_EQ(29, edid->manufactureOrModelYear);
263268
EXPECT_EQ(0, edid->manufactureWeek);
264269
EXPECT_EQ(128, edid->physicalSizeInCm.width);
@@ -284,6 +289,7 @@ TEST(DisplayIdentificationTest, parseEdid) {
284289
EXPECT_EQ("Hisense", edid->displayName);
285290
EXPECT_EQ(0, edid->productId);
286291
EXPECT_FALSE(edid->hashedBlockZeroSerialNumberOpt.has_value());
292+
EXPECT_FALSE(edid->hashedDescriptorBlockSerialNumberOpt.has_value());
287293
EXPECT_EQ(29, edid->manufactureOrModelYear);
288294
EXPECT_EQ(18, edid->manufactureWeek);
289295
EXPECT_EQ(0, edid->physicalSizeInCm.width);
@@ -310,6 +316,7 @@ TEST(DisplayIdentificationTest, parseEdid) {
310316
EXPECT_EQ(9373, edid->productId);
311317
EXPECT_TRUE(edid->hashedBlockZeroSerialNumberOpt.has_value());
312318
EXPECT_EQ(ftl::stable_hash("11223344"), edid->hashedBlockZeroSerialNumberOpt.value());
319+
EXPECT_FALSE(edid->hashedDescriptorBlockSerialNumberOpt.has_value());
313320
EXPECT_EQ(23, edid->manufactureOrModelYear);
314321
EXPECT_EQ(0xff, edid->manufactureWeek);
315322
EXPECT_EQ(52, edid->physicalSizeInCm.width);

0 commit comments

Comments
 (0)