Skip to content

Commit 72e3512

Browse files
committed
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
1 parent 48994ce commit 72e3512

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

services/java/com/android/server/accessibility/ScreenMagnifier.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import android.os.Message;
3939
import android.os.RemoteException;
4040
import android.os.ServiceManager;
41+
import android.os.SystemClock;
4142
import android.provider.Settings;
4243
import android.util.Property;
4344
import android.util.Slog;
@@ -662,12 +663,33 @@ private void sendDelayedMotionEvents() {
662663
while (mDelayedEventQueue != null) {
663664
MotionEventInfo info = mDelayedEventQueue;
664665
mDelayedEventQueue = info.mNext;
665-
ScreenMagnifier.this.onMotionEvent(info.mEvent, info.mRawEvent,
666-
info.mPolicyFlags);
666+
final long offset = SystemClock.uptimeMillis() - info.mCachedTimeMillis;
667+
MotionEvent event = obtainEventWithOffsetTimeAndDownTime(info.mEvent, offset);
668+
MotionEvent rawEvent = obtainEventWithOffsetTimeAndDownTime(info.mRawEvent, offset);
669+
ScreenMagnifier.this.onMotionEvent(event, rawEvent, info.mPolicyFlags);
670+
event.recycle();
671+
rawEvent.recycle();
667672
info.recycle();
668673
}
669674
}
670675

676+
private MotionEvent obtainEventWithOffsetTimeAndDownTime(MotionEvent event, long offset) {
677+
final int pointerCount = event.getPointerCount();
678+
PointerCoords[] coords = getTempPointerCoordsWithMinSize(pointerCount);
679+
PointerProperties[] properties = getTempPointerPropertiesWithMinSize(pointerCount);
680+
for (int i = 0; i < pointerCount; i++) {
681+
event.getPointerCoords(i, coords[i]);
682+
event.getPointerProperties(i, properties[i]);
683+
}
684+
final long downTime = event.getDownTime() + offset;
685+
final long eventTime = event.getEventTime() + offset;
686+
return MotionEvent.obtain(downTime, eventTime,
687+
event.getAction(), pointerCount, properties, coords,
688+
event.getMetaState(), event.getButtonState(),
689+
1.0f, 1.0f, event.getDeviceId(), event.getEdgeFlags(),
690+
event.getSource(), event.getFlags());
691+
}
692+
671693
private void clearDelayedMotionEvents() {
672694
while (mDelayedEventQueue != null) {
673695
MotionEventInfo info = mDelayedEventQueue;
@@ -746,6 +768,7 @@ private static final class MotionEventInfo {
746768
public MotionEvent mEvent;
747769
public MotionEvent mRawEvent;
748770
public int mPolicyFlags;
771+
public long mCachedTimeMillis;
749772

750773
public static MotionEventInfo obtain(MotionEvent event, MotionEvent rawEvent,
751774
int policyFlags) {
@@ -770,6 +793,7 @@ private void initialize(MotionEvent event, MotionEvent rawEvent,
770793
mEvent = MotionEvent.obtain(event);
771794
mRawEvent = MotionEvent.obtain(rawEvent);
772795
mPolicyFlags = policyFlags;
796+
mCachedTimeMillis = SystemClock.uptimeMillis();
773797
}
774798

775799
public void recycle() {
@@ -793,6 +817,7 @@ private void clear() {
793817
mRawEvent.recycle();
794818
mRawEvent = null;
795819
mPolicyFlags = 0;
820+
mCachedTimeMillis = 0;
796821
}
797822
}
798823

0 commit comments

Comments
 (0)