diff options
2 files changed, 39 insertions, 5 deletions
diff --git a/services/accessibility/java/com/android/server/accessibility/gestures/EventDispatcher.java b/services/accessibility/java/com/android/server/accessibility/gestures/EventDispatcher.java index 5ac3b69549c1..667364c9c901 100644 --- a/services/accessibility/java/com/android/server/accessibility/gestures/EventDispatcher.java +++ b/services/accessibility/java/com/android/server/accessibility/gestures/EventDispatcher.java @@ -301,7 +301,7 @@ class EventDispatcher { * @param policyFlags The policy flags associated with the event. */ void sendUpForInjectedDownPointers(MotionEvent prototype, int policyFlags) { - int pointerIdBits = 0; + int pointerIdBits = prototype.getPointerIdBits(); final int pointerCount = prototype.getPointerCount(); for (int i = 0; i < pointerCount; i++) { final int pointerId = prototype.getPointerId(i); @@ -309,10 +309,10 @@ class EventDispatcher { if (!isInjectedPointerDown(pointerId)) { continue; } - pointerIdBits |= (1 << pointerId); - final int action = computeInjectionAction(MotionEvent.ACTION_UP, i); + final int action = computeInjectionAction(MotionEvent.ACTION_POINTER_UP, i); sendMotionEvent( prototype, action, mState.getLastReceivedEvent(), pointerIdBits, policyFlags); + pointerIdBits &= ~(1 << pointerId); } } } diff --git a/services/tests/servicestests/src/com/android/server/accessibility/gestures/TouchExplorerTest.java b/services/tests/servicestests/src/com/android/server/accessibility/gestures/TouchExplorerTest.java index a4ceadb3028b..9053234aa220 100644 --- a/services/tests/servicestests/src/com/android/server/accessibility/gestures/TouchExplorerTest.java +++ b/services/tests/servicestests/src/com/android/server/accessibility/gestures/TouchExplorerTest.java @@ -89,9 +89,12 @@ public class TouchExplorerTest { @Override public void onMotionEvent(MotionEvent event, MotionEvent rawEvent, int policyFlags) { - MotionEventMatcher lastEventMatcher = new MotionEventMatcher(mLastEvent); mEvents.add(0, event.copy()); - assertThat(rawEvent, lastEventMatcher); + // LastEvent may not match if we're clearing the state + if (mLastEvent != null) { + MotionEventMatcher lastEventMatcher = new MotionEventMatcher(mLastEvent); + assertThat(rawEvent, lastEventMatcher); + } } @Override @@ -126,6 +129,31 @@ public class TouchExplorerTest { } @Test + public void upEventWhenInTwoFingerMove_clearsState() { + goFromStateClearTo(STATE_MOVING_2FINGERS); + + send(upEvent()); + assertState(STATE_CLEAR); + } + + @Test + public void clearEventsWhenInTwoFingerMove_clearsStateAndSendsUp() { + goFromStateClearTo(STATE_MOVING_2FINGERS); + + // Clear last event so we don't try to match against anything when cleanup events are sent + // for the clear + mLastEvent = null; + mTouchExplorer.clearEvents(InputDevice.SOURCE_TOUCHSCREEN); + assertState(STATE_CLEAR); + List<MotionEvent> events = getCapturedEvents(); + assertCapturedEvents( + MotionEvent.ACTION_DOWN, + MotionEvent.ACTION_POINTER_DOWN, + MotionEvent.ACTION_POINTER_UP, + MotionEvent.ACTION_UP); + } + + @Test public void testTwoFingersDrag_shouldDraggingAndActionDown() { goFromStateClearTo(STATE_DRAGGING_2FINGERS); @@ -268,6 +296,12 @@ public class TouchExplorerTest { DEFAULT_Y, 0)); } + private MotionEvent upEvent() { + MotionEvent event = downEvent(); + event.setAction(MotionEvent.ACTION_UP); + return event; + } + private MotionEvent pointerDownEvent() { final int secondPointerId = 0x0100; final int action = MotionEvent.ACTION_POINTER_DOWN | secondPointerId; |