Loading services/inputflinger/reader/mapper/KeyboardInputMapper.cpp +8 −3 Original line number Diff line number Diff line Loading @@ -243,11 +243,16 @@ std::list<NotifyArgs> KeyboardInputMapper::process(const RawEvent& rawEvent) { mHidUsageAccumulator.process(rawEvent); switch (rawEvent.type) { case EV_KEY: { int32_t scanCode = rawEvent.code; // Skip processing repeated keys (value == 2) since auto repeat is handled by Android // internally. if (rawEvent.value == 2) { break; } const int32_t scanCode = rawEvent.code; if (isSupportedScanCode(scanCode)) { out += processKey(rawEvent.when, rawEvent.readTime, rawEvent.value != 0, scanCode, mHidUsageAccumulator.consumeCurrentHidUsage()); out += processKey(rawEvent.when, rawEvent.readTime, rawEvent.value != 0, scanCode, mHidUsageAccumulator.consumeCurrentHidUsage()); } break; } Loading services/inputflinger/tests/KeyboardInputMapper_test.cpp +23 −0 Original line number Diff line number Diff line Loading @@ -20,16 +20,19 @@ #include "InputMapperTest.h" #include "InterfaceMocks.h" #include "TestEventMatchers.h" #define TAG "KeyboardInputMapper_test" namespace android { using testing::_; using testing::AllOf; using testing::Args; using testing::DoAll; using testing::Return; using testing::SetArgPointee; using testing::VariantWith; /** * Unit tests for KeyboardInputMapper. Loading Loading @@ -86,4 +89,24 @@ TEST_F(KeyboardInputMapperUnitTest, KeyPressTimestampRecorded) { } } TEST_F(KeyboardInputMapperUnitTest, RepeatEventsDiscarded) { std::list<NotifyArgs> args; args += process(ARBITRARY_TIME, EV_KEY, KEY_0, 1); args += process(ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0); args += process(ARBITRARY_TIME, EV_KEY, KEY_0, 2); args += process(ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0); args += process(ARBITRARY_TIME, EV_KEY, KEY_0, 0); args += process(ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0); EXPECT_THAT(args, ElementsAre(VariantWith<NotifyKeyArgs>(AllOf(WithKeyAction(AKEY_EVENT_ACTION_DOWN), WithKeyCode(AKEYCODE_0), WithScanCode(KEY_0))), VariantWith<NotifyKeyArgs>(AllOf(WithKeyAction(AKEY_EVENT_ACTION_UP), WithKeyCode(AKEYCODE_0), WithScanCode(KEY_0))))); } } // namespace android services/inputflinger/tests/TestEventMatchers.h +28 −0 Original line number Diff line number Diff line Loading @@ -540,6 +540,34 @@ inline WithKeyCodeMatcher WithKeyCode(int32_t keyCode) { return WithKeyCodeMatcher(keyCode); } /// Scan code class WithScanCodeMatcher { public: using is_gtest_matcher = void; explicit WithScanCodeMatcher(int32_t scanCode) : mScanCode(scanCode) {} bool MatchAndExplain(const NotifyKeyArgs& args, std::ostream*) const { return mScanCode == args.scanCode; } bool MatchAndExplain(const KeyEvent& event, std::ostream*) const { return mScanCode == event.getKeyCode(); } void DescribeTo(std::ostream* os) const { *os << "with scan code " << KeyEvent::getLabel(mScanCode); } void DescribeNegationTo(std::ostream* os) const { *os << "wrong scan code"; } private: const int32_t mScanCode; }; inline WithScanCodeMatcher WithScanCode(int32_t scanCode) { return WithScanCodeMatcher(scanCode); } /// EventId class WithEventIdMatcher { public: Loading Loading
services/inputflinger/reader/mapper/KeyboardInputMapper.cpp +8 −3 Original line number Diff line number Diff line Loading @@ -243,11 +243,16 @@ std::list<NotifyArgs> KeyboardInputMapper::process(const RawEvent& rawEvent) { mHidUsageAccumulator.process(rawEvent); switch (rawEvent.type) { case EV_KEY: { int32_t scanCode = rawEvent.code; // Skip processing repeated keys (value == 2) since auto repeat is handled by Android // internally. if (rawEvent.value == 2) { break; } const int32_t scanCode = rawEvent.code; if (isSupportedScanCode(scanCode)) { out += processKey(rawEvent.when, rawEvent.readTime, rawEvent.value != 0, scanCode, mHidUsageAccumulator.consumeCurrentHidUsage()); out += processKey(rawEvent.when, rawEvent.readTime, rawEvent.value != 0, scanCode, mHidUsageAccumulator.consumeCurrentHidUsage()); } break; } Loading
services/inputflinger/tests/KeyboardInputMapper_test.cpp +23 −0 Original line number Diff line number Diff line Loading @@ -20,16 +20,19 @@ #include "InputMapperTest.h" #include "InterfaceMocks.h" #include "TestEventMatchers.h" #define TAG "KeyboardInputMapper_test" namespace android { using testing::_; using testing::AllOf; using testing::Args; using testing::DoAll; using testing::Return; using testing::SetArgPointee; using testing::VariantWith; /** * Unit tests for KeyboardInputMapper. Loading Loading @@ -86,4 +89,24 @@ TEST_F(KeyboardInputMapperUnitTest, KeyPressTimestampRecorded) { } } TEST_F(KeyboardInputMapperUnitTest, RepeatEventsDiscarded) { std::list<NotifyArgs> args; args += process(ARBITRARY_TIME, EV_KEY, KEY_0, 1); args += process(ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0); args += process(ARBITRARY_TIME, EV_KEY, KEY_0, 2); args += process(ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0); args += process(ARBITRARY_TIME, EV_KEY, KEY_0, 0); args += process(ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0); EXPECT_THAT(args, ElementsAre(VariantWith<NotifyKeyArgs>(AllOf(WithKeyAction(AKEY_EVENT_ACTION_DOWN), WithKeyCode(AKEYCODE_0), WithScanCode(KEY_0))), VariantWith<NotifyKeyArgs>(AllOf(WithKeyAction(AKEY_EVENT_ACTION_UP), WithKeyCode(AKEYCODE_0), WithScanCode(KEY_0))))); } } // namespace android
services/inputflinger/tests/TestEventMatchers.h +28 −0 Original line number Diff line number Diff line Loading @@ -540,6 +540,34 @@ inline WithKeyCodeMatcher WithKeyCode(int32_t keyCode) { return WithKeyCodeMatcher(keyCode); } /// Scan code class WithScanCodeMatcher { public: using is_gtest_matcher = void; explicit WithScanCodeMatcher(int32_t scanCode) : mScanCode(scanCode) {} bool MatchAndExplain(const NotifyKeyArgs& args, std::ostream*) const { return mScanCode == args.scanCode; } bool MatchAndExplain(const KeyEvent& event, std::ostream*) const { return mScanCode == event.getKeyCode(); } void DescribeTo(std::ostream* os) const { *os << "with scan code " << KeyEvent::getLabel(mScanCode); } void DescribeNegationTo(std::ostream* os) const { *os << "wrong scan code"; } private: const int32_t mScanCode; }; inline WithScanCodeMatcher WithScanCode(int32_t scanCode) { return WithScanCodeMatcher(scanCode); } /// EventId class WithEventIdMatcher { public: Loading