diff options
| author | 2023-07-11 10:51:20 -0700 | |
|---|---|---|
| committer | 2023-07-11 19:19:21 +0000 | |
| commit | 7e2f8f1835c261dd50f007bb194b33597050e28d (patch) | |
| tree | ffe02b65a3a1e8c4284bfea6cbaf16597202a611 | |
| parent | 2cace077b66002a3d9a6aab70b56e03d860cd2e1 (diff) | |
Add type alias for DeviceId
To facilitate the future transition to a strong type, add a "weak" type
for DeviceId in this CL.
This will allow us to fix some of the existing code before having to
refactor all of it in a single topic.
Also, in this CL, simplify the names of some variables in TouchState
because we no longer have a conflict with the 'deviceId' member.
Bug: 211379801
Test: none
Change-Id: I1f287ad62fa26ba4bbbbbf353bebfbf8ad38ff67
| -rw-r--r-- | include/input/Input.h | 15 | ||||
| -rw-r--r-- | services/inputflinger/dispatcher/InputState.cpp | 2 | ||||
| -rw-r--r-- | services/inputflinger/dispatcher/InputState.h | 6 | ||||
| -rw-r--r-- | services/inputflinger/dispatcher/TouchState.cpp | 53 | ||||
| -rw-r--r-- | services/inputflinger/dispatcher/TouchState.h | 16 |
5 files changed, 47 insertions, 45 deletions
diff --git a/include/input/Input.h b/include/input/Input.h index 1fc9cb1207..a271f0c1f9 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -501,6 +501,9 @@ struct PointerProperties { PointerProperties& operator=(const PointerProperties&) = default; }; +// TODO(b/211379801) : Use a strong type from ftl/mixins.h instead +using DeviceId = int32_t; + /* * Input events. */ @@ -512,7 +515,7 @@ public: inline int32_t getId() const { return mId; } - inline int32_t getDeviceId() const { return mDeviceId; } + inline DeviceId getDeviceId() const { return mDeviceId; } inline uint32_t getSource() const { return mSource; } @@ -527,13 +530,13 @@ public: static int32_t nextId(); protected: - void initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, + void initialize(int32_t id, DeviceId deviceId, uint32_t source, int32_t displayId, std::array<uint8_t, 32> hmac); void initialize(const InputEvent& from); int32_t mId; - int32_t mDeviceId; + DeviceId mDeviceId; uint32_t mSource; int32_t mDisplayId; std::array<uint8_t, 32> mHmac; @@ -571,7 +574,7 @@ public: static const char* getLabel(int32_t keyCode); static std::optional<int> getKeyCodeFromLabel(const char* label); - void initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, + void initialize(int32_t id, DeviceId deviceId, uint32_t source, int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState, int32_t repeatCount, nsecs_t downTime, nsecs_t eventTime); @@ -835,7 +838,7 @@ public: ssize_t findPointerIndex(int32_t pointerId) const; - void initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, + void initialize(int32_t id, DeviceId deviceId, uint32_t source, int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, int32_t actionButton, int32_t flags, int32_t edgeFlags, int32_t metaState, int32_t buttonState, MotionClassification classification, const ui::Transform& transform, @@ -1013,7 +1016,7 @@ struct __attribute__((__packed__)) VerifiedInputEvent { }; Type type; - int32_t deviceId; + DeviceId deviceId; nsecs_t eventTimeNanos; uint32_t source; int32_t displayId; diff --git a/services/inputflinger/dispatcher/InputState.cpp b/services/inputflinger/dispatcher/InputState.cpp index fe0b89c025..e6941ef027 100644 --- a/services/inputflinger/dispatcher/InputState.cpp +++ b/services/inputflinger/dispatcher/InputState.cpp @@ -28,7 +28,7 @@ InputState::InputState(const IdGenerator& idGenerator) : mIdGenerator(idGenerato InputState::~InputState() {} -bool InputState::isHovering(int32_t deviceId, uint32_t source, int32_t displayId) const { +bool InputState::isHovering(DeviceId deviceId, uint32_t source, int32_t displayId) const { for (const MotionMemento& memento : mMotionMementos) { if (memento.deviceId == deviceId && memento.source == source && memento.displayId == displayId && memento.hovering) { diff --git a/services/inputflinger/dispatcher/InputState.h b/services/inputflinger/dispatcher/InputState.h index af2a3cbc93..e741137103 100644 --- a/services/inputflinger/dispatcher/InputState.h +++ b/services/inputflinger/dispatcher/InputState.h @@ -36,7 +36,7 @@ public: // Returns true if the specified source is known to have received a hover enter // motion event. - bool isHovering(int32_t deviceId, uint32_t source, int32_t displayId) const; + bool isHovering(DeviceId deviceId, uint32_t source, int32_t displayId) const; // Records tracking information for a key event that has just been published. // Returns true if the event should be delivered, false if it is inconsistent @@ -76,7 +76,7 @@ public: private: struct KeyMemento { - int32_t deviceId; + DeviceId deviceId; uint32_t source; int32_t displayId; int32_t keyCode; @@ -88,7 +88,7 @@ private: }; struct MotionMemento { - int32_t deviceId; + DeviceId deviceId; uint32_t source; int32_t displayId; int32_t flags; diff --git a/services/inputflinger/dispatcher/TouchState.cpp b/services/inputflinger/dispatcher/TouchState.cpp index dadfdc122a..4221e42ae5 100644 --- a/services/inputflinger/dispatcher/TouchState.cpp +++ b/services/inputflinger/dispatcher/TouchState.cpp @@ -40,25 +40,25 @@ std::set<int32_t> TouchState::getActiveDeviceIds() const { return out; } -bool TouchState::hasTouchingPointers(int32_t deviceId) const { +bool TouchState::hasTouchingPointers(DeviceId deviceId) const { return std::any_of(windows.begin(), windows.end(), [&](const TouchedWindow& window) { return window.hasTouchingPointers(deviceId); }); } -void TouchState::removeTouchingPointer(int32_t removedDeviceId, int32_t pointerId) { +void TouchState::removeTouchingPointer(DeviceId deviceId, int32_t pointerId) { for (TouchedWindow& touchedWindow : windows) { - touchedWindow.removeTouchingPointer(removedDeviceId, pointerId); + touchedWindow.removeTouchingPointer(deviceId, pointerId); } clearWindowsWithoutPointers(); } void TouchState::removeTouchingPointerFromWindow( - int32_t removedDeviceId, int32_t pointerId, + DeviceId deviceId, int32_t pointerId, const sp<android::gui::WindowInfoHandle>& windowHandle) { for (TouchedWindow& touchedWindow : windows) { if (touchedWindow.windowHandle == windowHandle) { - touchedWindow.removeTouchingPointer(removedDeviceId, pointerId); + touchedWindow.removeTouchingPointer(deviceId, pointerId); clearWindowsWithoutPointers(); return; } @@ -79,8 +79,7 @@ void TouchState::clearWindowsWithoutPointers() { } void TouchState::addOrUpdateWindow(const sp<WindowInfoHandle>& windowHandle, - ftl::Flags<InputTarget::Flags> targetFlags, - int32_t addedDeviceId, + ftl::Flags<InputTarget::Flags> targetFlags, DeviceId deviceId, std::bitset<MAX_POINTER_ID + 1> touchingPointerIds, std::optional<nsecs_t> firstDownTimeInTarget) { for (TouchedWindow& touchedWindow : windows) { @@ -94,9 +93,9 @@ void TouchState::addOrUpdateWindow(const sp<WindowInfoHandle>& windowHandle, // For cases like hover enter/exit or DISPATCH_AS_OUTSIDE a touch window might not have // downTime set initially. Need to update existing window when a pointer is down for the // window. - touchedWindow.addTouchingPointers(addedDeviceId, touchingPointerIds); + touchedWindow.addTouchingPointers(deviceId, touchingPointerIds); if (firstDownTimeInTarget) { - touchedWindow.trySetDownTimeInTarget(addedDeviceId, *firstDownTimeInTarget); + touchedWindow.trySetDownTimeInTarget(deviceId, *firstDownTimeInTarget); } return; } @@ -104,25 +103,25 @@ void TouchState::addOrUpdateWindow(const sp<WindowInfoHandle>& windowHandle, TouchedWindow touchedWindow; touchedWindow.windowHandle = windowHandle; touchedWindow.targetFlags = targetFlags; - touchedWindow.addTouchingPointers(addedDeviceId, touchingPointerIds); + touchedWindow.addTouchingPointers(deviceId, touchingPointerIds); if (firstDownTimeInTarget) { - touchedWindow.trySetDownTimeInTarget(addedDeviceId, *firstDownTimeInTarget); + touchedWindow.trySetDownTimeInTarget(deviceId, *firstDownTimeInTarget); } windows.push_back(touchedWindow); } void TouchState::addHoveringPointerToWindow(const sp<WindowInfoHandle>& windowHandle, - int32_t hoveringDeviceId, int32_t hoveringPointerId) { + DeviceId deviceId, int32_t hoveringPointerId) { for (TouchedWindow& touchedWindow : windows) { if (touchedWindow.windowHandle == windowHandle) { - touchedWindow.addHoveringPointer(hoveringDeviceId, hoveringPointerId); + touchedWindow.addHoveringPointer(deviceId, hoveringPointerId); return; } } TouchedWindow touchedWindow; touchedWindow.windowHandle = windowHandle; - touchedWindow.addHoveringPointer(hoveringDeviceId, hoveringPointerId); + touchedWindow.addHoveringPointer(deviceId, hoveringPointerId); windows.push_back(touchedWindow); } @@ -149,12 +148,12 @@ void TouchState::filterNonAsIsTouchWindows() { } } -void TouchState::cancelPointersForWindowsExcept(int32_t touchedDeviceId, +void TouchState::cancelPointersForWindowsExcept(DeviceId deviceId, std::bitset<MAX_POINTER_ID + 1> pointerIds, const sp<IBinder>& token) { std::for_each(windows.begin(), windows.end(), [&](TouchedWindow& w) { if (w.windowHandle->getToken() != token) { - w.removeTouchingPointers(touchedDeviceId, pointerIds); + w.removeTouchingPointers(deviceId, pointerIds); } }); clearWindowsWithoutPointers(); @@ -168,10 +167,10 @@ void TouchState::cancelPointersForWindowsExcept(int32_t touchedDeviceId, */ void TouchState::cancelPointersForNonPilferingWindows() { // First, find all pointers that are being pilfered, across all windows - std::map<int32_t /*deviceId*/, std::bitset<MAX_POINTER_ID + 1>> allPilferedPointerIdsByDevice; + std::map<DeviceId, std::bitset<MAX_POINTER_ID + 1>> allPilferedPointerIdsByDevice; for (const TouchedWindow& w : windows) { - for (const auto& [iterDeviceId, pilferedPointerIds] : w.getPilferingPointers()) { - allPilferedPointerIdsByDevice[iterDeviceId] |= pilferedPointerIds; + for (const auto& [deviceId, pilferedPointerIds] : w.getPilferingPointers()) { + allPilferedPointerIdsByDevice[deviceId] |= pilferedPointerIds; } }; @@ -183,12 +182,12 @@ void TouchState::cancelPointersForNonPilferingWindows() { // (only), the remove pointer 2 from window A and pointer 1 from window B. Usually, the set of // pilfered pointers will be disjoint across all windows, but there's no reason to cause that // limitation here. - for (const auto& [iterDeviceId, allPilferedPointerIds] : allPilferedPointerIdsByDevice) { + for (const auto& [deviceId, allPilferedPointerIds] : allPilferedPointerIdsByDevice) { std::for_each(windows.begin(), windows.end(), [&](TouchedWindow& w) { std::bitset<MAX_POINTER_ID + 1> pilferedByOtherWindows = - w.getPilferingPointers(iterDeviceId) ^ allPilferedPointerIds; + w.getPilferingPointers(deviceId) ^ allPilferedPointerIds; // Remove all pointers pilfered by other windows - w.removeTouchingPointers(iterDeviceId, pilferedByOtherWindows); + w.removeTouchingPointers(deviceId, pilferedByOtherWindows); }); } clearWindowsWithoutPointers(); @@ -248,11 +247,11 @@ bool TouchState::hasHoveringPointers() const { [](const TouchedWindow& window) { return window.hasHoveringPointers(); }); } -std::set<sp<WindowInfoHandle>> TouchState::getWindowsWithHoveringPointer(int32_t hoveringDeviceId, +std::set<sp<WindowInfoHandle>> TouchState::getWindowsWithHoveringPointer(DeviceId deviceId, int32_t pointerId) const { std::set<sp<WindowInfoHandle>> out; for (const TouchedWindow& window : windows) { - if (window.hasHoveringPointer(hoveringDeviceId, pointerId)) { + if (window.hasHoveringPointer(deviceId, pointerId)) { out.insert(window.windowHandle); } } @@ -266,10 +265,10 @@ void TouchState::removeHoveringPointer(int32_t hoveringDeviceId, int32_t hoverin clearWindowsWithoutPointers(); } -void TouchState::removeAllPointersForDevice(int32_t removedDeviceId) { +void TouchState::removeAllPointersForDevice(DeviceId deviceId) { for (TouchedWindow& window : windows) { - window.removeAllHoveringPointersForDevice(removedDeviceId); - window.removeAllTouchingPointersForDevice(removedDeviceId); + window.removeAllHoveringPointersForDevice(deviceId); + window.removeAllTouchingPointersForDevice(deviceId); } clearWindowsWithoutPointers(); diff --git a/services/inputflinger/dispatcher/TouchState.h b/services/inputflinger/dispatcher/TouchState.h index 9f29a4aa71..25b9643528 100644 --- a/services/inputflinger/dispatcher/TouchState.h +++ b/services/inputflinger/dispatcher/TouchState.h @@ -41,24 +41,24 @@ struct TouchState { std::set<int32_t> getActiveDeviceIds() const; bool hasTouchingPointers(int32_t device) const; - void removeTouchingPointer(int32_t deviceId, int32_t pointerId); - void removeTouchingPointerFromWindow(int32_t deviceId, int32_t pointerId, + void removeTouchingPointer(DeviceId deviceId, int32_t pointerId); + void removeTouchingPointerFromWindow(DeviceId deviceId, int32_t pointerId, const sp<android::gui::WindowInfoHandle>& windowHandle); void addOrUpdateWindow(const sp<android::gui::WindowInfoHandle>& windowHandle, - ftl::Flags<InputTarget::Flags> targetFlags, int32_t deviceId, + ftl::Flags<InputTarget::Flags> targetFlags, DeviceId deviceId, std::bitset<MAX_POINTER_ID + 1> touchingPointerIds, std::optional<nsecs_t> firstDownTimeInTarget = std::nullopt); void addHoveringPointerToWindow(const sp<android::gui::WindowInfoHandle>& windowHandle, - int32_t deviceId, int32_t hoveringPointerId); - void removeHoveringPointer(int32_t deviceId, int32_t hoveringPointerId); + DeviceId deviceId, int32_t hoveringPointerId); + void removeHoveringPointer(DeviceId deviceId, int32_t hoveringPointerId); void clearHoveringPointers(); - void removeAllPointersForDevice(int32_t deviceId); + void removeAllPointersForDevice(DeviceId deviceId); void removeWindowByToken(const sp<IBinder>& token); void filterNonAsIsTouchWindows(); // Cancel pointers for current set of windows except the window with particular binder token. - void cancelPointersForWindowsExcept(int32_t deviceId, + void cancelPointersForWindowsExcept(DeviceId deviceId, std::bitset<MAX_POINTER_ID + 1> pointerIds, const sp<IBinder>& token); // Cancel pointers for current set of non-pilfering windows i.e. windows with isPilferingWindow @@ -75,7 +75,7 @@ struct TouchState { bool hasHoveringPointers() const; std::set<sp<android::gui::WindowInfoHandle>> getWindowsWithHoveringPointer( - int32_t deviceId, int32_t pointerId) const; + DeviceId deviceId, int32_t pointerId) const; std::string dump() const; }; |