From 128eab19fbb226cdd79acb010a79100ed49fd162 Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Thu, 23 May 2019 10:25:59 +0800 Subject: Clear events when ACTION_CANCEL is present When ACTION_CANCEL is present in the queue, we can clear the existing events from the queue. This will also help pilfer pointers, because this will allow extra time for the inputMonitor to pilfer pointers and prevent unwanted behaviour. Bug: 130352502 Test: open maps, then swipe from left or right. Observe that the map does not shift in response to this gesture. Change-Id: I6b3798f73da3dd26369d1d7887e24fde61333c31 --- libs/input/InputTransport.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'libs') diff --git a/libs/input/InputTransport.cpp b/libs/input/InputTransport.cpp index 2a5a6048ed..d02cb8ea46 100644 --- a/libs/input/InputTransport.cpp +++ b/libs/input/InputTransport.cpp @@ -84,6 +84,10 @@ inline static float lerp(float a, float b, float alpha) { return a + alpha * (b - a); } +inline static bool isPointerEvent(int32_t source) { + return (source & AINPUT_SOURCE_CLASS_POINTER) == AINPUT_SOURCE_CLASS_POINTER; +} + // --- InputMessage --- bool InputMessage::isValid(size_t actualSize) const { @@ -637,6 +641,16 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, mChannel->getName().c_str()); #endif break; + } else if (isPointerEvent(mMsg.body.motion.source) && + mMsg.body.motion.action == AMOTION_EVENT_ACTION_CANCEL) { + // No need to process events that we are going to cancel anyways + const size_t count = batch.samples.size(); + for (size_t i = 0; i < count; i++) { + const InputMessage& msg = batch.samples.itemAt(i); + sendFinishedSignal(msg.body.motion.seq, false); + } + batch.samples.removeItemsAt(0, count); + mBatches.removeAt(batchIndex); } else { // We cannot append to the batch in progress, so we need to consume // the previous batch right now and defer the new message until later. @@ -759,8 +773,7 @@ status_t InputConsumer::consumeSamples(InputEventFactoryInterface* factory, } void InputConsumer::updateTouchState(InputMessage& msg) { - if (!mResampleTouch || - !(msg.body.motion.source & AINPUT_SOURCE_CLASS_POINTER)) { + if (!mResampleTouch || !isPointerEvent(msg.body.motion.source)) { return; } @@ -872,7 +885,7 @@ void InputConsumer::rewriteMessage(TouchState& state, InputMessage& msg) { void InputConsumer::resampleTouchState(nsecs_t sampleTime, MotionEvent* event, const InputMessage* next) { if (!mResampleTouch - || !(event->getSource() & AINPUT_SOURCE_CLASS_POINTER) + || !(isPointerEvent(event->getSource())) || event->getAction() != AMOTION_EVENT_ACTION_MOVE) { return; } -- cgit v1.2.3-59-g8ed1b