From f6db4c395d2fc0821a6a42aaeb88154eb7183aae Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Thu, 10 Feb 2022 19:46:34 -0800 Subject: Block touches when stylus is down Since we haven't yet added simultaneous touch and stylus support, let's improve the user experience by blocking all touch when the stylus is down. Bug: 210159205 Test: atest inputflinger_tests Change-Id: Id6a6467d7feb7c7d91770ddbd63b92583832d504 (cherry picked from commit a3c8e51901d17f696838d3e8260464f7437468a5) --- services/inputflinger/UnwantedInteractionBlocker.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'services/inputflinger/UnwantedInteractionBlocker.cpp') diff --git a/services/inputflinger/UnwantedInteractionBlocker.cpp b/services/inputflinger/UnwantedInteractionBlocker.cpp index 64dbb8ceb4..f904bfd82e 100644 --- a/services/inputflinger/UnwantedInteractionBlocker.cpp +++ b/services/inputflinger/UnwantedInteractionBlocker.cpp @@ -44,7 +44,8 @@ static std::string toLower(std::string s) { } static bool isFromTouchscreen(int32_t source) { - return isFromSource(source, AINPUT_SOURCE_TOUCHSCREEN); + return isFromSource(source, AINPUT_SOURCE_TOUCHSCREEN) && + !isFromSource(source, AINPUT_SOURCE_STYLUS); } static ::base::TimeTicks toChromeTimestamp(nsecs_t eventTime) { @@ -367,6 +368,14 @@ void UnwantedInteractionBlocker::notifyKey(const NotifyKeyArgs* args) { } void UnwantedInteractionBlocker::notifyMotion(const NotifyMotionArgs* args) { + ftl::StaticVector processedArgs = + mPreferStylusOverTouchBlocker.processMotion(*args); + for (const NotifyMotionArgs& loopArgs : processedArgs) { + notifyMotionInner(&loopArgs); + } +} + +void UnwantedInteractionBlocker::notifyMotionInner(const NotifyMotionArgs* args) { auto it = mPalmRejectors.find(args->deviceId); const bool sendToPalmRejector = it != mPalmRejectors.end() && isFromTouchscreen(args->source); if (!sendToPalmRejector) { @@ -440,6 +449,8 @@ void UnwantedInteractionBlocker::notifyInputDevicesChanged( void UnwantedInteractionBlocker::dump(std::string& dump) { dump += "UnwantedInteractionBlocker:\n"; + dump += " mPreferStylusOverTouchBlocker:\n"; + dump += addPrefix(mPreferStylusOverTouchBlocker.dump(), " "); dump += StringPrintf(" mEnablePalmRejection: %s\n", toString(mEnablePalmRejection)); dump += StringPrintf(" isPalmRejectionEnabled (flag value): %s\n", toString(isPalmRejectionEnabled())); -- cgit v1.2.3-59-g8ed1b