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/reader/InputDevice.cpp b/services/inputflinger/reader/InputDevice.cpp
index 44dfd15..15586e2 100644
--- a/services/inputflinger/reader/InputDevice.cpp
+++ b/services/inputflinger/reader/InputDevice.cpp
@@ -442,7 +442,7 @@
InputDeviceInfo InputDevice::getDeviceInfo() {
InputDeviceInfo outDeviceInfo;
outDeviceInfo.initialize(mId, mGeneration, mControllerNumber, mIdentifier, mAlias, mIsExternal,
- mHasMic, getAssociatedDisplayId().value_or(ADISPLAY_ID_NONE),
+ mHasMic, getAssociatedDisplayId().value_or(ui::ADISPLAY_ID_NONE),
{mShouldSmoothScroll}, isEnabled());
for_each_mapper(
@@ -699,14 +699,14 @@
return NotifyDeviceResetArgs(mContext->getNextId(), when, mId);
}
-std::optional<int32_t> InputDevice::getAssociatedDisplayId() {
+std::optional<ui::LogicalDisplayId> InputDevice::getAssociatedDisplayId() {
// Check if we had associated to the specific display.
if (mAssociatedViewport) {
return mAssociatedViewport->displayId;
}
// No associated display port, check if some InputMapper is associated.
- return first_in_mappers<int32_t>(
+ return first_in_mappers<ui::LogicalDisplayId>(
[](InputMapper& mapper) { return mapper.getAssociatedDisplayId(); });
}