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

Commit 72e35129 authored by Svetoslav Ganov's avatar Svetoslav Ganov
Browse files

Long press not working if explore by touch and magnification are on.

1. In the magnifier we are caching the touch events until we figure
   out whether the user is triple tapping to enable magnification.
   If the user is not trying to engage magnification we deliver the
   stashed events. However, these events are stale and the subsequent
   transformations such as the touch explorer get confused when trying
   to detect a tap since the delay is longer than the tap slop.
   This change compensates for the time the events were cached
   before sending them to the next transformation in the chain.

bug:7362365

Change-Id: Idd8539ffed7ba4892c5a916bd34910fd2ef50f75
parent 48994ce9
Loading
Loading
Loading
Loading
+27 −2
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.os.Handler;
import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.provider.Settings;
import android.util.Property;
import android.util.Slog;
@@ -662,12 +663,33 @@ public final class ScreenMagnifier implements EventStreamTransformation {
            while (mDelayedEventQueue != null) {
                MotionEventInfo info = mDelayedEventQueue;
                mDelayedEventQueue = info.mNext;
                ScreenMagnifier.this.onMotionEvent(info.mEvent, info.mRawEvent,
                        info.mPolicyFlags);
                final long offset = SystemClock.uptimeMillis() - info.mCachedTimeMillis;
                MotionEvent event = obtainEventWithOffsetTimeAndDownTime(info.mEvent, offset);
                MotionEvent rawEvent = obtainEventWithOffsetTimeAndDownTime(info.mRawEvent, offset);
                ScreenMagnifier.this.onMotionEvent(event, rawEvent, info.mPolicyFlags);
                event.recycle();
                rawEvent.recycle();
                info.recycle();
            }
        }

        private MotionEvent obtainEventWithOffsetTimeAndDownTime(MotionEvent event, long offset) {
            final int pointerCount = event.getPointerCount();
            PointerCoords[] coords = getTempPointerCoordsWithMinSize(pointerCount);
            PointerProperties[] properties = getTempPointerPropertiesWithMinSize(pointerCount);
            for (int i = 0; i < pointerCount; i++) {
                event.getPointerCoords(i, coords[i]);
                event.getPointerProperties(i, properties[i]);
            }
            final long downTime = event.getDownTime() + offset;
            final long eventTime = event.getEventTime() + offset;
            return MotionEvent.obtain(downTime, eventTime,
                    event.getAction(), pointerCount, properties, coords,
                    event.getMetaState(), event.getButtonState(),
                    1.0f, 1.0f, event.getDeviceId(), event.getEdgeFlags(),
                    event.getSource(), event.getFlags());
        }

        private void clearDelayedMotionEvents() {
            while (mDelayedEventQueue != null) {
                MotionEventInfo info = mDelayedEventQueue;
@@ -746,6 +768,7 @@ public final class ScreenMagnifier implements EventStreamTransformation {
        public MotionEvent mEvent;
        public MotionEvent mRawEvent;
        public int mPolicyFlags;
        public long mCachedTimeMillis;

        public static MotionEventInfo obtain(MotionEvent event, MotionEvent rawEvent,
                int policyFlags) {
@@ -770,6 +793,7 @@ public final class ScreenMagnifier implements EventStreamTransformation {
            mEvent = MotionEvent.obtain(event);
            mRawEvent = MotionEvent.obtain(rawEvent);
            mPolicyFlags = policyFlags;
            mCachedTimeMillis = SystemClock.uptimeMillis();
        }

        public void recycle() {
@@ -793,6 +817,7 @@ public final class ScreenMagnifier implements EventStreamTransformation {
            mRawEvent.recycle();
            mRawEvent = null;
            mPolicyFlags = 0;
            mCachedTimeMillis = 0;
        }
    }