Ensure stylus buttons generate events consistently
Add tests to verify that a touchscreen stylus and fused/unfused external
styluses generate button events consistently.
Make changes in TouchInputMapper to enforce consistentcy for external
stylus buttons. In particular, we allow the external stylus's button
state to be applied to the touches even when there is no fusion in
progress.
Bug: 246394583
Test: atest inputflinger_tests
Change-Id: I645481db18e1bec8b61d8309aa4f02afcf1a5383
diff --git a/services/inputflinger/tests/UinputDevice.cpp b/services/inputflinger/tests/UinputDevice.cpp
index 1051aa9..97a2614 100644
--- a/services/inputflinger/tests/UinputDevice.cpp
+++ b/services/inputflinger/tests/UinputDevice.cpp
@@ -160,11 +160,14 @@
// --- UinputTouchScreen ---
UinputTouchScreen::UinputTouchScreen(const Rect& size)
- : UinputDevice(DEVICE_NAME, PRODUCT_ID), mSize(size) {}
+ : UinputKeyboard(DEVICE_NAME, PRODUCT_ID,
+ {BTN_TOUCH, BTN_TOOL_PEN, BTN_STYLUS, BTN_STYLUS2, BTN_STYLUS3}),
+ mSize(size) {}
void UinputTouchScreen::configureDevice(int fd, uinput_user_dev* device) {
+ UinputKeyboard::configureDevice(fd, device);
+
// Setup the touch screen device
- ioctl(fd, UI_SET_EVBIT, EV_KEY);
ioctl(fd, UI_SET_EVBIT, EV_REL);
ioctl(fd, UI_SET_EVBIT, EV_ABS);
ioctl(fd, UI_SET_ABSBIT, ABS_MT_SLOT);
@@ -174,10 +177,6 @@
ioctl(fd, UI_SET_ABSBIT, ABS_MT_TRACKING_ID);
ioctl(fd, UI_SET_ABSBIT, ABS_MT_TOOL_TYPE);
ioctl(fd, UI_SET_PROPBIT, INPUT_PROP_DIRECT);
- ioctl(fd, UI_SET_KEYBIT, BTN_TOUCH);
- ioctl(fd, UI_SET_KEYBIT, BTN_STYLUS);
- ioctl(fd, UI_SET_KEYBIT, BTN_STYLUS2);
- ioctl(fd, UI_SET_KEYBIT, BTN_STYLUS3);
device->absmin[ABS_MT_SLOT] = RAW_SLOT_MIN;
device->absmax[ABS_MT_SLOT] = RAW_SLOT_MAX;
@@ -229,10 +228,6 @@
injectEvent(EV_SYN, SYN_REPORT, 0);
}
-void UinputTouchScreen::sendKey(int32_t scanCode, int32_t value) {
- injectEvent(EV_KEY, scanCode, value);
-}
-
// Get the center x, y base on the range definition.
const Point UinputTouchScreen::getCenterPoint() {
return Point(mSize.left + mSize.width() / 2, mSize.top + mSize.height() / 2);