Use a strongly typed LogicalDisplayId for displayId(2/n)
Currently, we use int32_t for displayId, which is not a safe type, and
it may also lead to misdefinition of types. Here, we introduce
LogicalDisplayId as a strong type for displayId and move all contents
of constants.h into LogicalDisplayId.h.
Bug: 339106983
Test: atest inputflinger_tests
Test: atest InputTests
Test: m checkinput
Test: m libsurfaceflinger_unittest
Test: presubmit
Change-Id: If44e56f69553d095af5adb59b595e4a852ab32ce
Signed-off-by: Linnan Li <lilinnan@xiaomi.corp-partner.google.com>
diff --git a/services/inputflinger/tests/FakePointerController.cpp b/services/inputflinger/tests/FakePointerController.cpp
index 28d4b67..731a286 100644
--- a/services/inputflinger/tests/FakePointerController.cpp
+++ b/services/inputflinger/tests/FakePointerController.cpp
@@ -32,7 +32,7 @@
mHaveBounds = false;
}
-const std::map<int32_t, std::vector<int32_t>>& FakePointerController::getSpots() {
+const std::map<ui::LogicalDisplayId, std::vector<int32_t>>& FakePointerController::getSpots() {
return mSpotsByDisplay;
}
@@ -51,9 +51,9 @@
return {mX, mY};
}
-int32_t FakePointerController::getDisplayId() const {
+ui::LogicalDisplayId FakePointerController::getDisplayId() const {
if (!mEnabled || !mDisplayId) {
- return ADISPLAY_ID_NONE;
+ return ui::ADISPLAY_ID_NONE;
}
return *mDisplayId;
}
@@ -76,7 +76,7 @@
mCustomIconStyle = icon.style;
}
-void FakePointerController::setSkipScreenshot(int32_t displayId, bool skip) {
+void FakePointerController::setSkipScreenshot(ui::LogicalDisplayId displayId, bool skip) {
if (skip) {
mDisplaysToSkipScreenshot.insert(displayId);
} else {
@@ -84,7 +84,7 @@
}
};
-void FakePointerController::assertViewportSet(int32_t displayId) {
+void FakePointerController::assertViewportSet(ui::LogicalDisplayId displayId) {
ASSERT_TRUE(mDisplayId);
ASSERT_EQ(displayId, mDisplayId);
}
@@ -99,7 +99,7 @@
ASSERT_NEAR(y, actualY, 1);
}
-void FakePointerController::assertSpotCount(int32_t displayId, int32_t count) {
+void FakePointerController::assertSpotCount(ui::LogicalDisplayId displayId, int32_t count) {
auto it = mSpotsByDisplay.find(displayId);
ASSERT_TRUE(it != mSpotsByDisplay.end()) << "Spots not found for display " << displayId;
ASSERT_EQ(static_cast<size_t>(count), it->second.size());
@@ -125,7 +125,8 @@
ASSERT_EQ(std::nullopt, mCustomIconStyle);
}
-void FakePointerController::assertIsHiddenOnMirroredDisplays(int32_t displayId, bool isHidden) {
+void FakePointerController::assertIsHiddenOnMirroredDisplays(ui::LogicalDisplayId displayId,
+ bool isHidden) {
if (isHidden) {
ASSERT_TRUE(mDisplaysToSkipScreenshot.find(displayId) != mDisplaysToSkipScreenshot.end());
} else {
@@ -166,7 +167,7 @@
}
void FakePointerController::setSpots(const PointerCoords*, const uint32_t*, BitSet32 spotIdBits,
- int32_t displayId) {
+ ui::LogicalDisplayId displayId) {
if (!mEnabled) return;
std::vector<int32_t> newSpots;