Use std::vector when sending keyCodes
We are currently sending a raw pointer to keyCodes and a size. The size
is also used for outFlags, but it's not well-documented anyways.
Eventually, we may want to just return the flags instead of returning
the boolean.
For now, though, just change the incoming parameter to a vector to make
it less errorprone.
Bug: 228005926
Test: atest libinput_tests inputflinger_tests
Change-Id: I6cc2f5d9b3b7b7c3c120a779ea4cfb4b06e27d1e
diff --git a/services/inputflinger/reader/include/EventHub.h b/services/inputflinger/reader/include/EventHub.h
index 130c556..5453ebb 100644
--- a/services/inputflinger/reader/include/EventHub.h
+++ b/services/inputflinger/reader/include/EventHub.h
@@ -311,7 +311,7 @@
/*
* Examine key input devices for specific framework keycode support
*/
- virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, const int32_t* keyCodes,
+ virtual bool markSupportedKeyCodes(int32_t deviceId, const std::vector<int32_t>& keyCodes,
uint8_t* outFlags) const = 0;
virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const = 0;
@@ -488,7 +488,7 @@
status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis,
int32_t* outValue) const override final;
- bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, const int32_t* keyCodes,
+ bool markSupportedKeyCodes(int32_t deviceId, const std::vector<int32_t>& keyCodes,
uint8_t* outFlags) const override final;
size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) override final;
diff --git a/services/inputflinger/reader/include/InputDevice.h b/services/inputflinger/reader/include/InputDevice.h
index 728020e..51872ac 100644
--- a/services/inputflinger/reader/include/InputDevice.h
+++ b/services/inputflinger/reader/include/InputDevice.h
@@ -88,7 +88,7 @@
int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
int32_t getKeyCodeForKeyLocation(int32_t locationKeyCode) const;
- bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, const int32_t* keyCodes,
+ bool markSupportedKeyCodes(uint32_t sourceMask, const std::vector<int32_t>& keyCodes,
uint8_t* outFlags);
void vibrate(const VibrationSequence& sequence, ssize_t repeat, int32_t token);
void cancelVibrate(int32_t token);
@@ -324,9 +324,9 @@
inline status_t getAbsoluteAxisValue(int32_t code, int32_t* outValue) const {
return mEventHub->getAbsoluteAxisValue(mId, code, outValue);
}
- inline bool markSupportedKeyCodes(size_t numCodes, const int32_t* keyCodes,
+ inline bool markSupportedKeyCodes(const std::vector<int32_t>& keyCodes,
uint8_t* outFlags) const {
- return mEventHub->markSupportedKeyCodes(mId, numCodes, keyCodes, outFlags);
+ return mEventHub->markSupportedKeyCodes(mId, keyCodes, outFlags);
}
inline bool hasScanCode(int32_t scanCode) const {
return mEventHub->hasScanCode(mId, scanCode);
diff --git a/services/inputflinger/reader/include/InputReader.h b/services/inputflinger/reader/include/InputReader.h
index daeaa1d..ae41e01 100644
--- a/services/inputflinger/reader/include/InputReader.h
+++ b/services/inputflinger/reader/include/InputReader.h
@@ -73,7 +73,7 @@
void toggleCapsLockState(int32_t deviceId) override;
- bool hasKeys(int32_t deviceId, uint32_t sourceMask, size_t numCodes, const int32_t* keyCodes,
+ bool hasKeys(int32_t deviceId, uint32_t sourceMask, const std::vector<int32_t>& keyCodes,
uint8_t* outFlags) override;
void requestRefreshConfiguration(uint32_t changes) override;
@@ -237,8 +237,9 @@
typedef int32_t (InputDevice::*GetStateFunc)(uint32_t sourceMask, int32_t code);
int32_t getStateLocked(int32_t deviceId, uint32_t sourceMask, int32_t code,
GetStateFunc getStateFunc) REQUIRES(mLock);
- bool markSupportedKeyCodesLocked(int32_t deviceId, uint32_t sourceMask, size_t numCodes,
- const int32_t* keyCodes, uint8_t* outFlags) REQUIRES(mLock);
+ bool markSupportedKeyCodesLocked(int32_t deviceId, uint32_t sourceMask,
+ const std::vector<int32_t>& keyCodes, uint8_t* outFlags)
+ REQUIRES(mLock);
// find an InputDevice from an InputDevice id
InputDevice* findInputDeviceLocked(int32_t deviceId) const REQUIRES(mLock);