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/include/input/InputDevice.h b/include/input/InputDevice.h
index e93fe8c..8783d9c 100644
--- a/include/input/InputDevice.h
+++ b/include/input/InputDevice.h
@@ -280,7 +280,7 @@
void initialize(int32_t id, int32_t generation, int32_t controllerNumber,
const InputDeviceIdentifier& identifier, const std::string& alias,
- bool isExternal, bool hasMic, int32_t associatedDisplayId,
+ bool isExternal, bool hasMic, ui::LogicalDisplayId associatedDisplayId,
InputDeviceViewBehavior viewBehavior = {{}}, bool enabled = true);
inline int32_t getId() const { return mId; }
@@ -348,7 +348,7 @@
}
inline std::optional<InputDeviceUsiVersion> getUsiVersion() const { return mUsiVersion; }
- inline int32_t getAssociatedDisplayId() const { return mAssociatedDisplayId; }
+ inline ui::LogicalDisplayId getAssociatedDisplayId() const { return mAssociatedDisplayId; }
inline void setEnabled(bool enabled) { mEnabled = enabled; }
inline bool isEnabled() const { return mEnabled; }
@@ -366,7 +366,7 @@
int32_t mKeyboardType;
std::shared_ptr<KeyCharacterMap> mKeyCharacterMap;
std::optional<InputDeviceUsiVersion> mUsiVersion;
- int32_t mAssociatedDisplayId;
+ ui::LogicalDisplayId mAssociatedDisplayId{ui::ADISPLAY_ID_NONE};
bool mEnabled;
bool mHasVibrator;