Loading services/java/com/android/server/accessibility/AccessibilityInputFilter.java +7 −4 Original line number Original line Diff line number Diff line Loading @@ -119,13 +119,16 @@ class AccessibilityInputFilter extends InputFilter implements EventStreamTransfo mCurrentDeviceId = deviceId; mCurrentDeviceId = deviceId; } } mPm.userActivity(event.getEventTime(), false); mPm.userActivity(event.getEventTime(), false); MotionEvent motionEvent = (MotionEvent) event; MotionEvent rawEvent = (MotionEvent) event; mEventHandler.onMotionEvent(motionEvent, policyFlags); MotionEvent transformedEvent = MotionEvent.obtain(rawEvent); mEventHandler.onMotionEvent(transformedEvent, rawEvent, policyFlags); transformedEvent.recycle(); } } @Override @Override public void onMotionEvent(MotionEvent event, int policyFlags) { public void onMotionEvent(MotionEvent transformedEvent, MotionEvent rawEvent, sendInputEvent(event, policyFlags); int policyFlags) { sendInputEvent(transformedEvent, policyFlags); } } @Override @Override Loading services/java/com/android/server/accessibility/EventStreamTransformation.java +6 −3 Original line number Original line Diff line number Diff line Loading @@ -57,12 +57,15 @@ import android.view.accessibility.AccessibilityEvent; interface EventStreamTransformation { interface EventStreamTransformation { /** /** * Receives a motion event. * Receives motion event. Passed are the event transformed by previous * transformations and the raw event to which no transformations have * been applied. * * * @param event The motion event. * @param event The transformed motion event. * @param rawEvent The raw motion event. * @param policyFlags Policy flags for the event. * @param policyFlags Policy flags for the event. */ */ public void onMotionEvent(MotionEvent event, int policyFlags); public void onMotionEvent(MotionEvent event, MotionEvent rawEvent, int policyFlags); /** /** * Receives an accessibility event. * Receives an accessibility event. Loading services/java/com/android/server/accessibility/ScreenMagnifier.java +24 −13 Original line number Original line Diff line number Diff line Loading @@ -203,14 +203,15 @@ public final class ScreenMagnifier implements EventStreamTransformation { } } @Override @Override public void onMotionEvent(MotionEvent event, int policyFlags) { public void onMotionEvent(MotionEvent event, MotionEvent rawEvent, int policyFlags) { mMagnifiedContentInteractonStateHandler.onMotionEvent(event); mMagnifiedContentInteractonStateHandler.onMotionEvent(event); switch (mCurrentState) { switch (mCurrentState) { case STATE_DELEGATING: { case STATE_DELEGATING: { handleMotionEventStateDelegating(event, policyFlags); handleMotionEventStateDelegating(event, rawEvent, policyFlags); } break; } break; case STATE_DETECTING: { case STATE_DETECTING: { mDetectingStateHandler.onMotionEvent(event, policyFlags); mDetectingStateHandler.onMotionEvent(event, rawEvent, policyFlags); } break; } break; case STATE_VIEWPORT_DRAGGING: { case STATE_VIEWPORT_DRAGGING: { mStateViewportDraggingHandler.onMotionEvent(event, policyFlags); mStateViewportDraggingHandler.onMotionEvent(event, policyFlags); Loading Loading @@ -259,7 +260,8 @@ public final class ScreenMagnifier implements EventStreamTransformation { mScreenStateObserver.destroy(); mScreenStateObserver.destroy(); } } private void handleMotionEventStateDelegating(MotionEvent event, int policyFlags) { private void handleMotionEventStateDelegating(MotionEvent event, MotionEvent rawEvent, int policyFlags) { if (event.getActionMasked() == MotionEvent.ACTION_UP) { if (event.getActionMasked() == MotionEvent.ACTION_UP) { if (mDetectingStateHandler.mDelayedEventQueue == null) { if (mDetectingStateHandler.mDelayedEventQueue == null) { transitionToState(STATE_DETECTING); transitionToState(STATE_DETECTING); Loading Loading @@ -290,7 +292,7 @@ public final class ScreenMagnifier implements EventStreamTransformation { coords, 0, 0, 1.0f, 1.0f, event.getDeviceId(), 0, event.getSource(), coords, 0, 0, 1.0f, 1.0f, event.getDeviceId(), 0, event.getSource(), event.getFlags()); event.getFlags()); } } mNext.onMotionEvent(event, policyFlags); mNext.onMotionEvent(event, rawEvent, policyFlags); } } } } Loading Loading @@ -533,8 +535,8 @@ public final class ScreenMagnifier implements EventStreamTransformation { } } }; }; public void onMotionEvent(MotionEvent event, int policyFlags) { public void onMotionEvent(MotionEvent event, MotionEvent rawEvent, int policyFlags) { cacheDelayedMotionEvent(event, policyFlags); cacheDelayedMotionEvent(event, rawEvent, policyFlags); final int action = event.getActionMasked(); final int action = event.getActionMasked(); switch (action) { switch (action) { case MotionEvent.ACTION_DOWN: { case MotionEvent.ACTION_DOWN: { Loading Loading @@ -640,8 +642,10 @@ public final class ScreenMagnifier implements EventStreamTransformation { } } } } private void cacheDelayedMotionEvent(MotionEvent event, int policyFlags) { private void cacheDelayedMotionEvent(MotionEvent event, MotionEvent rawEvent, MotionEventInfo info = MotionEventInfo.obtain(event, policyFlags); int policyFlags) { MotionEventInfo info = MotionEventInfo.obtain(event, rawEvent, policyFlags); if (mDelayedEventQueue == null) { if (mDelayedEventQueue == null) { mDelayedEventQueue = info; mDelayedEventQueue = info; } else { } else { Loading @@ -657,7 +661,8 @@ public final class ScreenMagnifier implements EventStreamTransformation { while (mDelayedEventQueue != null) { while (mDelayedEventQueue != null) { MotionEventInfo info = mDelayedEventQueue; MotionEventInfo info = mDelayedEventQueue; mDelayedEventQueue = info.mNext; mDelayedEventQueue = info.mNext; ScreenMagnifier.this.onMotionEvent(info.mEvent, info.mPolicyFlags); ScreenMagnifier.this.onMotionEvent(info.mEvent, info.mRawEvent, info.mPolicyFlags); info.recycle(); info.recycle(); } } } } Loading Loading @@ -738,9 +743,11 @@ public final class ScreenMagnifier implements EventStreamTransformation { private boolean mInPool; private boolean mInPool; public MotionEvent mEvent; public MotionEvent mEvent; public MotionEvent mRawEvent; public int mPolicyFlags; public int mPolicyFlags; public static MotionEventInfo obtain(MotionEvent event, int policyFlags) { public static MotionEventInfo obtain(MotionEvent event, MotionEvent rawEvent, int policyFlags) { synchronized (sLock) { synchronized (sLock) { MotionEventInfo info; MotionEventInfo info; if (sPoolSize > 0) { if (sPoolSize > 0) { Loading @@ -752,13 +759,15 @@ public final class ScreenMagnifier implements EventStreamTransformation { } else { } else { info = new MotionEventInfo(); info = new MotionEventInfo(); } } info.initialize(event, policyFlags); info.initialize(event, rawEvent, policyFlags); return info; return info; } } } } private void initialize(MotionEvent event, int policyFlags) { private void initialize(MotionEvent event, MotionEvent rawEvent, int policyFlags) { mEvent = MotionEvent.obtain(event); mEvent = MotionEvent.obtain(event); mRawEvent = MotionEvent.obtain(rawEvent); mPolicyFlags = policyFlags; mPolicyFlags = policyFlags; } } Loading @@ -780,6 +789,8 @@ public final class ScreenMagnifier implements EventStreamTransformation { private void clear() { private void clear() { mEvent.recycle(); mEvent.recycle(); mEvent = null; mEvent = null; mRawEvent.recycle(); mRawEvent = null; mPolicyFlags = 0; mPolicyFlags = 0; } } } } Loading services/java/com/android/server/accessibility/TouchExplorer.java +27 −22 Original line number Original line Diff line number Diff line Loading @@ -162,7 +162,7 @@ class TouchExplorer implements EventStreamTransformation { private EventStreamTransformation mNext; private EventStreamTransformation mNext; // Helper to track gesture velocity. // Helper to track gesture velocity. private VelocityTracker mVelocityTracker; private final VelocityTracker mVelocityTracker = VelocityTracker.obtain(); // Helper class to track received pointers. // Helper class to track received pointers. private final ReceivedPointerTracker mReceivedPointerTracker; private final ReceivedPointerTracker mReceivedPointerTracker; Loading Loading @@ -309,18 +309,18 @@ class TouchExplorer implements EventStreamTransformation { } } @Override @Override public void onMotionEvent(MotionEvent event, int policyFlags) { public void onMotionEvent(MotionEvent event, MotionEvent rawEvent, int policyFlags) { if (DEBUG) { if (DEBUG) { Slog.d(LOG_TAG, "Received event: " + event + ", policyFlags=0x" Slog.d(LOG_TAG, "Received event: " + event + ", policyFlags=0x" + Integer.toHexString(policyFlags)); + Integer.toHexString(policyFlags)); Slog.d(LOG_TAG, getStateSymbolicName(mCurrentState)); Slog.d(LOG_TAG, getStateSymbolicName(mCurrentState)); } } mReceivedPointerTracker.onMotionEvent(event); mReceivedPointerTracker.onMotionEvent(rawEvent); switch(mCurrentState) { switch(mCurrentState) { case STATE_TOUCH_EXPLORING: { case STATE_TOUCH_EXPLORING: { handleMotionEventStateTouchExploring(event, policyFlags); handleMotionEventStateTouchExploring(event, rawEvent, policyFlags); } break; } break; case STATE_DRAGGING: { case STATE_DRAGGING: { handleMotionEventStateDragging(event, policyFlags); handleMotionEventStateDragging(event, policyFlags); Loading @@ -329,7 +329,7 @@ class TouchExplorer implements EventStreamTransformation { handleMotionEventStateDelegating(event, policyFlags); handleMotionEventStateDelegating(event, policyFlags); } break; } break; case STATE_GESTURE_DETECTING: { case STATE_GESTURE_DETECTING: { handleMotionEventGestureDetecting(event, policyFlags); handleMotionEventGestureDetecting(rawEvent, policyFlags); } break; } break; default: default: throw new IllegalStateException("Illegal state: " + mCurrentState); throw new IllegalStateException("Illegal state: " + mCurrentState); Loading Loading @@ -382,16 +382,15 @@ class TouchExplorer implements EventStreamTransformation { * Handles a motion event in touch exploring state. * Handles a motion event in touch exploring state. * * * @param event The event to be handled. * @param event The event to be handled. * @param rawEvent The raw (unmodified) motion event. * @param policyFlags The policy flags associated with the event. * @param policyFlags The policy flags associated with the event. */ */ private void handleMotionEventStateTouchExploring(MotionEvent event, int policyFlags) { private void handleMotionEventStateTouchExploring(MotionEvent event, MotionEvent rawEvent, int policyFlags) { ReceivedPointerTracker receivedTracker = mReceivedPointerTracker; ReceivedPointerTracker receivedTracker = mReceivedPointerTracker; final int activePointerCount = receivedTracker.getActivePointerCount(); final int activePointerCount = receivedTracker.getActivePointerCount(); if (mVelocityTracker == null) { mVelocityTracker.addMovement(rawEvent); mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(event); mDoubleTapDetector.onMotionEvent(event, policyFlags); mDoubleTapDetector.onMotionEvent(event, policyFlags); Loading @@ -410,7 +409,7 @@ class TouchExplorer implements EventStreamTransformation { // have a distance slop before getting into gesture detection // have a distance slop before getting into gesture detection // mode and not using the points within this slop significantly // mode and not using the points within this slop significantly // decreases the quality of gesture recognition. // decreases the quality of gesture recognition. handleMotionEventGestureDetecting(event, policyFlags); handleMotionEventGestureDetecting(rawEvent, policyFlags); //$FALL-THROUGH$ //$FALL-THROUGH$ case MotionEvent.ACTION_POINTER_DOWN: { case MotionEvent.ACTION_POINTER_DOWN: { switch (activePointerCount) { switch (activePointerCount) { Loading Loading @@ -471,12 +470,13 @@ class TouchExplorer implements EventStreamTransformation { // have a distance slop before getting into gesture detection // have a distance slop before getting into gesture detection // mode and not using the points within this slop significantly // mode and not using the points within this slop significantly // decreases the quality of gesture recognition. // decreases the quality of gesture recognition. handleMotionEventGestureDetecting(event, policyFlags); handleMotionEventGestureDetecting(rawEvent, policyFlags); // It is *important* to use the distance traveled by the pointers // on the screen which may or may not be magnified. final float deltaX = receivedTracker.getReceivedPointerDownX(pointerId) final float deltaX = receivedTracker.getReceivedPointerDownX(pointerId) - event.getX(pointerIndex); - rawEvent.getX(pointerIndex); final float deltaY = receivedTracker.getReceivedPointerDownY(pointerId) final float deltaY = receivedTracker.getReceivedPointerDownY(pointerId) - event.getY(pointerIndex); - rawEvent.getY(pointerIndex); final double moveDelta = Math.hypot(deltaX, deltaY); final double moveDelta = Math.hypot(deltaX, deltaY); // The user has moved enough for us to decide. // The user has moved enough for us to decide. if (moveDelta > mDoubleTapSlop) { if (moveDelta > mDoubleTapSlop) { Loading @@ -491,6 +491,7 @@ class TouchExplorer implements EventStreamTransformation { // We have to perform gesture detection, so // We have to perform gesture detection, so // clear the current state and try to detect. // clear the current state and try to detect. mCurrentState = STATE_GESTURE_DETECTING; mCurrentState = STATE_GESTURE_DETECTING; mVelocityTracker.clear(); mSendHoverEnterDelayed.remove(); mSendHoverEnterDelayed.remove(); mSendHoverExitDelayed.remove(); mSendHoverExitDelayed.remove(); mPerformLongPressDelayed.remove(); mPerformLongPressDelayed.remove(); Loading Loading @@ -535,10 +536,12 @@ class TouchExplorer implements EventStreamTransformation { // If the user is touch exploring the second pointer may be // If the user is touch exploring the second pointer may be // performing a double tap to activate an item without need // performing a double tap to activate an item without need // for the user to lift his exploring finger. // for the user to lift his exploring finger. // It is *important* to use the distance traveled by the pointers // on the screen which may or may not be magnified. final float deltaX = receivedTracker.getReceivedPointerDownX(pointerId) final float deltaX = receivedTracker.getReceivedPointerDownX(pointerId) - event.getX(pointerIndex); - rawEvent.getX(pointerIndex); final float deltaY = receivedTracker.getReceivedPointerDownY(pointerId) final float deltaY = receivedTracker.getReceivedPointerDownY(pointerId) - event.getY(pointerIndex); - rawEvent.getY(pointerIndex); final double moveDelta = Math.hypot(deltaX, deltaY); final double moveDelta = Math.hypot(deltaX, deltaY); if (moveDelta < mDoubleTapSlop) { if (moveDelta < mDoubleTapSlop) { break; break; Loading @@ -565,6 +568,7 @@ class TouchExplorer implements EventStreamTransformation { mCurrentState = STATE_DELEGATING; mCurrentState = STATE_DELEGATING; sendDownForAllActiveNotInjectedPointers(event, policyFlags); sendDownForAllActiveNotInjectedPointers(event, policyFlags); } } mVelocityTracker.clear(); } break; } break; default: { default: { // More than one pointer so the user is not touch exploring // More than one pointer so the user is not touch exploring Loading @@ -585,6 +589,7 @@ class TouchExplorer implements EventStreamTransformation { // More than two pointers are delegated to the view hierarchy. // More than two pointers are delegated to the view hierarchy. mCurrentState = STATE_DELEGATING; mCurrentState = STATE_DELEGATING; sendDownForAllActiveNotInjectedPointers(event, policyFlags); sendDownForAllActiveNotInjectedPointers(event, policyFlags); mVelocityTracker.clear(); } } } } } break; } break; Loading Loading @@ -615,10 +620,7 @@ class TouchExplorer implements EventStreamTransformation { } } } break; } break; } } if (mVelocityTracker != null) { mVelocityTracker.clear(); mVelocityTracker.clear(); mVelocityTracker = null; } } break; } break; case MotionEvent.ACTION_CANCEL: { case MotionEvent.ACTION_CANCEL: { clear(event, policyFlags); clear(event, policyFlags); Loading Loading @@ -1046,7 +1048,10 @@ class TouchExplorer implements EventStreamTransformation { // Make sure that the user will see the event. // Make sure that the user will see the event. policyFlags |= WindowManagerPolicy.FLAG_PASS_TO_USER; policyFlags |= WindowManagerPolicy.FLAG_PASS_TO_USER; if (mNext != null) { if (mNext != null) { mNext.onMotionEvent(event, policyFlags); // TODO: For now pass null for the raw event since the touch // explorer is the last event transformation and it does // not care about the raw event. mNext.onMotionEvent(event, null, policyFlags); } } mInjectedPointerTracker.onMotionEvent(event); mInjectedPointerTracker.onMotionEvent(event); Loading Loading
services/java/com/android/server/accessibility/AccessibilityInputFilter.java +7 −4 Original line number Original line Diff line number Diff line Loading @@ -119,13 +119,16 @@ class AccessibilityInputFilter extends InputFilter implements EventStreamTransfo mCurrentDeviceId = deviceId; mCurrentDeviceId = deviceId; } } mPm.userActivity(event.getEventTime(), false); mPm.userActivity(event.getEventTime(), false); MotionEvent motionEvent = (MotionEvent) event; MotionEvent rawEvent = (MotionEvent) event; mEventHandler.onMotionEvent(motionEvent, policyFlags); MotionEvent transformedEvent = MotionEvent.obtain(rawEvent); mEventHandler.onMotionEvent(transformedEvent, rawEvent, policyFlags); transformedEvent.recycle(); } } @Override @Override public void onMotionEvent(MotionEvent event, int policyFlags) { public void onMotionEvent(MotionEvent transformedEvent, MotionEvent rawEvent, sendInputEvent(event, policyFlags); int policyFlags) { sendInputEvent(transformedEvent, policyFlags); } } @Override @Override Loading
services/java/com/android/server/accessibility/EventStreamTransformation.java +6 −3 Original line number Original line Diff line number Diff line Loading @@ -57,12 +57,15 @@ import android.view.accessibility.AccessibilityEvent; interface EventStreamTransformation { interface EventStreamTransformation { /** /** * Receives a motion event. * Receives motion event. Passed are the event transformed by previous * transformations and the raw event to which no transformations have * been applied. * * * @param event The motion event. * @param event The transformed motion event. * @param rawEvent The raw motion event. * @param policyFlags Policy flags for the event. * @param policyFlags Policy flags for the event. */ */ public void onMotionEvent(MotionEvent event, int policyFlags); public void onMotionEvent(MotionEvent event, MotionEvent rawEvent, int policyFlags); /** /** * Receives an accessibility event. * Receives an accessibility event. Loading
services/java/com/android/server/accessibility/ScreenMagnifier.java +24 −13 Original line number Original line Diff line number Diff line Loading @@ -203,14 +203,15 @@ public final class ScreenMagnifier implements EventStreamTransformation { } } @Override @Override public void onMotionEvent(MotionEvent event, int policyFlags) { public void onMotionEvent(MotionEvent event, MotionEvent rawEvent, int policyFlags) { mMagnifiedContentInteractonStateHandler.onMotionEvent(event); mMagnifiedContentInteractonStateHandler.onMotionEvent(event); switch (mCurrentState) { switch (mCurrentState) { case STATE_DELEGATING: { case STATE_DELEGATING: { handleMotionEventStateDelegating(event, policyFlags); handleMotionEventStateDelegating(event, rawEvent, policyFlags); } break; } break; case STATE_DETECTING: { case STATE_DETECTING: { mDetectingStateHandler.onMotionEvent(event, policyFlags); mDetectingStateHandler.onMotionEvent(event, rawEvent, policyFlags); } break; } break; case STATE_VIEWPORT_DRAGGING: { case STATE_VIEWPORT_DRAGGING: { mStateViewportDraggingHandler.onMotionEvent(event, policyFlags); mStateViewportDraggingHandler.onMotionEvent(event, policyFlags); Loading Loading @@ -259,7 +260,8 @@ public final class ScreenMagnifier implements EventStreamTransformation { mScreenStateObserver.destroy(); mScreenStateObserver.destroy(); } } private void handleMotionEventStateDelegating(MotionEvent event, int policyFlags) { private void handleMotionEventStateDelegating(MotionEvent event, MotionEvent rawEvent, int policyFlags) { if (event.getActionMasked() == MotionEvent.ACTION_UP) { if (event.getActionMasked() == MotionEvent.ACTION_UP) { if (mDetectingStateHandler.mDelayedEventQueue == null) { if (mDetectingStateHandler.mDelayedEventQueue == null) { transitionToState(STATE_DETECTING); transitionToState(STATE_DETECTING); Loading Loading @@ -290,7 +292,7 @@ public final class ScreenMagnifier implements EventStreamTransformation { coords, 0, 0, 1.0f, 1.0f, event.getDeviceId(), 0, event.getSource(), coords, 0, 0, 1.0f, 1.0f, event.getDeviceId(), 0, event.getSource(), event.getFlags()); event.getFlags()); } } mNext.onMotionEvent(event, policyFlags); mNext.onMotionEvent(event, rawEvent, policyFlags); } } } } Loading Loading @@ -533,8 +535,8 @@ public final class ScreenMagnifier implements EventStreamTransformation { } } }; }; public void onMotionEvent(MotionEvent event, int policyFlags) { public void onMotionEvent(MotionEvent event, MotionEvent rawEvent, int policyFlags) { cacheDelayedMotionEvent(event, policyFlags); cacheDelayedMotionEvent(event, rawEvent, policyFlags); final int action = event.getActionMasked(); final int action = event.getActionMasked(); switch (action) { switch (action) { case MotionEvent.ACTION_DOWN: { case MotionEvent.ACTION_DOWN: { Loading Loading @@ -640,8 +642,10 @@ public final class ScreenMagnifier implements EventStreamTransformation { } } } } private void cacheDelayedMotionEvent(MotionEvent event, int policyFlags) { private void cacheDelayedMotionEvent(MotionEvent event, MotionEvent rawEvent, MotionEventInfo info = MotionEventInfo.obtain(event, policyFlags); int policyFlags) { MotionEventInfo info = MotionEventInfo.obtain(event, rawEvent, policyFlags); if (mDelayedEventQueue == null) { if (mDelayedEventQueue == null) { mDelayedEventQueue = info; mDelayedEventQueue = info; } else { } else { Loading @@ -657,7 +661,8 @@ public final class ScreenMagnifier implements EventStreamTransformation { while (mDelayedEventQueue != null) { while (mDelayedEventQueue != null) { MotionEventInfo info = mDelayedEventQueue; MotionEventInfo info = mDelayedEventQueue; mDelayedEventQueue = info.mNext; mDelayedEventQueue = info.mNext; ScreenMagnifier.this.onMotionEvent(info.mEvent, info.mPolicyFlags); ScreenMagnifier.this.onMotionEvent(info.mEvent, info.mRawEvent, info.mPolicyFlags); info.recycle(); info.recycle(); } } } } Loading Loading @@ -738,9 +743,11 @@ public final class ScreenMagnifier implements EventStreamTransformation { private boolean mInPool; private boolean mInPool; public MotionEvent mEvent; public MotionEvent mEvent; public MotionEvent mRawEvent; public int mPolicyFlags; public int mPolicyFlags; public static MotionEventInfo obtain(MotionEvent event, int policyFlags) { public static MotionEventInfo obtain(MotionEvent event, MotionEvent rawEvent, int policyFlags) { synchronized (sLock) { synchronized (sLock) { MotionEventInfo info; MotionEventInfo info; if (sPoolSize > 0) { if (sPoolSize > 0) { Loading @@ -752,13 +759,15 @@ public final class ScreenMagnifier implements EventStreamTransformation { } else { } else { info = new MotionEventInfo(); info = new MotionEventInfo(); } } info.initialize(event, policyFlags); info.initialize(event, rawEvent, policyFlags); return info; return info; } } } } private void initialize(MotionEvent event, int policyFlags) { private void initialize(MotionEvent event, MotionEvent rawEvent, int policyFlags) { mEvent = MotionEvent.obtain(event); mEvent = MotionEvent.obtain(event); mRawEvent = MotionEvent.obtain(rawEvent); mPolicyFlags = policyFlags; mPolicyFlags = policyFlags; } } Loading @@ -780,6 +789,8 @@ public final class ScreenMagnifier implements EventStreamTransformation { private void clear() { private void clear() { mEvent.recycle(); mEvent.recycle(); mEvent = null; mEvent = null; mRawEvent.recycle(); mRawEvent = null; mPolicyFlags = 0; mPolicyFlags = 0; } } } } Loading
services/java/com/android/server/accessibility/TouchExplorer.java +27 −22 Original line number Original line Diff line number Diff line Loading @@ -162,7 +162,7 @@ class TouchExplorer implements EventStreamTransformation { private EventStreamTransformation mNext; private EventStreamTransformation mNext; // Helper to track gesture velocity. // Helper to track gesture velocity. private VelocityTracker mVelocityTracker; private final VelocityTracker mVelocityTracker = VelocityTracker.obtain(); // Helper class to track received pointers. // Helper class to track received pointers. private final ReceivedPointerTracker mReceivedPointerTracker; private final ReceivedPointerTracker mReceivedPointerTracker; Loading Loading @@ -309,18 +309,18 @@ class TouchExplorer implements EventStreamTransformation { } } @Override @Override public void onMotionEvent(MotionEvent event, int policyFlags) { public void onMotionEvent(MotionEvent event, MotionEvent rawEvent, int policyFlags) { if (DEBUG) { if (DEBUG) { Slog.d(LOG_TAG, "Received event: " + event + ", policyFlags=0x" Slog.d(LOG_TAG, "Received event: " + event + ", policyFlags=0x" + Integer.toHexString(policyFlags)); + Integer.toHexString(policyFlags)); Slog.d(LOG_TAG, getStateSymbolicName(mCurrentState)); Slog.d(LOG_TAG, getStateSymbolicName(mCurrentState)); } } mReceivedPointerTracker.onMotionEvent(event); mReceivedPointerTracker.onMotionEvent(rawEvent); switch(mCurrentState) { switch(mCurrentState) { case STATE_TOUCH_EXPLORING: { case STATE_TOUCH_EXPLORING: { handleMotionEventStateTouchExploring(event, policyFlags); handleMotionEventStateTouchExploring(event, rawEvent, policyFlags); } break; } break; case STATE_DRAGGING: { case STATE_DRAGGING: { handleMotionEventStateDragging(event, policyFlags); handleMotionEventStateDragging(event, policyFlags); Loading @@ -329,7 +329,7 @@ class TouchExplorer implements EventStreamTransformation { handleMotionEventStateDelegating(event, policyFlags); handleMotionEventStateDelegating(event, policyFlags); } break; } break; case STATE_GESTURE_DETECTING: { case STATE_GESTURE_DETECTING: { handleMotionEventGestureDetecting(event, policyFlags); handleMotionEventGestureDetecting(rawEvent, policyFlags); } break; } break; default: default: throw new IllegalStateException("Illegal state: " + mCurrentState); throw new IllegalStateException("Illegal state: " + mCurrentState); Loading Loading @@ -382,16 +382,15 @@ class TouchExplorer implements EventStreamTransformation { * Handles a motion event in touch exploring state. * Handles a motion event in touch exploring state. * * * @param event The event to be handled. * @param event The event to be handled. * @param rawEvent The raw (unmodified) motion event. * @param policyFlags The policy flags associated with the event. * @param policyFlags The policy flags associated with the event. */ */ private void handleMotionEventStateTouchExploring(MotionEvent event, int policyFlags) { private void handleMotionEventStateTouchExploring(MotionEvent event, MotionEvent rawEvent, int policyFlags) { ReceivedPointerTracker receivedTracker = mReceivedPointerTracker; ReceivedPointerTracker receivedTracker = mReceivedPointerTracker; final int activePointerCount = receivedTracker.getActivePointerCount(); final int activePointerCount = receivedTracker.getActivePointerCount(); if (mVelocityTracker == null) { mVelocityTracker.addMovement(rawEvent); mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(event); mDoubleTapDetector.onMotionEvent(event, policyFlags); mDoubleTapDetector.onMotionEvent(event, policyFlags); Loading @@ -410,7 +409,7 @@ class TouchExplorer implements EventStreamTransformation { // have a distance slop before getting into gesture detection // have a distance slop before getting into gesture detection // mode and not using the points within this slop significantly // mode and not using the points within this slop significantly // decreases the quality of gesture recognition. // decreases the quality of gesture recognition. handleMotionEventGestureDetecting(event, policyFlags); handleMotionEventGestureDetecting(rawEvent, policyFlags); //$FALL-THROUGH$ //$FALL-THROUGH$ case MotionEvent.ACTION_POINTER_DOWN: { case MotionEvent.ACTION_POINTER_DOWN: { switch (activePointerCount) { switch (activePointerCount) { Loading Loading @@ -471,12 +470,13 @@ class TouchExplorer implements EventStreamTransformation { // have a distance slop before getting into gesture detection // have a distance slop before getting into gesture detection // mode and not using the points within this slop significantly // mode and not using the points within this slop significantly // decreases the quality of gesture recognition. // decreases the quality of gesture recognition. handleMotionEventGestureDetecting(event, policyFlags); handleMotionEventGestureDetecting(rawEvent, policyFlags); // It is *important* to use the distance traveled by the pointers // on the screen which may or may not be magnified. final float deltaX = receivedTracker.getReceivedPointerDownX(pointerId) final float deltaX = receivedTracker.getReceivedPointerDownX(pointerId) - event.getX(pointerIndex); - rawEvent.getX(pointerIndex); final float deltaY = receivedTracker.getReceivedPointerDownY(pointerId) final float deltaY = receivedTracker.getReceivedPointerDownY(pointerId) - event.getY(pointerIndex); - rawEvent.getY(pointerIndex); final double moveDelta = Math.hypot(deltaX, deltaY); final double moveDelta = Math.hypot(deltaX, deltaY); // The user has moved enough for us to decide. // The user has moved enough for us to decide. if (moveDelta > mDoubleTapSlop) { if (moveDelta > mDoubleTapSlop) { Loading @@ -491,6 +491,7 @@ class TouchExplorer implements EventStreamTransformation { // We have to perform gesture detection, so // We have to perform gesture detection, so // clear the current state and try to detect. // clear the current state and try to detect. mCurrentState = STATE_GESTURE_DETECTING; mCurrentState = STATE_GESTURE_DETECTING; mVelocityTracker.clear(); mSendHoverEnterDelayed.remove(); mSendHoverEnterDelayed.remove(); mSendHoverExitDelayed.remove(); mSendHoverExitDelayed.remove(); mPerformLongPressDelayed.remove(); mPerformLongPressDelayed.remove(); Loading Loading @@ -535,10 +536,12 @@ class TouchExplorer implements EventStreamTransformation { // If the user is touch exploring the second pointer may be // If the user is touch exploring the second pointer may be // performing a double tap to activate an item without need // performing a double tap to activate an item without need // for the user to lift his exploring finger. // for the user to lift his exploring finger. // It is *important* to use the distance traveled by the pointers // on the screen which may or may not be magnified. final float deltaX = receivedTracker.getReceivedPointerDownX(pointerId) final float deltaX = receivedTracker.getReceivedPointerDownX(pointerId) - event.getX(pointerIndex); - rawEvent.getX(pointerIndex); final float deltaY = receivedTracker.getReceivedPointerDownY(pointerId) final float deltaY = receivedTracker.getReceivedPointerDownY(pointerId) - event.getY(pointerIndex); - rawEvent.getY(pointerIndex); final double moveDelta = Math.hypot(deltaX, deltaY); final double moveDelta = Math.hypot(deltaX, deltaY); if (moveDelta < mDoubleTapSlop) { if (moveDelta < mDoubleTapSlop) { break; break; Loading @@ -565,6 +568,7 @@ class TouchExplorer implements EventStreamTransformation { mCurrentState = STATE_DELEGATING; mCurrentState = STATE_DELEGATING; sendDownForAllActiveNotInjectedPointers(event, policyFlags); sendDownForAllActiveNotInjectedPointers(event, policyFlags); } } mVelocityTracker.clear(); } break; } break; default: { default: { // More than one pointer so the user is not touch exploring // More than one pointer so the user is not touch exploring Loading @@ -585,6 +589,7 @@ class TouchExplorer implements EventStreamTransformation { // More than two pointers are delegated to the view hierarchy. // More than two pointers are delegated to the view hierarchy. mCurrentState = STATE_DELEGATING; mCurrentState = STATE_DELEGATING; sendDownForAllActiveNotInjectedPointers(event, policyFlags); sendDownForAllActiveNotInjectedPointers(event, policyFlags); mVelocityTracker.clear(); } } } } } break; } break; Loading Loading @@ -615,10 +620,7 @@ class TouchExplorer implements EventStreamTransformation { } } } break; } break; } } if (mVelocityTracker != null) { mVelocityTracker.clear(); mVelocityTracker.clear(); mVelocityTracker = null; } } break; } break; case MotionEvent.ACTION_CANCEL: { case MotionEvent.ACTION_CANCEL: { clear(event, policyFlags); clear(event, policyFlags); Loading Loading @@ -1046,7 +1048,10 @@ class TouchExplorer implements EventStreamTransformation { // Make sure that the user will see the event. // Make sure that the user will see the event. policyFlags |= WindowManagerPolicy.FLAG_PASS_TO_USER; policyFlags |= WindowManagerPolicy.FLAG_PASS_TO_USER; if (mNext != null) { if (mNext != null) { mNext.onMotionEvent(event, policyFlags); // TODO: For now pass null for the raw event since the touch // explorer is the last event transformation and it does // not care about the raw event. mNext.onMotionEvent(event, null, policyFlags); } } mInjectedPointerTracker.onMotionEvent(event); mInjectedPointerTracker.onMotionEvent(event); Loading