diff options
| -rw-r--r-- | include/input/Input.h | 2 | ||||
| -rw-r--r-- | libs/input/Input.cpp | 4 | ||||
| -rw-r--r-- | services/inputflinger/PreferStylusOverTouchBlocker.cpp | 3 | ||||
| -rw-r--r-- | services/inputflinger/UnwantedInteractionBlocker.cpp | 19 | ||||
| -rw-r--r-- | services/inputflinger/dispatcher/InputDispatcher.cpp | 3 | ||||
| -rw-r--r-- | services/inputflinger/reader/InputReader.cpp | 3 | ||||
| -rw-r--r-- | services/inputflinger/reader/mapper/TouchInputMapper.cpp | 6 |
7 files changed, 22 insertions, 18 deletions
diff --git a/include/input/Input.h b/include/input/Input.h index dd74a51e5e..d298d817f5 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -209,6 +209,8 @@ std::string inputEventSourceToString(int32_t source); bool isFromSource(uint32_t source, uint32_t test); +bool isStylusToolType(uint32_t toolType); + /* * Flags that flow alongside events in the input dispatch system to help with certain * policy decisions such as waking from device sleep. diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index cf5a7e7b05..3685f54a53 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -238,6 +238,10 @@ bool isFromSource(uint32_t source, uint32_t test) { return (source & test) == test; } +bool isStylusToolType(uint32_t toolType) { + return toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS || toolType == AMOTION_EVENT_TOOL_TYPE_ERASER; +} + VerifiedKeyEvent verifiedKeyEventFromKeyEvent(const KeyEvent& event) { return {{VerifiedInputEvent::Type::KEY, event.getDeviceId(), event.getEventTime(), event.getSource(), event.getDisplayId()}, diff --git a/services/inputflinger/PreferStylusOverTouchBlocker.cpp b/services/inputflinger/PreferStylusOverTouchBlocker.cpp index beec2e162e..ddd514676b 100644 --- a/services/inputflinger/PreferStylusOverTouchBlocker.cpp +++ b/services/inputflinger/PreferStylusOverTouchBlocker.cpp @@ -25,8 +25,7 @@ static std::pair<bool, bool> checkToolType(const NotifyMotionArgs& args) { for (size_t i = 0; i < args.pointerCount; i++) { // Make sure we are canceling stylus pointers const int32_t toolType = args.pointerProperties[i].toolType; - if (toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS || - toolType == AMOTION_EVENT_TOOL_TYPE_ERASER) { + if (isStylusToolType(toolType)) { hasStylus = true; } if (toolType == AMOTION_EVENT_TOOL_TYPE_FINGER) { diff --git a/services/inputflinger/UnwantedInteractionBlocker.cpp b/services/inputflinger/UnwantedInteractionBlocker.cpp index ec41025e9d..c170b81475 100644 --- a/services/inputflinger/UnwantedInteractionBlocker.cpp +++ b/services/inputflinger/UnwantedInteractionBlocker.cpp @@ -99,14 +99,17 @@ static bool isPalmRejectionEnabled() { } static int getLinuxToolCode(int toolType) { - if (toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS) { - return BTN_TOOL_PEN; + switch (toolType) { + case AMOTION_EVENT_TOOL_TYPE_STYLUS: + return BTN_TOOL_PEN; + case AMOTION_EVENT_TOOL_TYPE_ERASER: + return BTN_TOOL_RUBBER; + case AMOTION_EVENT_TOOL_TYPE_FINGER: + return BTN_TOOL_FINGER; + default: + ALOGW("Got tool type %" PRId32 ", converting to BTN_TOOL_FINGER", toolType); + return BTN_TOOL_FINGER; } - if (toolType == AMOTION_EVENT_TOOL_TYPE_FINGER) { - return BTN_TOOL_FINGER; - } - ALOGW("Got tool type %" PRId32 ", converting to BTN_TOOL_FINGER", toolType); - return BTN_TOOL_FINGER; } static int32_t getActionUpForPointerId(const NotifyMotionArgs& args, int32_t pointerId) { @@ -195,7 +198,7 @@ NotifyMotionArgs removePointerIds(const NotifyMotionArgs& args, static std::optional<NotifyMotionArgs> removeStylusPointerIds(const NotifyMotionArgs& args) { std::set<int32_t> stylusPointerIds; for (uint32_t i = 0; i < args.pointerCount; i++) { - if (args.pointerProperties[i].toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS) { + if (isStylusToolType(args.pointerProperties[i].toolType)) { stylusPointerIds.insert(args.pointerProperties[i].id); } } diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index f6982173af..4091310193 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -479,8 +479,7 @@ bool windowAcceptsTouchAt(const WindowInfo& windowInfo, int32_t displayId, int32 bool isPointerFromStylus(const MotionEntry& entry, int32_t pointerIndex) { return isFromSource(entry.source, AINPUT_SOURCE_STYLUS) && - (entry.pointerProperties[pointerIndex].toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS || - entry.pointerProperties[pointerIndex].toolType == AMOTION_EVENT_TOOL_TYPE_ERASER); + isStylusToolType(entry.pointerProperties[pointerIndex].toolType); } // Determines if the given window can be targeted as InputTarget::FLAG_FOREGROUND. diff --git a/services/inputflinger/reader/InputReader.cpp b/services/inputflinger/reader/InputReader.cpp index f8b1b3fa6e..f04a6469ea 100644 --- a/services/inputflinger/reader/InputReader.cpp +++ b/services/inputflinger/reader/InputReader.cpp @@ -66,8 +66,7 @@ static bool isStylusPointerGestureStart(const NotifyMotionArgs& motionArgs) { return false; } const auto actionIndex = MotionEvent::getActionIndex(motionArgs.action); - return motionArgs.pointerProperties[actionIndex].toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS || - motionArgs.pointerProperties[actionIndex].toolType == AMOTION_EVENT_TOOL_TYPE_ERASER; + return isStylusToolType(motionArgs.pointerProperties[actionIndex].toolType); } // --- InputReader --- diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.cpp b/services/inputflinger/reader/mapper/TouchInputMapper.cpp index f8d6cf9e7f..7db73dbb9e 100644 --- a/services/inputflinger/reader/mapper/TouchInputMapper.cpp +++ b/services/inputflinger/reader/mapper/TouchInputMapper.cpp @@ -1595,8 +1595,7 @@ std::list<NotifyArgs> TouchInputMapper::cookAndDispatch(nsecs_t when, nsecs_t re uint32_t id = idBits.clearFirstMarkedBit(); const RawPointerData::Pointer& pointer = mCurrentRawState.rawPointerData.pointerForId(id); - if (pointer.toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS || - pointer.toolType == AMOTION_EVENT_TOOL_TYPE_ERASER) { + if (isStylusToolType(pointer.toolType)) { mCurrentCookedState.stylusIdBits.markBit(id); } else if (pointer.toolType == AMOTION_EVENT_TOOL_TYPE_FINGER || pointer.toolType == AMOTION_EVENT_TOOL_TYPE_UNKNOWN) { @@ -1609,8 +1608,7 @@ std::list<NotifyArgs> TouchInputMapper::cookAndDispatch(nsecs_t when, nsecs_t re uint32_t id = idBits.clearFirstMarkedBit(); const RawPointerData::Pointer& pointer = mCurrentRawState.rawPointerData.pointerForId(id); - if (pointer.toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS || - pointer.toolType == AMOTION_EVENT_TOOL_TYPE_ERASER) { + if (isStylusToolType(pointer.toolType)) { mCurrentCookedState.stylusIdBits.markBit(id); } } |