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