KeyboardInputMapper: Miscelaneous code cleanup
Initialize all members at construction, make some functions static,
remove some unused parameters, and use an optional return type for
clarity.
There should be no behavior changes in this CL.
Bug: 245989146
Test: atest inputflinger_tests
Change-Id: Ia57d1c88f0d60938a5e803f51d99c335e7fcf459
diff --git a/services/inputflinger/reader/mapper/KeyboardInputMapper.h b/services/inputflinger/reader/mapper/KeyboardInputMapper.h
index 8d72ee9..3dd570d 100644
--- a/services/inputflinger/reader/mapper/KeyboardInputMapper.h
+++ b/services/inputflinger/reader/mapper/KeyboardInputMapper.h
@@ -23,7 +23,7 @@
class KeyboardInputMapper : public InputMapper {
public:
KeyboardInputMapper(InputDeviceContext& deviceContext, uint32_t source, int32_t keyboardType);
- virtual ~KeyboardInputMapper();
+ ~KeyboardInputMapper() override = default;
uint32_t getSources() const override;
void populateDeviceInfo(InputDeviceInfo* deviceInfo) override;
@@ -47,58 +47,54 @@
private:
// The current viewport.
- std::optional<DisplayViewport> mViewport;
+ std::optional<DisplayViewport> mViewport{};
struct KeyDown {
- nsecs_t downTime;
- int32_t keyCode;
- int32_t scanCode;
+ nsecs_t downTime{};
+ int32_t keyCode{};
+ int32_t scanCode{};
};
- uint32_t mSource;
- int32_t mKeyboardType;
+ uint32_t mSource{};
+ int32_t mKeyboardType{};
- std::vector<KeyDown> mKeyDowns; // keys that are down
- int32_t mMetaState;
+ std::vector<KeyDown> mKeyDowns{}; // keys that are down
+ int32_t mMetaState{};
- int32_t mCurrentHidUsage; // most recent HID usage seen this packet, or 0 if none
+ int32_t mCurrentHidUsage{}; // most recent HID usage seen this packet, or 0 if none
struct LedState {
- bool avail; // led is available
- bool on; // we think the led is currently on
+ bool avail{}; // led is available
+ bool on{}; // we think the led is currently on
};
- LedState mCapsLockLedState;
- LedState mNumLockLedState;
- LedState mScrollLockLedState;
+ LedState mCapsLockLedState{};
+ LedState mNumLockLedState{};
+ LedState mScrollLockLedState{};
// Immutable configuration parameters.
struct Parameters {
- bool orientationAware;
- bool handlesKeyRepeat;
- bool doNotWakeByDefault;
- } mParameters;
+ bool orientationAware{};
+ bool handlesKeyRepeat{};
+ bool doNotWakeByDefault{};
+ } mParameters{};
void configureParameters();
- void dumpParameters(std::string& dump);
+ void dumpParameters(std::string& dump) const;
int32_t getOrientation();
int32_t getDisplayId();
- bool isKeyboardOrGamepadKey(int32_t scanCode);
- bool isMediaKey(int32_t keyCode);
-
[[nodiscard]] std::list<NotifyArgs> processKey(nsecs_t when, nsecs_t readTime, bool down,
int32_t scanCode, int32_t usageCode);
bool updateMetaStateIfNeeded(int32_t keyCode, bool down);
- ssize_t findKeyDown(int32_t scanCode);
+ std::optional<size_t> findKeyDownIndex(int32_t scanCode);
void resetLedState();
void initializeLedState(LedState& ledState, int32_t led);
void updateLedStateForModifier(LedState& ledState, int32_t led, int32_t modifier, bool reset);
- std::optional<DisplayViewport> findViewport(nsecs_t when,
- const InputReaderConfiguration* config);
+ std::optional<DisplayViewport> findViewport(const InputReaderConfiguration* config);
[[nodiscard]] std::list<NotifyArgs> cancelAllDownKeys(nsecs_t when);
};