Loading services/inputflinger/tests/InputReader_test.cpp +22 −0 Original line number Diff line number Diff line Loading @@ -1494,6 +1494,28 @@ TEST_F(InputReaderIntegrationTest, KeyboardWithStylusButtons) { ASSERT_EQ(AINPUT_KEYBOARD_TYPE_ALPHABETIC, device->getKeyboardType()); } TEST_F(InputReaderIntegrationTest, HidUsageKeyboardIsNotAStylus) { // Create a Uinput keyboard that simulates a keyboard that can report HID usage codes. The // hid-input driver reports HID usage codes using the value for EV_MSC MSC_SCAN event. std::unique_ptr<UinputKeyboardWithHidUsage> keyboard = createUinputDevice<UinputKeyboardWithHidUsage>( std::initializer_list<int>{KEY_VOLUMEUP, KEY_VOLUMEDOWN}); ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertInputDevicesChanged()); const auto device = findDeviceByName(keyboard->getName()); ASSERT_TRUE(device.has_value()); ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, device->getSources()) << "Unexpected source " << inputEventSourceToString(device->getSources()).c_str(); // If a device supports reporting HID usage codes, it shouldn't automatically support // stylus keys. const std::vector<int> keycodes{AKEYCODE_STYLUS_BUTTON_PRIMARY}; uint8_t outFlags[] = {0}; ASSERT_TRUE(mReader->hasKeys(device->getId(), AINPUT_SOURCE_KEYBOARD, keycodes, outFlags)); ASSERT_EQ(0, outFlags[0]) << "Keyboard should not have stylus button"; } /** * The Steam controller sends BTN_GEAR_DOWN and BTN_GEAR_UP for the two "paddle" buttons * on the back. In this test, we make sure that BTN_GEAR_DOWN / BTN_WHEEL and BTN_GEAR_UP Loading services/inputflinger/tests/UinputDevice.cpp +12 −0 Original line number Diff line number Diff line Loading @@ -157,6 +157,18 @@ void UinputExternalStylusWithPressure::setPressure(int32_t pressure) { injectEvent(EV_SYN, SYN_REPORT, 0); } // --- UinputKeyboardWithHidUsage --- UinputKeyboardWithHidUsage::UinputKeyboardWithHidUsage(std::initializer_list<int> keys) : UinputKeyboard(DEVICE_NAME, PRODUCT_ID, keys) {} void UinputKeyboardWithHidUsage::configureDevice(int fd, uinput_user_dev* device) { UinputKeyboard::configureDevice(fd, device); ioctl(fd, UI_SET_EVBIT, EV_MSC); ioctl(fd, UI_SET_MSCBIT, MSC_SCAN); } // --- UinputTouchScreen --- UinputTouchScreen::UinputTouchScreen(const Rect& size) Loading services/inputflinger/tests/UinputDevice.h +18 −1 Original line number Diff line number Diff line Loading @@ -165,13 +165,30 @@ private: explicit UinputExternalStylusWithPressure(); }; // --- UinputKeyboardWithUsage --- // A keyboard that supports EV_MSC MSC_SCAN through which it can report HID usage codes. class UinputKeyboardWithHidUsage : public UinputKeyboard { public: static constexpr const char* DEVICE_NAME = "Test Uinput Keyboard With Usage"; static constexpr int16_t PRODUCT_ID = 47; template <class D, class... Ts> friend std::unique_ptr<D> createUinputDevice(Ts... args); protected: explicit UinputKeyboardWithHidUsage(std::initializer_list<int> keys); void configureDevice(int fd, uinput_user_dev* device) override; }; // --- UinputTouchScreen --- // A multi-touch touchscreen device with specific size that also supports styluses. class UinputTouchScreen : public UinputKeyboard { public: static constexpr const char* DEVICE_NAME = "Test Uinput Touch Screen"; static constexpr int16_t PRODUCT_ID = 47; static constexpr int16_t PRODUCT_ID = 48; static const int32_t RAW_TOUCH_MIN = 0; static const int32_t RAW_TOUCH_MAX = 31; Loading Loading
services/inputflinger/tests/InputReader_test.cpp +22 −0 Original line number Diff line number Diff line Loading @@ -1494,6 +1494,28 @@ TEST_F(InputReaderIntegrationTest, KeyboardWithStylusButtons) { ASSERT_EQ(AINPUT_KEYBOARD_TYPE_ALPHABETIC, device->getKeyboardType()); } TEST_F(InputReaderIntegrationTest, HidUsageKeyboardIsNotAStylus) { // Create a Uinput keyboard that simulates a keyboard that can report HID usage codes. The // hid-input driver reports HID usage codes using the value for EV_MSC MSC_SCAN event. std::unique_ptr<UinputKeyboardWithHidUsage> keyboard = createUinputDevice<UinputKeyboardWithHidUsage>( std::initializer_list<int>{KEY_VOLUMEUP, KEY_VOLUMEDOWN}); ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertInputDevicesChanged()); const auto device = findDeviceByName(keyboard->getName()); ASSERT_TRUE(device.has_value()); ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, device->getSources()) << "Unexpected source " << inputEventSourceToString(device->getSources()).c_str(); // If a device supports reporting HID usage codes, it shouldn't automatically support // stylus keys. const std::vector<int> keycodes{AKEYCODE_STYLUS_BUTTON_PRIMARY}; uint8_t outFlags[] = {0}; ASSERT_TRUE(mReader->hasKeys(device->getId(), AINPUT_SOURCE_KEYBOARD, keycodes, outFlags)); ASSERT_EQ(0, outFlags[0]) << "Keyboard should not have stylus button"; } /** * The Steam controller sends BTN_GEAR_DOWN and BTN_GEAR_UP for the two "paddle" buttons * on the back. In this test, we make sure that BTN_GEAR_DOWN / BTN_WHEEL and BTN_GEAR_UP Loading
services/inputflinger/tests/UinputDevice.cpp +12 −0 Original line number Diff line number Diff line Loading @@ -157,6 +157,18 @@ void UinputExternalStylusWithPressure::setPressure(int32_t pressure) { injectEvent(EV_SYN, SYN_REPORT, 0); } // --- UinputKeyboardWithHidUsage --- UinputKeyboardWithHidUsage::UinputKeyboardWithHidUsage(std::initializer_list<int> keys) : UinputKeyboard(DEVICE_NAME, PRODUCT_ID, keys) {} void UinputKeyboardWithHidUsage::configureDevice(int fd, uinput_user_dev* device) { UinputKeyboard::configureDevice(fd, device); ioctl(fd, UI_SET_EVBIT, EV_MSC); ioctl(fd, UI_SET_MSCBIT, MSC_SCAN); } // --- UinputTouchScreen --- UinputTouchScreen::UinputTouchScreen(const Rect& size) Loading
services/inputflinger/tests/UinputDevice.h +18 −1 Original line number Diff line number Diff line Loading @@ -165,13 +165,30 @@ private: explicit UinputExternalStylusWithPressure(); }; // --- UinputKeyboardWithUsage --- // A keyboard that supports EV_MSC MSC_SCAN through which it can report HID usage codes. class UinputKeyboardWithHidUsage : public UinputKeyboard { public: static constexpr const char* DEVICE_NAME = "Test Uinput Keyboard With Usage"; static constexpr int16_t PRODUCT_ID = 47; template <class D, class... Ts> friend std::unique_ptr<D> createUinputDevice(Ts... args); protected: explicit UinputKeyboardWithHidUsage(std::initializer_list<int> keys); void configureDevice(int fd, uinput_user_dev* device) override; }; // --- UinputTouchScreen --- // A multi-touch touchscreen device with specific size that also supports styluses. class UinputTouchScreen : public UinputKeyboard { public: static constexpr const char* DEVICE_NAME = "Test Uinput Touch Screen"; static constexpr int16_t PRODUCT_ID = 47; static constexpr int16_t PRODUCT_ID = 48; static const int32_t RAW_TOUCH_MIN = 0; static const int32_t RAW_TOUCH_MAX = 31; Loading