summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Prabir Pradhan <prabirmsp@google.com> 2023-10-24 20:34:26 +0000
committer Prabir Pradhan <prabirmsp@google.com> 2023-10-24 20:38:37 +0000
commita2dce3e13b3b86ac0bf0e6ce081cc594029fac95 (patch)
treeab4c4c13ac3c8ec7822569e157306a06a0eff57a
parent97c05f176eaa4f68e78f29eeb39c156274c244d8 (diff)
Prevent keyboards from being recognized as a stylus
We are getting reports of keyboards and other peripherals being misconfigured as a stylus, because they report support for stylus buttons. To eliminate some of these misconfigurations, prevent anything detected as a alphabetical keyboard from being categorized as a stylus. Bug: 293996865 Test: None (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:3c28b94505b5c6edaeb7e0df3ace7cf3f8125887) (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:0824e928e70da8c0fb78d9793a5a3f8f4f8f9db0) Merged-In: I3f071d2ac6a2b70abc1130b4d5df1509452bb63b Change-Id: I3f071d2ac6a2b70abc1130b4d5df1509452bb63b
-rw-r--r--services/inputflinger/reader/EventHub.cpp3
-rw-r--r--services/inputflinger/tests/InputReader_test.cpp18
2 files changed, 20 insertions, 1 deletions
diff --git a/services/inputflinger/reader/EventHub.cpp b/services/inputflinger/reader/EventHub.cpp
index 0354164155..c468d45c02 100644
--- a/services/inputflinger/reader/EventHub.cpp
+++ b/services/inputflinger/reader/EventHub.cpp
@@ -2409,7 +2409,8 @@ void EventHub::openDeviceLocked(const std::string& devicePath) {
}
// See if this device has any stylus buttons that we would want to fuse with touch data.
- if (!device->classes.any(InputDeviceClass::TOUCH | InputDeviceClass::TOUCH_MT)) {
+ if (!device->classes.any(InputDeviceClass::TOUCH | InputDeviceClass::TOUCH_MT) &&
+ !device->classes.any(InputDeviceClass::ALPHAKEY)) {
for (int32_t keycode : STYLUS_BUTTON_KEYCODES) {
if (device->hasKeycodeLocked(keycode)) {
device->classes |= InputDeviceClass::EXTERNAL_STYLUS;
diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp
index 5141acb5b9..a70f10b81c 100644
--- a/services/inputflinger/tests/InputReader_test.cpp
+++ b/services/inputflinger/tests/InputReader_test.cpp
@@ -1476,6 +1476,24 @@ TEST_F(InputReaderIntegrationTest, ExternalStylusesButtons) {
AllOf(UP, WithKeyCode(AKEYCODE_STYLUS_BUTTON_TERTIARY))));
}
+TEST_F(InputReaderIntegrationTest, KeyboardWithStylusButtons) {
+ std::unique_ptr<UinputKeyboard> keyboard =
+ createUinputDevice<UinputKeyboard>("KeyboardWithStylusButtons", /*productId=*/99,
+ std::initializer_list<int>{KEY_Q, KEY_W, KEY_E,
+ KEY_R, KEY_T, KEY_Y,
+ BTN_STYLUS, BTN_STYLUS2,
+ BTN_STYLUS3});
+ ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertInputDevicesChanged());
+
+ const auto device = findDeviceByName(keyboard->getName());
+ ASSERT_TRUE(device.has_value());
+
+ // An alphabetical keyboard that reports stylus buttons should not be recognized as a stylus.
+ ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, device->getSources())
+ << "Unexpected source " << inputEventSourceToString(device->getSources()).c_str();
+ ASSERT_EQ(AINPUT_KEYBOARD_TYPE_ALPHABETIC, device->getKeyboardType());
+}
+
/**
* 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