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
diff --git a/services/surfaceflinger/tests/unittests/DisplayIdentificationTest.cpp b/services/surfaceflinger/tests/unittests/DisplayIdentificationTest.cpp
index dc04b6d..cd4a5c9 100644
--- a/services/surfaceflinger/tests/unittests/DisplayIdentificationTest.cpp
+++ b/services/surfaceflinger/tests/unittests/DisplayIdentificationTest.cpp
@@ -25,6 +25,7 @@
#include <gtest/gtest.h>
#include "DisplayHardware/DisplayIdentification.h"
+#include "DisplayHardware/Hash.h"
using ::testing::ElementsAre;
@@ -134,7 +135,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
@@ -309,9 +310,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(4633257497453176576, primaryInfo->id.value);
+ EXPECT_EQ(4621520285560261121, secondaryInfo->id.value);
+ EXPECT_EQ(4633127902230889474, tertiaryInfo->id.value);
}
TEST(DisplayIdentificationTest, deviceProductInfo) {