Cancel ongoing touchpad move gesture if user starts typing
To improve touchpad palm rejection while typing, this change will cancel
any ongoing touchpad move gesture if user starts typing on keyboard. In
this change we:
1. Introduce a new flag to gaurd this change
2. Add behaviour to cancel ongoing gesture
Bug: 301055381
Test: atest inputflinger_tests
Change-Id: I0830cb24f2046380e140cddd71096b8a611c51de
diff --git a/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp b/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp
index 34ca0b3..d331d55 100644
--- a/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp
@@ -449,6 +449,9 @@
if (mPointerCaptured) {
return mCapturedEventConverter.process(*rawEvent);
}
+ if (mMotionAccumulator.getActiveSlotsCount() == 0) {
+ mGestureStartTime = rawEvent->when;
+ }
std::optional<SelfContainedHardwareState> state = mStateConverter.processRawEvent(rawEvent);
if (state) {
updatePalmDetectionMetrics();
@@ -514,7 +517,7 @@
if (mDisplayId) {
MetricsAccumulator& metricsAccumulator = MetricsAccumulator::getInstance();
for (Gesture& gesture : mGesturesToProcess) {
- out += mGestureConverter.handleGesture(when, readTime, gesture);
+ out += mGestureConverter.handleGesture(when, readTime, mGestureStartTime, gesture);
metricsAccumulator.processGesture(mMetricsId, gesture);
}
}
diff --git a/services/inputflinger/reader/mapper/TouchpadInputMapper.h b/services/inputflinger/reader/mapper/TouchpadInputMapper.h
index ece0eca..897edca 100644
--- a/services/inputflinger/reader/mapper/TouchpadInputMapper.h
+++ b/services/inputflinger/reader/mapper/TouchpadInputMapper.h
@@ -113,6 +113,8 @@
// ADISPLAY_ID_NONE to target the focused display. If there is no display target (i.e.
// std::nullopt), all events will be ignored.
std::optional<int32_t> mDisplayId;
+
+ nsecs_t mGestureStartTime{0};
};
} // namespace android
diff --git a/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp b/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp
index 9552104..71cb5a7 100644
--- a/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp
+++ b/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp
@@ -35,8 +35,14 @@
namespace {
+// This will disable the tap to click while the user is typing on a physical keyboard
const bool ENABLE_TOUCHPAD_PALM_REJECTION = input_flags::enable_touchpad_typing_palm_rejection();
+// In addition to v1, v2 will also cancel ongoing move gestures while typing and add delay in
+// re-enabling the tap to click.
+const bool ENABLE_TOUCHPAD_PALM_REJECTION_V2 =
+ input_flags::enable_v2_touchpad_typing_palm_rejection();
+
uint32_t gesturesButtonToMotionEventButton(uint32_t gesturesButton) {
switch (gesturesButton) {
case GESTURES_BUTTON_LEFT:
@@ -131,6 +137,7 @@
}
std::list<NotifyArgs> GestureConverter::handleGesture(nsecs_t when, nsecs_t readTime,
+ nsecs_t gestureStartTime,
const Gesture& gesture) {
if (!mDisplayId) {
// Ignore gestures when there is no target display configured.
@@ -139,13 +146,13 @@
switch (gesture.type) {
case kGestureTypeMove:
- return {handleMove(when, readTime, gesture)};
+ return handleMove(when, readTime, gestureStartTime, gesture);
case kGestureTypeButtonsChange:
return handleButtonsChange(when, readTime, gesture);
case kGestureTypeScroll:
return handleScroll(when, readTime, gesture);
case kGestureTypeFling:
- return handleFling(when, readTime, gesture);
+ return handleFling(when, readTime, gestureStartTime, gesture);
case kGestureTypeSwipe:
return handleMultiFingerSwipe(when, readTime, 3, gesture.details.swipe.dx,
gesture.details.swipe.dy);
@@ -162,18 +169,40 @@
}
}
-NotifyMotionArgs GestureConverter::handleMove(nsecs_t when, nsecs_t readTime,
- const Gesture& gesture) {
+std::list<NotifyArgs> GestureConverter::handleMove(nsecs_t when, nsecs_t readTime,
+ nsecs_t gestureStartTime,
+ const Gesture& gesture) {
float deltaX = gesture.details.move.dx;
float deltaY = gesture.details.move.dy;
- if (ENABLE_TOUCHPAD_PALM_REJECTION && (std::abs(deltaX) > 0 || std::abs(deltaY) > 0)) {
- enableTapToClick();
+ if (ENABLE_TOUCHPAD_PALM_REJECTION_V2) {
+ bool wasHoverCancelled = mIsHoverCancelled;
+ // Gesture will be cancelled if it started before the user started typing and
+ // there is a active IME connection.
+ mIsHoverCancelled = gestureStartTime <= mReaderContext.getLastKeyDownTimestamp() &&
+ mReaderContext.getPolicy()->isInputMethodConnectionActive();
+
+ if (!wasHoverCancelled && mIsHoverCancelled) {
+ // This is the first event of the cancelled gesture, we won't return because we need to
+ // generate a HOVER_EXIT event
+ mPointerController->fade(PointerControllerInterface::Transition::GRADUAL);
+ } else if (mIsHoverCancelled) {
+ return {};
+ }
}
+
rotateDelta(mOrientation, &deltaX, &deltaY);
- mPointerController->setPresentation(PointerControllerInterface::Presentation::POINTER);
- mPointerController->move(deltaX, deltaY);
- mPointerController->unfade(PointerControllerInterface::Transition::IMMEDIATE);
+ // Update the cursor, and enable tap to click if the gesture is not cancelled
+ if (!mIsHoverCancelled) {
+ // handleFling calls hoverMove with zero delta on FLING_TAP_DOWN. Don't enable tap to click
+ // for this case as subsequent handleButtonsChange may choose to ignore this tap.
+ if (ENABLE_TOUCHPAD_PALM_REJECTION && (std::abs(deltaX) > 0 || std::abs(deltaY) > 0)) {
+ enableTapToClick();
+ }
+ mPointerController->setPresentation(PointerControllerInterface::Presentation::POINTER);
+ mPointerController->move(deltaX, deltaY);
+ mPointerController->unfade(PointerControllerInterface::Transition::IMMEDIATE);
+ }
const auto [xCursorPosition, yCursorPosition] =
mEnablePointerChoreographer ? FloatPoint{0, 0} : mPointerController->getPosition();
@@ -187,10 +216,12 @@
const bool down = isPointerDown(mButtonState);
coords.setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, down ? 1.0f : 0.0f);
- const int32_t action = down ? AMOTION_EVENT_ACTION_MOVE : AMOTION_EVENT_ACTION_HOVER_MOVE;
- return makeMotionArgs(when, readTime, action, /* actionButton= */ 0, mButtonState,
- /* pointerCount= */ 1, mFingerProps.data(), &coords, xCursorPosition,
- yCursorPosition);
+ const int32_t action = mIsHoverCancelled
+ ? AMOTION_EVENT_ACTION_HOVER_EXIT
+ : (down ? AMOTION_EVENT_ACTION_MOVE : AMOTION_EVENT_ACTION_HOVER_MOVE);
+ return {makeMotionArgs(when, readTime, action, /* actionButton= */ 0, mButtonState,
+ /* pointerCount= */ 1, mFingerProps.data(), &coords, xCursorPosition,
+ yCursorPosition)};
}
std::list<NotifyArgs> GestureConverter::handleButtonsChange(nsecs_t when, nsecs_t readTime,
@@ -348,6 +379,7 @@
}
std::list<NotifyArgs> GestureConverter::handleFling(nsecs_t when, nsecs_t readTime,
+ nsecs_t gestureStartTime,
const Gesture& gesture) {
switch (gesture.details.fling.fling_state) {
case GESTURES_FLING_START:
@@ -369,10 +401,10 @@
if (!mReaderContext.isPreventingTouchpadTaps()) {
enableTapToClick();
}
- return {handleMove(when, readTime,
- Gesture(kGestureMove, gesture.start_time, gesture.end_time,
- /*dx=*/0.f,
- /*dy=*/0.f))};
+ return handleMove(when, readTime, gestureStartTime,
+ Gesture(kGestureMove, gesture.start_time, gesture.end_time,
+ /*dx=*/0.f,
+ /*dy=*/0.f));
}
break;
default:
diff --git a/services/inputflinger/reader/mapper/gestures/GestureConverter.h b/services/inputflinger/reader/mapper/gestures/GestureConverter.h
index 732a4b2..c51a586 100644
--- a/services/inputflinger/reader/mapper/gestures/GestureConverter.h
+++ b/services/inputflinger/reader/mapper/gestures/GestureConverter.h
@@ -53,17 +53,20 @@
void populateMotionRanges(InputDeviceInfo& info) const;
[[nodiscard]] std::list<NotifyArgs> handleGesture(nsecs_t when, nsecs_t readTime,
+ nsecs_t gestureStartTime,
const Gesture& gesture);
private:
- [[nodiscard]] NotifyMotionArgs handleMove(nsecs_t when, nsecs_t readTime,
- const Gesture& gesture);
+ [[nodiscard]] std::list<NotifyArgs> handleMove(nsecs_t when, nsecs_t readTime,
+ nsecs_t gestureStartTime,
+ const Gesture& gesture);
[[nodiscard]] std::list<NotifyArgs> handleButtonsChange(nsecs_t when, nsecs_t readTime,
const Gesture& gesture);
[[nodiscard]] std::list<NotifyArgs> releaseAllButtons(nsecs_t when, nsecs_t readTime);
[[nodiscard]] std::list<NotifyArgs> handleScroll(nsecs_t when, nsecs_t readTime,
const Gesture& gesture);
[[nodiscard]] std::list<NotifyArgs> handleFling(nsecs_t when, nsecs_t readTime,
+ nsecs_t gestureStartTime,
const Gesture& gesture);
[[nodiscard]] NotifyMotionArgs endScroll(nsecs_t when, nsecs_t readTime);
@@ -83,6 +86,7 @@
float yCursorPosition);
void enableTapToClick();
+ bool mIsHoverCancelled{false};
const int32_t mDeviceId;
InputReaderContext& mReaderContext;