diff options
author | 2024-11-13 16:53:33 -0500 | |
---|---|---|
committer | 2024-11-16 01:30:59 -0500 | |
commit | c37c90444774da117f8a4eef14b091f0a54086f2 (patch) | |
tree | 9d4bea5da983aef37450e238b2f44add9c79db5b /libs/ui/DisplayIdentification.cpp | |
parent | 3e96f94d2cda8e5c9180e116aac6c57537fb970c (diff) |
SF: Parse, hash, and cache block 0 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 bytes 12-15
of block 0 in the EDID blob, 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: 378923334
Test: DisplayIdentification_test
Change-Id: I8e5c79f2f51c2fd2085dfaba7f5c45fbc698cbcb
Diffstat (limited to 'libs/ui/DisplayIdentification.cpp')
-rw-r--r-- | libs/ui/DisplayIdentification.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/libs/ui/DisplayIdentification.cpp b/libs/ui/DisplayIdentification.cpp index 503f92ff32..5cdaa71627 100644 --- a/libs/ui/DisplayIdentification.cpp +++ b/libs/ui/DisplayIdentification.cpp @@ -19,9 +19,12 @@ #include <algorithm> #include <cctype> +#include <cstdint> #include <numeric> #include <optional> #include <span> +#include <string> +#include <string_view> #include <ftl/hash.h> #include <log/log.h> @@ -194,6 +197,21 @@ std::optional<Edid> parseEdid(const DisplayIdentificationData& edid) { const uint16_t productId = static_cast<uint16_t>(edid[kProductIdOffset] | (edid[kProductIdOffset + 1] << 8)); + // Bytes 12-15: display serial number, in little-endian (LSB). This field is + // optional and its absence is marked by having all bytes set to 0x00. + // Values do not represent ASCII characters. + constexpr size_t kSerialNumberOffset = 12; + if (edid.size() < kSerialNumberOffset + sizeof(uint32_t)) { + ALOGE("Invalid EDID: block zero S/N is truncated."); + return {}; + } + const uint32_t blockZeroSerialNumber = edid[kSerialNumberOffset] + + (edid[kSerialNumberOffset + 1] << 8) + (edid[kSerialNumberOffset + 2] << 16) + + (edid[kSerialNumberOffset + 3] << 24); + const auto hashedBlockZeroSNOpt = blockZeroSerialNumber == 0 + ? std::nullopt + : ftl::stable_hash(std::string_view(std::to_string(blockZeroSerialNumber))); + constexpr size_t kManufactureWeekOffset = 16; if (edid.size() < kManufactureWeekOffset + sizeof(uint8_t)) { ALOGE("Invalid EDID: manufacture week is truncated."); @@ -350,6 +368,7 @@ std::optional<Edid> parseEdid(const DisplayIdentificationData& edid) { return Edid{ .manufacturerId = manufacturerId, .productId = productId, + .hashedBlockZeroSerialNumberOpt = hashedBlockZeroSNOpt, .pnpId = *pnpId, .modelHash = modelHash, .displayName = displayName, |