Make display unique id stable across x86 and x86_64 builds
... by using a minimal version of CityHash64 for the hash function.
std::hash differs between x86 and x86_64 and also:
"Hash functions are only required to produce the same result for the
same input within a single execution of a program;"
This is problematic for input device configuration files which
reference the display unique id.
Bug: b/186150820
Test: libsurfaceflinger_unittest
Change-Id: If15b66775fa48f14cc56bbd23536b61844b7ae37
Merged-In: If15b66775fa48f14cc56bbd23536b61844b7ae37
diff --git a/services/surfaceflinger/tests/unittests/DisplayIdentificationTest.cpp b/services/surfaceflinger/tests/unittests/DisplayIdentificationTest.cpp
index 2a0e913..300ef26 100644
--- a/services/surfaceflinger/tests/unittests/DisplayIdentificationTest.cpp
+++ b/services/surfaceflinger/tests/unittests/DisplayIdentificationTest.cpp
@@ -21,6 +21,7 @@
#include <gtest/gtest.h>
#include "DisplayHardware/DisplayIdentification.h"
+#include "DisplayHardware/Hash.h"
namespace android {
namespace {
@@ -128,7 +129,7 @@
}
uint32_t hash(const char* str) {
- return static_cast<uint32_t>(std::hash<std::string_view>()(str));
+ return static_cast<uint32_t>(cityHash64Len0To16(str));
}
} // namespace
@@ -303,9 +304,9 @@
ASSERT_TRUE(tertiaryInfo);
// Display IDs should be unique.
- EXPECT_NE(primaryInfo->id, secondaryInfo->id);
- EXPECT_NE(primaryInfo->id, tertiaryInfo->id);
- EXPECT_NE(secondaryInfo->id, tertiaryInfo->id);
+ EXPECT_EQ(21571479025788672, primaryInfo->id.value);
+ EXPECT_EQ(9834267132873217, secondaryInfo->id.value);
+ EXPECT_EQ(21441883803501570, tertiaryInfo->id.value);
}
TEST(DisplayIdentificationTest, deviceProductInfo) {