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/include/InputReaderBase.h b/services/inputflinger/include/InputReaderBase.h
index 4d8ed99..e5c3aa0 100644
--- a/services/inputflinger/include/InputReaderBase.h
+++ b/services/inputflinger/include/InputReaderBase.h
@@ -125,7 +125,7 @@
std::unordered_map<std::string, KeyboardLayoutInfo> keyboardLayoutAssociations;
// The suggested display ID to show the cursor.
- int32_t defaultPointerDisplayId;
+ ui::LogicalDisplayId defaultPointerDisplayId;
// The mouse pointer speed, as a number from -7 (slowest) to 7 (fastest).
//
@@ -135,7 +135,7 @@
// Displays on which an acceleration curve shouldn't be applied for pointer movements from mice.
//
// Currently only used when the enable_new_mouse_pointer_ballistics flag is enabled.
- std::set<int32_t> displaysWithMousePointerAccelerationDisabled;
+ std::set<ui::LogicalDisplayId> displaysWithMousePointerAccelerationDisabled;
// Velocity control parameters for mouse pointer movements.
//
@@ -243,6 +243,7 @@
InputReaderConfiguration()
: virtualKeyQuietTime(0),
+ defaultPointerDisplayId(ui::ADISPLAY_ID_DEFAULT),
mousePointerSpeed(0),
displaysWithMousePointerAccelerationDisabled(),
pointerVelocityControlParameters(1.0f, 500.0f, 3000.0f,
@@ -275,7 +276,7 @@
std::optional<DisplayViewport> getDisplayViewportByUniqueId(const std::string& uniqueDisplayId)
const;
std::optional<DisplayViewport> getDisplayViewportByPort(uint8_t physicalPort) const;
- std::optional<DisplayViewport> getDisplayViewportById(int32_t displayId) const;
+ std::optional<DisplayViewport> getDisplayViewportById(ui::LogicalDisplayId displayId) const;
void setDisplayViewports(const std::vector<DisplayViewport>& viewports);
void dump(std::string& dump) const;
@@ -366,7 +367,7 @@
virtual std::vector<InputDeviceSensorInfo> getSensors(int32_t deviceId) = 0;
/* Return true if the device can send input events to the specified display. */
- virtual bool canDispatchToDisplay(int32_t deviceId, int32_t displayId) = 0;
+ virtual bool canDispatchToDisplay(int32_t deviceId, ui::LogicalDisplayId displayId) = 0;
/* Enable sensor in input reader mapper. */
virtual bool enableSensor(int32_t deviceId, InputDeviceSensorType sensorType,
@@ -471,7 +472,7 @@
* be used as the range of possible values for pointing devices, like mice and touchpads.
*/
virtual std::optional<DisplayViewport> getPointerViewportForAssociatedDisplay(
- int32_t associatedDisplayId = ADISPLAY_ID_NONE) = 0;
+ ui::LogicalDisplayId associatedDisplayId = ui::ADISPLAY_ID_NONE) = 0;
};
} // namespace android
diff --git a/services/inputflinger/include/NotifyArgs.h b/services/inputflinger/include/NotifyArgs.h
index 736b1e0..865f3d0 100644
--- a/services/inputflinger/include/NotifyArgs.h
+++ b/services/inputflinger/include/NotifyArgs.h
@@ -61,7 +61,7 @@
int32_t deviceId;
uint32_t source;
- int32_t displayId;
+ ui::LogicalDisplayId displayId{ui::ADISPLAY_ID_NONE};
uint32_t policyFlags;
int32_t action;
int32_t flags;
@@ -74,9 +74,9 @@
inline NotifyKeyArgs() {}
NotifyKeyArgs(int32_t id, nsecs_t eventTime, nsecs_t readTime, int32_t deviceId,
- uint32_t source, int32_t displayId, uint32_t policyFlags, int32_t action,
- int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState,
- nsecs_t downTime);
+ uint32_t source, ui::LogicalDisplayId displayId, uint32_t policyFlags,
+ int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode,
+ int32_t metaState, nsecs_t downTime);
bool operator==(const NotifyKeyArgs& rhs) const = default;
@@ -91,7 +91,7 @@
int32_t deviceId;
uint32_t source;
- int32_t displayId;
+ ui::LogicalDisplayId displayId{ui::ADISPLAY_ID_NONE};
uint32_t policyFlags;
int32_t action;
int32_t actionButton;
@@ -123,12 +123,12 @@
inline NotifyMotionArgs() {}
NotifyMotionArgs(int32_t id, nsecs_t eventTime, nsecs_t readTime, int32_t deviceId,
- uint32_t source, int32_t displayId, uint32_t policyFlags, int32_t action,
- int32_t actionButton, int32_t flags, int32_t metaState, int32_t buttonState,
- MotionClassification classification, int32_t edgeFlags, uint32_t pointerCount,
- const PointerProperties* pointerProperties, const PointerCoords* pointerCoords,
- float xPrecision, float yPrecision, float xCursorPosition,
- float yCursorPosition, nsecs_t downTime,
+ uint32_t source, ui::LogicalDisplayId displayId, uint32_t policyFlags,
+ int32_t action, int32_t actionButton, int32_t flags, int32_t metaState,
+ int32_t buttonState, MotionClassification classification, int32_t edgeFlags,
+ uint32_t pointerCount, const PointerProperties* pointerProperties,
+ const PointerCoords* pointerCoords, float xPrecision, float yPrecision,
+ float xCursorPosition, float yCursorPosition, nsecs_t downTime,
const std::vector<TouchVideoFrame>& videoFrames);
NotifyMotionArgs(const NotifyMotionArgs& other) = default;
diff --git a/services/inputflinger/include/NotifyArgsBuilders.h b/services/inputflinger/include/NotifyArgsBuilders.h
index 1bd5595..1ba0cfd 100644
--- a/services/inputflinger/include/NotifyArgsBuilders.h
+++ b/services/inputflinger/include/NotifyArgsBuilders.h
@@ -19,7 +19,6 @@
#include <NotifyArgs.h>
#include <android/input.h>
#include <attestation/HmacKeyManager.h>
-#include <gui/constants.h>
#include <input/Input.h>
#include <input/InputEventBuilders.h>
#include <utils/Timers.h> // for nsecs_t, systemTime
@@ -55,7 +54,7 @@
return *this;
}
- MotionArgsBuilder& displayId(int32_t displayId) {
+ MotionArgsBuilder& displayId(ui::LogicalDisplayId displayId) {
mDisplayId = displayId;
return *this;
}
@@ -151,7 +150,7 @@
uint32_t mSource;
nsecs_t mDownTime;
nsecs_t mEventTime;
- int32_t mDisplayId{ADISPLAY_ID_DEFAULT};
+ ui::LogicalDisplayId mDisplayId{ui::ADISPLAY_ID_DEFAULT};
uint32_t mPolicyFlags = DEFAULT_POLICY_FLAGS;
int32_t mActionButton{0};
int32_t mButtonState{0};
@@ -187,7 +186,7 @@
return *this;
}
- KeyArgsBuilder& displayId(int32_t displayId) {
+ KeyArgsBuilder& displayId(ui::LogicalDisplayId displayId) {
mDisplayId = displayId;
return *this;
}
@@ -230,7 +229,7 @@
uint32_t mSource;
nsecs_t mDownTime;
nsecs_t mEventTime;
- int32_t mDisplayId{ADISPLAY_ID_DEFAULT};
+ ui::LogicalDisplayId mDisplayId{ui::ADISPLAY_ID_DEFAULT};
uint32_t mPolicyFlags = DEFAULT_POLICY_FLAGS;
int32_t mFlags{0};
int32_t mKeyCode{AKEYCODE_UNKNOWN};
diff --git a/services/inputflinger/include/PointerChoreographerPolicyInterface.h b/services/inputflinger/include/PointerChoreographerPolicyInterface.h
index 462aedc..f6dc109 100644
--- a/services/inputflinger/include/PointerChoreographerPolicyInterface.h
+++ b/services/inputflinger/include/PointerChoreographerPolicyInterface.h
@@ -53,7 +53,8 @@
* @param displayId The updated display on which the mouse cursor is shown
* @param position The new position of the mouse cursor on the logical display
*/
- virtual void notifyPointerDisplayIdChanged(int32_t displayId, const FloatPoint& position) = 0;
+ virtual void notifyPointerDisplayIdChanged(ui::LogicalDisplayId displayId,
+ const FloatPoint& position) = 0;
};
} // namespace android
diff --git a/services/inputflinger/include/PointerControllerInterface.h b/services/inputflinger/include/PointerControllerInterface.h
index c1467b3..cee44fc 100644
--- a/services/inputflinger/include/PointerControllerInterface.h
+++ b/services/inputflinger/include/PointerControllerInterface.h
@@ -125,13 +125,13 @@
* pressed (not hovering).
*/
virtual void setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex,
- BitSet32 spotIdBits, int32_t displayId) = 0;
+ BitSet32 spotIdBits, ui::LogicalDisplayId displayId) = 0;
/* Removes all spots. */
virtual void clearSpots() = 0;
/* Gets the id of the display where the pointer should be shown. */
- virtual int32_t getDisplayId() const = 0;
+ virtual ui::LogicalDisplayId getDisplayId() const = 0;
/* Sets the associated display of this pointer. Pointer should show on that display. */
virtual void setDisplayViewport(const DisplayViewport& displayViewport) = 0;
@@ -145,7 +145,7 @@
/* Sets the flag to skip screenshot of the pointer indicators on the display matching the
* provided displayId.
*/
- virtual void setSkipScreenshot(int32_t displayId, bool skip) = 0;
+ virtual void setSkipScreenshot(ui::LogicalDisplayId displayId, bool skip) = 0;
};
} // namespace android