1 /*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 // TODO(b/129481165): remove the #pragma below and fix conversion issues
18 #pragma clang diagnostic push
19 #pragma clang diagnostic ignored "-Wextra"
20
21 #include <functional>
22 #include <string_view>
23
24 #include <ftl/hash.h>
25 #include <gmock/gmock.h>
26 #include <gtest/gtest.h>
27 #include <ui/DisplayIdentification.h>
28
29 using ::testing::ElementsAre;
30
31 namespace android {
32
33 namespace {
34
35 const unsigned char kInternalEdid[] =
36 "\x00\xff\xff\xff\xff\xff\xff\x00\x4c\xa3\x42\x31\x4e\x61\xbc\x00"
37 "\x00\x15\x01\x03\x80\x1a\x10\x78\x0a\xd3\xe5\x95\x5c\x60\x90\x27"
38 "\x19\x50\x54\x00\x00\x00\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"
39 "\x01\x01\x01\x01\x01\x01\x9e\x1b\x00\xa0\x50\x20\x12\x30\x10\x30"
40 "\x13\x00\x05\xa3\x10\x00\x00\x19\x00\x00\x00\x0f\x00\x00\x00\x00"
41 "\x00\x00\x00\x00\x00\x23\x87\x02\x64\x00\x00\x00\x00\xfe\x00\x53"
42 "\x41\x4d\x53\x55\x4e\x47\x0a\x20\x20\x20\x20\x20\x00\x00\x00\xfe"
43 "\x00\x31\x32\x31\x41\x54\x31\x31\x2d\x38\x30\x31\x0a\x20\x00\x45";
44
45 const unsigned char kExternalEdid[] =
46 "\x00\xff\xff\xff\xff\xff\xff\x00\x22\xf0\x6c\x28\x01\x01\x01\x01"
47 "\x02\x16\x01\x04\xb5\x40\x28\x78\xe2\x8d\x85\xad\x4f\x35\xb1\x25"
48 "\x0e\x50\x54\x00\x00\x00\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"
49 "\x01\x01\x01\x01\x01\x01\xe2\x68\x00\xa0\xa0\x40\x2e\x60\x30\x20"
50 "\x36\x00\x81\x90\x21\x00\x00\x1a\xbc\x1b\x00\xa0\x50\x20\x17\x30"
51 "\x30\x20\x36\x00\x81\x90\x21\x00\x00\x1a\x00\x00\x00\xfc\x00\x48"
52 "\x50\x20\x5a\x52\x33\x30\x77\x0a\x20\x20\x20\x20\x00\x00\x00\xff"
53 "\x00\x43\x4e\x34\x32\x30\x32\x31\x33\x37\x51\x0a\x20\x20\x00\x71";
54
55 // Extended EDID with timing extension.
56 const unsigned char kExternalEedid[] =
57 "\x00\xff\xff\xff\xff\xff\xff\x00\x4c\x2d\xfe\x08\xb1\x7f\x39\x05"
58 "\x29\x15\x01\x03\x80\x10\x09\x78\x0a\xee\x91\xa3\x54\x4c\x99\x26"
59 "\x0f\x50\x54\xbd\xef\x80\x71\x4f\x81\xc0\x81\x00\x81\x80\x95\x00"
60 "\xa9\xc0\xb3\x00\x01\x01\x02\x3a\x80\x18\x71\x38\x2d\x40\x58\x2c"
61 "\x45\x00\xa0\x5a\x00\x00\x00\x1e\x66\x21\x56\xaa\x51\x00\x1e\x30"
62 "\x46\x8f\x33\x00\xa0\x5a\x00\x00\x00\x1e\x00\x00\x00\xfd\x00\x18"
63 "\x4b\x0f\x51\x17\x00\x0a\x20\x20\x20\x20\x20\x20\x00\x00\x00\xfc"
64 "\x00\x53\x41\x4d\x53\x55\x4e\x47\x0a\x20\x20\x20\x20\x20\x01\x1d"
65 "\x02\x03\x1f\xf1\x47\x90\x04\x05\x03\x20\x22\x07\x23\x09\x07\x07"
66 "\x83\x01\x00\x00\xe2\x00\x0f\x67\x03\x0c\x00\x20\x00\xb8\x2d\x01"
67 "\x1d\x80\x18\x71\x1c\x16\x20\x58\x2c\x25\x00\xa0\x5a\x00\x00\x00"
68 "\x9e\x01\x1d\x00\x72\x51\xd0\x1e\x20\x6e\x28\x55\x00\xa0\x5a\x00"
69 "\x00\x00\x1e\x8c\x0a\xd0\x8a\x20\xe0\x2d\x10\x10\x3e\x96\x00\xa0"
70 "\x5a\x00\x00\x00\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
71 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
72 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc6";
73
74 const unsigned char kPanasonicTvEdid[] =
75 "\x00\xff\xff\xff\xff\xff\xff\x00\x34\xa9\x96\xa2\x01\x01\x01"
76 "\x01\x00\x1d\x01\x03\x80\x80\x48\x78\x0a\xda\xff\xa3\x58\x4a"
77 "\xa2\x29\x17\x49\x4b\x20\x08\x00\x31\x40\x61\x40\x01\x01\x01"
78 "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x08\xe8\x00\x30\xf2\x70"
79 "\x5a\x80\xb0\x58\x8a\x00\xba\x88\x21\x00\x00\x1e\x02\x3a\x80"
80 "\x18\x71\x38\x2d\x40\x58\x2c\x45\x00\xba\x88\x21\x00\x00\x1e"
81 "\x00\x00\x00\xfc\x00\x50\x61\x6e\x61\x73\x6f\x6e\x69\x63\x2d"
82 "\x54\x56\x0a\x00\x00\x00\xfd\x00\x17\x3d\x0f\x88\x3c\x00\x0a"
83 "\x20\x20\x20\x20\x20\x20\x01\x1d\x02\x03\x6b\xf0\x57\x61\x60"
84 "\x10\x1f\x66\x65\x05\x14\x20\x21\x22\x04\x13\x03\x12\x07\x16"
85 "\x5d\x5e\x5f\x62\x63\x64\x2c\x0d\x07\x01\x15\x07\x50\x57\x07"
86 "\x01\x67\x04\x03\x83\x0f\x00\x00\x6e\x03\x0c\x00\x20\x00\x38"
87 "\x3c\x2f\x08\x80\x01\x02\x03\x04\x67\xd8\x5d\xc4\x01\x78\x80"
88 "\x03\xe2\x00\x4b\xe3\x05\xff\x01\xe2\x0f\x33\xe3\x06\x0f\x01"
89 "\xe5\x01\x8b\x84\x90\x01\xeb\x01\x46\xd0\x00\x44\x03\x70\x80"
90 "\x5e\x75\x94\xe6\x11\x46\xd0\x00\x70\x00\x66\x21\x56\xaa\x51"
91 "\x00\x1e\x30\x46\x8f\x33\x00\xba\x88\x21\x00\x00\x1e\x00\x00"
92 "\xc8";
93
94 const unsigned char kHisenseTvEdid[] =
95 "\x00\xff\xff\xff\xff\xff\xff\x00\x20\xa3\x00\x00\x00\x00\x00"
96 "\x00\x12\x1d\x01\x03\x80\x00\x00\x78\x0a\xd7\xa5\xa2\x59\x4a"
97 "\x96\x24\x14\x50\x54\xa3\x08\x00\xd1\xc0\xb3\x00\x81\x00\x81"
98 "\x80\x81\x40\x81\xc0\x01\x01\x01\x01\x02\x3a\x80\x18\x71\x38"
99 "\x2d\x40\x58\x2c\x45\x00\x3f\x43\x21\x00\x00\x1a\x02\x3a\x80"
100 "\x18\x71\x38\x2d\x40\x58\x2c\x45\x00\x3f\x43\x21\x00\x00\x1a"
101 "\x00\x00\x00\xfd\x00\x1e\x4c\x1e\x5a\x1e\x00\x0a\x20\x20\x20"
102 "\x20\x20\x20\x00\x00\x00\xfc\x00\x48\x69\x73\x65\x6e\x73\x65"
103 "\x0a\x20\x20\x20\x20\x20\x01\x47\x02\x03\x2d\x71\x50\x90\x05"
104 "\x04\x03\x07\x02\x06\x01\x1f\x14\x13\x12\x16\x11\x15\x20\x2c"
105 "\x09\x07\x03\x15\x07\x50\x57\x07\x00\x39\x07\xbb\x66\x03\x0c"
106 "\x00\x12\x34\x00\x83\x01\x00\x00\x01\x1d\x00\x72\x51\xd0\x1e"
107 "\x20\x6e\x28\x55\x00\xc4\x8e\x21\x00\x00\x1e\x01\x1d\x80\x18"
108 "\x71\x1c\x16\x20\x58\x2c\x25\x00\xc4\x8e\x21\x00\x00\x9e\x8c"
109 "\x0a\xd0\x8a\x20\xe0\x2d\x10\x10\x3e\x96\x00\x13\x8e\x21\x00"
110 "\x00\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
111 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
112 "\x07";
113
114 const unsigned char kCtlDisplayEdid[] =
115 "\x00\xff\xff\xff\xff\xff\xff\x00\x0e\x8c\x9d\x24\x30\x41\xab\x00"
116 "\xff\x17\x01\x04\xa5\x34\x1d\x78\x3a\xa7\x25\xa4\x57\x51\xa0\x26"
117 "\x10\x50\x54\xbf\xef\x80\xb3\x00\xa9\x40\x95\x00\x81\x40\x81\x80"
118 "\x95\x0f\x71\x4f\x90\x40\x02\x3a\x80\x18\x71\x38\x2d\x40\x58\x2c"
119 "\x45\x00\x09\x25\x21\x00\x00\x1e\x66\x21\x50\xb0\x51\x00\x1b\x30"
120 "\x40\x70\x36\x00\x09\x25\x21\x00\x00\x1e\x00\x00\x00\xfd\x00\x31"
121 "\x4c\x1e\x52\x14\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfc"
122 "\x00\x4c\x50\x32\x33\x36\x31\x0a\x20\x20\x20\x20\x20\x20\x01\x3e"
123 "\x02\x03\x22\xf2\x4f\x90\x9f\x05\x14\x04\x13\x03\x02\x12\x11\x07"
124 "\x06\x16\x15\x01\x23\x09\x07\x07\x83\x01\x00\x00\x65\xb9\x14\x00"
125 "\x04\x00\x02\x3a\x80\x18\x71\x38\x2d\x40\x58\x2c\x45\x00\x09\x25"
126 "\x21\x00\x00\x1e\x02\x3a\x80\xd0\x72\x38\x2d\x40\x10\x2c\x45\x80"
127 "\x09\x25\x21\x00\x00\x1e\x01\x1d\x00\x72\x51\xd0\x1e\x20\x6e\x28"
128 "\x55\x00\x09\x25\x21\x00\x00\x1e\x8c\x0a\xd0\x8a\x20\xe0\x2d\x10"
129 "\x10\x3e\x96\x00\x09\x25\x21\x00\x00\x18\x00\x00\x00\x00\x00\x00"
130 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf4";
131
132 template <size_t N>
asDisplayIdentificationData(const unsigned char (& bytes)[N])133 DisplayIdentificationData asDisplayIdentificationData(const unsigned char (&bytes)[N]) {
134 return DisplayIdentificationData(bytes, bytes + N - 1);
135 }
136
hash(const char * str)137 uint32_t hash(const char* str) {
138 return static_cast<uint32_t>(*ftl::stable_hash(str));
139 }
140
141 } // namespace
142
getInternalEdid()143 const DisplayIdentificationData& getInternalEdid() {
144 static const DisplayIdentificationData data = asDisplayIdentificationData(kInternalEdid);
145 return data;
146 }
147
getExternalEdid()148 const DisplayIdentificationData& getExternalEdid() {
149 static const DisplayIdentificationData data = asDisplayIdentificationData(kExternalEdid);
150 return data;
151 }
152
getExternalEedid()153 const DisplayIdentificationData& getExternalEedid() {
154 static const DisplayIdentificationData data = asDisplayIdentificationData(kExternalEedid);
155 return data;
156 }
157
getPanasonicTvEdid()158 const DisplayIdentificationData& getPanasonicTvEdid() {
159 static const DisplayIdentificationData data = asDisplayIdentificationData(kPanasonicTvEdid);
160 return data;
161 }
162
getHisenseTvEdid()163 const DisplayIdentificationData& getHisenseTvEdid() {
164 static const DisplayIdentificationData data = asDisplayIdentificationData(kHisenseTvEdid);
165 return data;
166 }
167
getCtlDisplayEdid()168 const DisplayIdentificationData& getCtlDisplayEdid() {
169 static const DisplayIdentificationData data = asDisplayIdentificationData(kCtlDisplayEdid);
170 return data;
171 }
172
TEST(DisplayIdentificationTest,isEdid)173 TEST(DisplayIdentificationTest, isEdid) {
174 EXPECT_FALSE(isEdid({}));
175
176 EXPECT_TRUE(isEdid(getInternalEdid()));
177 EXPECT_TRUE(isEdid(getExternalEdid()));
178 EXPECT_TRUE(isEdid(getExternalEedid()));
179 EXPECT_TRUE(isEdid(getPanasonicTvEdid()));
180 EXPECT_TRUE(isEdid(getHisenseTvEdid()));
181 EXPECT_TRUE(isEdid(getCtlDisplayEdid()));
182 }
183
TEST(DisplayIdentificationTest,parseEdid)184 TEST(DisplayIdentificationTest, parseEdid) {
185 auto edid = parseEdid(getInternalEdid());
186 ASSERT_TRUE(edid);
187 EXPECT_EQ(0x4ca3u, edid->manufacturerId);
188 EXPECT_STREQ("SEC", edid->pnpId.data());
189 // ASCII text should be used as fallback if display name and serial number are missing.
190 EXPECT_EQ(hash("121AT11-801"), edid->modelHash);
191 EXPECT_EQ(hash("121AT11-801"), 626564263);
192 EXPECT_TRUE(edid->displayName.empty());
193 EXPECT_EQ(12610, edid->productId);
194 EXPECT_TRUE(edid->hashedBlockZeroSerialNumberOpt.has_value());
195 EXPECT_EQ(ftl::stable_hash("12345678"), edid->hashedBlockZeroSerialNumberOpt.value());
196 EXPECT_FALSE(edid->hashedDescriptorBlockSerialNumberOpt.has_value());
197 EXPECT_EQ(21, edid->manufactureOrModelYear);
198 EXPECT_EQ(0, edid->manufactureWeek);
199 EXPECT_EQ(26, edid->physicalSizeInCm.width);
200 EXPECT_EQ(16, edid->physicalSizeInCm.height);
201 EXPECT_FALSE(edid->cea861Block);
202 EXPECT_EQ(1280, edid->preferredDetailedTimingDescriptor->pixelSizeCount.width);
203 EXPECT_EQ(800, edid->preferredDetailedTimingDescriptor->pixelSizeCount.height);
204 EXPECT_EQ(261, edid->preferredDetailedTimingDescriptor->physicalSizeInMm.width);
205 EXPECT_EQ(163, edid->preferredDetailedTimingDescriptor->physicalSizeInMm.height);
206
207 edid = parseEdid(getExternalEdid());
208 ASSERT_TRUE(edid);
209 EXPECT_EQ(0x22f0u, edid->manufacturerId);
210 EXPECT_STREQ("HWP", edid->pnpId.data());
211 EXPECT_EQ(hash("HP ZR30w"), edid->modelHash);
212 EXPECT_EQ(hash("HP ZR30w"), 918492362);
213 EXPECT_EQ("HP ZR30w", edid->displayName);
214 EXPECT_EQ(10348, edid->productId);
215 EXPECT_TRUE(edid->hashedBlockZeroSerialNumberOpt.has_value());
216 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());
219 EXPECT_EQ(22, edid->manufactureOrModelYear);
220 EXPECT_EQ(2, edid->manufactureWeek);
221 EXPECT_EQ(64, edid->physicalSizeInCm.width);
222 EXPECT_EQ(40, edid->physicalSizeInCm.height);
223 EXPECT_FALSE(edid->cea861Block);
224 EXPECT_EQ(1280, edid->preferredDetailedTimingDescriptor->pixelSizeCount.width);
225 EXPECT_EQ(800, edid->preferredDetailedTimingDescriptor->pixelSizeCount.height);
226 EXPECT_EQ(641, edid->preferredDetailedTimingDescriptor->physicalSizeInMm.width);
227 EXPECT_EQ(400, edid->preferredDetailedTimingDescriptor->physicalSizeInMm.height);
228
229 edid = parseEdid(getExternalEedid());
230 ASSERT_TRUE(edid);
231 EXPECT_EQ(0x4c2du, edid->manufacturerId);
232 EXPECT_STREQ("SAM", edid->pnpId.data());
233 EXPECT_EQ(hash("SAMSUNG"), edid->modelHash);
234 EXPECT_EQ(hash("SAMSUNG"), 1201368132);
235 EXPECT_EQ("SAMSUNG", edid->displayName);
236 EXPECT_EQ(2302, edid->productId);
237 EXPECT_TRUE(edid->hashedBlockZeroSerialNumberOpt.has_value());
238 EXPECT_EQ(ftl::stable_hash("87654321"), edid->hashedBlockZeroSerialNumberOpt.value());
239 EXPECT_FALSE(edid->hashedDescriptorBlockSerialNumberOpt.has_value());
240 EXPECT_EQ(21, edid->manufactureOrModelYear);
241 EXPECT_EQ(41, edid->manufactureWeek);
242 EXPECT_EQ(16, edid->physicalSizeInCm.width);
243 EXPECT_EQ(9, edid->physicalSizeInCm.height);
244 ASSERT_TRUE(edid->cea861Block);
245 ASSERT_TRUE(edid->cea861Block->hdmiVendorDataBlock);
246 auto physicalAddress = edid->cea861Block->hdmiVendorDataBlock->physicalAddress;
247 EXPECT_EQ(2, physicalAddress.a);
248 EXPECT_EQ(0, physicalAddress.b);
249 EXPECT_EQ(0, physicalAddress.c);
250 EXPECT_EQ(0, physicalAddress.d);
251 EXPECT_EQ(1366, edid->preferredDetailedTimingDescriptor->pixelSizeCount.width);
252 EXPECT_EQ(768, edid->preferredDetailedTimingDescriptor->pixelSizeCount.height);
253 EXPECT_EQ(160, edid->preferredDetailedTimingDescriptor->physicalSizeInMm.width);
254 EXPECT_EQ(90, edid->preferredDetailedTimingDescriptor->physicalSizeInMm.height);
255
256 edid = parseEdid(getPanasonicTvEdid());
257 ASSERT_TRUE(edid);
258 EXPECT_EQ(13481, edid->manufacturerId);
259 EXPECT_STREQ("MEI", edid->pnpId.data());
260 EXPECT_EQ(hash("Panasonic-TV"), edid->modelHash);
261 EXPECT_EQ(hash("Panasonic-TV"), 3876373262);
262 EXPECT_EQ("Panasonic-TV", edid->displayName);
263 EXPECT_EQ(41622, edid->productId);
264 EXPECT_TRUE(edid->hashedBlockZeroSerialNumberOpt.has_value());
265 EXPECT_EQ(ftl::stable_hash("16843009"), edid->hashedBlockZeroSerialNumberOpt.value());
266 EXPECT_FALSE(edid->hashedDescriptorBlockSerialNumberOpt.has_value());
267 EXPECT_EQ(29, edid->manufactureOrModelYear);
268 EXPECT_EQ(0, edid->manufactureWeek);
269 EXPECT_EQ(128, edid->physicalSizeInCm.width);
270 EXPECT_EQ(72, edid->physicalSizeInCm.height);
271 ASSERT_TRUE(edid->cea861Block);
272 ASSERT_TRUE(edid->cea861Block->hdmiVendorDataBlock);
273 physicalAddress = edid->cea861Block->hdmiVendorDataBlock->physicalAddress;
274 EXPECT_EQ(2, physicalAddress.a);
275 EXPECT_EQ(0, physicalAddress.b);
276 EXPECT_EQ(0, physicalAddress.c);
277 EXPECT_EQ(0, physicalAddress.d);
278 EXPECT_EQ(1920, edid->preferredDetailedTimingDescriptor->pixelSizeCount.width);
279 EXPECT_EQ(1080, edid->preferredDetailedTimingDescriptor->pixelSizeCount.height);
280 EXPECT_EQ(698, edid->preferredDetailedTimingDescriptor->physicalSizeInMm.width);
281 EXPECT_EQ(392, edid->preferredDetailedTimingDescriptor->physicalSizeInMm.height);
282
283 edid = parseEdid(getHisenseTvEdid());
284 ASSERT_TRUE(edid);
285 EXPECT_EQ(8355, edid->manufacturerId);
286 EXPECT_STREQ("HEC", edid->pnpId.data());
287 EXPECT_EQ(hash("Hisense"), edid->modelHash);
288 EXPECT_EQ(hash("Hisense"), 2859844809);
289 EXPECT_EQ("Hisense", edid->displayName);
290 EXPECT_EQ(0, edid->productId);
291 EXPECT_FALSE(edid->hashedBlockZeroSerialNumberOpt.has_value());
292 EXPECT_FALSE(edid->hashedDescriptorBlockSerialNumberOpt.has_value());
293 EXPECT_EQ(29, edid->manufactureOrModelYear);
294 EXPECT_EQ(18, edid->manufactureWeek);
295 EXPECT_EQ(0, edid->physicalSizeInCm.width);
296 EXPECT_EQ(0, edid->physicalSizeInCm.height);
297 ASSERT_TRUE(edid->cea861Block);
298 ASSERT_TRUE(edid->cea861Block->hdmiVendorDataBlock);
299 physicalAddress = edid->cea861Block->hdmiVendorDataBlock->physicalAddress;
300 EXPECT_EQ(1, physicalAddress.a);
301 EXPECT_EQ(2, physicalAddress.b);
302 EXPECT_EQ(3, physicalAddress.c);
303 EXPECT_EQ(4, physicalAddress.d);
304 EXPECT_EQ(1920, edid->preferredDetailedTimingDescriptor->pixelSizeCount.width);
305 EXPECT_EQ(1080, edid->preferredDetailedTimingDescriptor->pixelSizeCount.height);
306 EXPECT_EQ(575, edid->preferredDetailedTimingDescriptor->physicalSizeInMm.width);
307 EXPECT_EQ(323, edid->preferredDetailedTimingDescriptor->physicalSizeInMm.height);
308
309 edid = parseEdid(getCtlDisplayEdid());
310 ASSERT_TRUE(edid);
311 EXPECT_EQ(3724, edid->manufacturerId);
312 EXPECT_STREQ("CTL", edid->pnpId.data());
313 EXPECT_EQ(hash("LP2361"), edid->modelHash);
314 EXPECT_EQ(hash("LP2361"), 1523181158);
315 EXPECT_EQ("LP2361", edid->displayName);
316 EXPECT_EQ(9373, edid->productId);
317 EXPECT_TRUE(edid->hashedBlockZeroSerialNumberOpt.has_value());
318 EXPECT_EQ(ftl::stable_hash("11223344"), edid->hashedBlockZeroSerialNumberOpt.value());
319 EXPECT_FALSE(edid->hashedDescriptorBlockSerialNumberOpt.has_value());
320 EXPECT_EQ(23, edid->manufactureOrModelYear);
321 EXPECT_EQ(0xff, edid->manufactureWeek);
322 EXPECT_EQ(52, edid->physicalSizeInCm.width);
323 EXPECT_EQ(29, edid->physicalSizeInCm.height);
324 ASSERT_TRUE(edid->cea861Block);
325 EXPECT_FALSE(edid->cea861Block->hdmiVendorDataBlock);
326 EXPECT_EQ(1360, edid->preferredDetailedTimingDescriptor->pixelSizeCount.width);
327 EXPECT_EQ(768, edid->preferredDetailedTimingDescriptor->pixelSizeCount.height);
328 EXPECT_EQ(521, edid->preferredDetailedTimingDescriptor->physicalSizeInMm.width);
329 EXPECT_EQ(293, edid->preferredDetailedTimingDescriptor->physicalSizeInMm.height);
330 }
331
TEST(DisplayIdentificationTest,parseInvalidEdid)332 TEST(DisplayIdentificationTest, parseInvalidEdid) {
333 EXPECT_FALSE(isEdid({}));
334 EXPECT_FALSE(parseEdid({}));
335
336 // Display name must be printable.
337 auto data = getExternalEdid();
338 data[97] = '\x1b';
339 auto edid = parseEdid(data);
340 ASSERT_TRUE(edid);
341 // Serial number should be used as fallback if display name is invalid.
342 const auto modelHash = hash("CN4202137Q");
343 EXPECT_EQ(modelHash, edid->modelHash);
344 EXPECT_EQ(modelHash, 3582951527);
345 EXPECT_TRUE(edid->displayName.empty());
346
347 // Parsing should succeed even if EDID is truncated.
348 data.pop_back();
349 edid = parseEdid(data);
350 ASSERT_TRUE(edid);
351 EXPECT_EQ(modelHash, edid->modelHash);
352 }
353
TEST(DisplayIdentificationTest,getPnpId)354 TEST(DisplayIdentificationTest, getPnpId) {
355 EXPECT_FALSE(getPnpId(0));
356 EXPECT_FALSE(getPnpId(static_cast<uint16_t>(-1)));
357
358 EXPECT_STREQ("SEC", getPnpId(0x4ca3u).value_or(PnpId{}).data());
359 EXPECT_STREQ("HWP", getPnpId(0x22f0u).value_or(PnpId{}).data());
360 EXPECT_STREQ("SAM", getPnpId(0x4c2du).value_or(PnpId{}).data());
361 }
362
TEST(DisplayIdentificationTest,parseDisplayIdentificationData)363 TEST(DisplayIdentificationTest, parseDisplayIdentificationData) {
364 const auto primaryInfo = parseDisplayIdentificationData(0, getInternalEdid());
365 ASSERT_TRUE(primaryInfo);
366
367 const auto secondaryInfo = parseDisplayIdentificationData(1, getExternalEdid());
368 ASSERT_TRUE(secondaryInfo);
369
370 const auto tertiaryInfo = parseDisplayIdentificationData(2, getExternalEedid());
371 ASSERT_TRUE(tertiaryInfo);
372
373 // Display IDs should be unique.
374 EXPECT_EQ(4633257497453176576, primaryInfo->id.value);
375 EXPECT_EQ(4621520285560261121, secondaryInfo->id.value);
376 EXPECT_EQ(4633127902230889474, tertiaryInfo->id.value);
377 }
378
TEST(DisplayIdentificationTest,deviceProductInfo)379 TEST(DisplayIdentificationTest, deviceProductInfo) {
380 using ManufactureYear = DeviceProductInfo::ManufactureYear;
381 using ManufactureWeekAndYear = DeviceProductInfo::ManufactureWeekAndYear;
382 using ModelYear = DeviceProductInfo::ModelYear;
383
384 {
385 const auto displayIdInfo = parseDisplayIdentificationData(0, getInternalEdid());
386 ASSERT_TRUE(displayIdInfo);
387 ASSERT_TRUE(displayIdInfo->deviceProductInfo);
388 const auto& info = *displayIdInfo->deviceProductInfo;
389 EXPECT_EQ("", info.name);
390 EXPECT_STREQ("SEC", info.manufacturerPnpId.data());
391 EXPECT_EQ("12610", info.productId);
392 ASSERT_TRUE(std::holds_alternative<ManufactureYear>(info.manufactureOrModelDate));
393 EXPECT_EQ(2011, std::get<ManufactureYear>(info.manufactureOrModelDate).year);
394 EXPECT_TRUE(info.relativeAddress.empty());
395 }
396 {
397 const auto displayIdInfo = parseDisplayIdentificationData(0, getExternalEdid());
398 ASSERT_TRUE(displayIdInfo);
399 ASSERT_TRUE(displayIdInfo->deviceProductInfo);
400 const auto& info = *displayIdInfo->deviceProductInfo;
401 EXPECT_EQ("HP ZR30w", info.name);
402 EXPECT_STREQ("HWP", info.manufacturerPnpId.data());
403 EXPECT_EQ("10348", info.productId);
404 ASSERT_TRUE(std::holds_alternative<ManufactureWeekAndYear>(info.manufactureOrModelDate));
405 const auto& date = std::get<ManufactureWeekAndYear>(info.manufactureOrModelDate);
406 EXPECT_EQ(2012, date.year);
407 EXPECT_EQ(2, date.week);
408 EXPECT_TRUE(info.relativeAddress.empty());
409 }
410 {
411 const auto displayIdInfo = parseDisplayIdentificationData(0, getExternalEedid());
412 ASSERT_TRUE(displayIdInfo);
413 ASSERT_TRUE(displayIdInfo->deviceProductInfo);
414 const auto& info = *displayIdInfo->deviceProductInfo;
415 EXPECT_EQ("SAMSUNG", info.name);
416 EXPECT_STREQ("SAM", info.manufacturerPnpId.data());
417 EXPECT_EQ("2302", info.productId);
418 ASSERT_TRUE(std::holds_alternative<ManufactureWeekAndYear>(info.manufactureOrModelDate));
419 const auto& date = std::get<ManufactureWeekAndYear>(info.manufactureOrModelDate);
420 EXPECT_EQ(2011, date.year);
421 EXPECT_EQ(41, date.week);
422 EXPECT_THAT(info.relativeAddress, ElementsAre(2, 0, 0, 0));
423 }
424 {
425 const auto displayIdInfo = parseDisplayIdentificationData(0, getPanasonicTvEdid());
426 ASSERT_TRUE(displayIdInfo);
427 ASSERT_TRUE(displayIdInfo->deviceProductInfo);
428 const auto& info = *displayIdInfo->deviceProductInfo;
429 EXPECT_EQ("Panasonic-TV", info.name);
430 EXPECT_STREQ("MEI", info.manufacturerPnpId.data());
431 EXPECT_EQ("41622", info.productId);
432 ASSERT_TRUE(std::holds_alternative<ManufactureYear>(info.manufactureOrModelDate));
433 const auto& date = std::get<ManufactureYear>(info.manufactureOrModelDate);
434 EXPECT_EQ(2019, date.year);
435 EXPECT_THAT(info.relativeAddress, ElementsAre(2, 0, 0, 0));
436 }
437 {
438 const auto displayIdInfo = parseDisplayIdentificationData(0, getHisenseTvEdid());
439 ASSERT_TRUE(displayIdInfo);
440 ASSERT_TRUE(displayIdInfo->deviceProductInfo);
441 const auto& info = *displayIdInfo->deviceProductInfo;
442 EXPECT_EQ("Hisense", info.name);
443 EXPECT_STREQ("HEC", info.manufacturerPnpId.data());
444 EXPECT_EQ("0", info.productId);
445 ASSERT_TRUE(std::holds_alternative<ManufactureWeekAndYear>(info.manufactureOrModelDate));
446 const auto& date = std::get<ManufactureWeekAndYear>(info.manufactureOrModelDate);
447 EXPECT_EQ(2019, date.year);
448 EXPECT_EQ(18, date.week);
449 EXPECT_THAT(info.relativeAddress, ElementsAre(1, 2, 3, 4));
450 }
451 {
452 const auto displayIdInfo = parseDisplayIdentificationData(0, getCtlDisplayEdid());
453 ASSERT_TRUE(displayIdInfo);
454 ASSERT_TRUE(displayIdInfo->deviceProductInfo);
455 const auto& info = *displayIdInfo->deviceProductInfo;
456 EXPECT_EQ("LP2361", info.name);
457 EXPECT_STREQ("CTL", info.manufacturerPnpId.data());
458 EXPECT_EQ("9373", info.productId);
459 ASSERT_TRUE(std::holds_alternative<ModelYear>(info.manufactureOrModelDate));
460 EXPECT_EQ(2013, std::get<ModelYear>(info.manufactureOrModelDate).year);
461 EXPECT_TRUE(info.relativeAddress.empty());
462 }
463 }
464
TEST(DisplayIdentificationTest,fromPort)465 TEST(DisplayIdentificationTest, fromPort) {
466 // Manufacturer ID should be invalid.
467 ASSERT_FALSE(getPnpId(PhysicalDisplayId::fromPort(0)));
468 ASSERT_FALSE(getPnpId(PhysicalDisplayId::fromPort(0xffu)));
469 }
470
TEST(DisplayIdentificationTest,getVirtualDisplayId)471 TEST(DisplayIdentificationTest, getVirtualDisplayId) {
472 // Manufacturer ID should be invalid.
473 ASSERT_FALSE(getPnpId(getVirtualDisplayId(0)));
474 ASSERT_FALSE(getPnpId(getVirtualDisplayId(0xffff'ffffu)));
475 }
476
477 } // namespace android
478
479 // TODO(b/129481165): remove the #pragma below and fix conversion issues
480 #pragma clang diagnostic pop // ignored "-Wextra"
481