Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4a318ed2 authored by Jackal Guo's avatar Jackal Guo
Browse files

Adjust down time to prevent subsequent modules being misleading

MagnificationGestureHandler cache some events to see if users want to
trigger magnification. If no magnification is triggered we inject the
events with original down time. This causes the subsequent modules,
like GestureDetector, be misleading. For example, injecting a cached
ACTION_DOWN event may mistrigger a long click if the down time of the
event is long enough ago.

Bug: 131815497
Test: a11y CTS & unit tests
Change-Id: I19508e8ef7c91af02cdc628463d5715f6de22cd3
parent b178d3b8
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.content.IntentFilter;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import android.util.Log;
import android.util.MathUtils;
import android.util.Slog;
@@ -622,6 +623,8 @@ class MagnificationGestureHandler extends BaseEventStreamTransformation {
        private MotionEvent mLastUp;
        private MotionEvent mPreLastUp;

        private long mLastDetectingDownEventTime;

        @VisibleForTesting boolean mShortcutTriggered;

        @VisibleForTesting Handler mHandler = new Handler(Looper.getMainLooper(), this);
@@ -662,6 +665,7 @@ class MagnificationGestureHandler extends BaseEventStreamTransformation {
            switch (event.getActionMasked()) {
                case MotionEvent.ACTION_DOWN: {

                    mLastDetectingDownEventTime = event.getDownTime();
                    mHandler.removeMessages(MESSAGE_TRANSITION_TO_DELEGATING_STATE);

                    if (!mMagnificationController.magnificationRegionContains(
@@ -838,14 +842,25 @@ class MagnificationGestureHandler extends BaseEventStreamTransformation {
        }

        private void sendDelayedMotionEvents() {
            while (mDelayedEventQueue != null) {
            if (mDelayedEventQueue == null) {
                return;
            }

            // Adjust down time to prevent subsequent modules being misleading, and also limit
            // the maximum offset to mMultiTapMaxDelay to prevent the down time of 2nd tap is
            // in the future when multi-tap happens.
            final long offset = Math.min(
                    SystemClock.uptimeMillis() - mLastDetectingDownEventTime, mMultiTapMaxDelay);

            do {
                MotionEventInfo info = mDelayedEventQueue;
                mDelayedEventQueue = info.mNext;

                info.event.setDownTime(info.event.getDownTime() + offset);
                handleEventWith(mDelegatingState, info.event, info.rawEvent, info.policyFlags);

                info.recycle();
            }
            } while (mDelayedEventQueue != null);
        }

        private void clearDelayedMotionEvents() {