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

Commit 6cc94de8 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Add FLAG_CANCELED to synthesized MotionEvents

MotionEvents with ACTION_CANCELED are supposed to have FLAG_CANCELED
also set. This is currently enforced by InputVerifier.

However, the MotionEvents created in Java don't follow this contract.

Since we currently don't have an API to set flags, but we do have an API
to set action, fix this in the implementation of MotionEvent.java.

This helps with verification of injected events.

Bug: 211379801
Test: atest MotionEventTest
Change-Id: Idfb1524733e312d933b421e9fd1dda3c6722ae13
parent 97ee1bfd
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -2197,6 +2197,9 @@ public final class MotionEvent extends InputEvent implements Parcelable {
            float xOffset, float yOffset, float xPrecision, float yPrecision,
            long downTimeNanos, long eventTimeNanos,
            int pointerCount, PointerProperties[] pointerIds, PointerCoords[] pointerCoords) {
        if (action == ACTION_CANCEL) {
            flags |= FLAG_CANCELED;
        }
        mNativePtr = nativeInitialize(mNativePtr, deviceId, source, displayId, action, flags,
                edgeFlags, metaState, buttonState, classification, xOffset, yOffset,
                xPrecision, yPrecision, downTimeNanos, eventTimeNanos, pointerCount, pointerIds,
@@ -2387,6 +2390,11 @@ public final class MotionEvent extends InputEvent implements Parcelable {
        nativeSetFlags(mNativePtr, tainted ? flags | FLAG_TAINTED : flags & ~FLAG_TAINTED);
    }

    private void setCanceled(boolean canceled) {
        final int flags = getFlags();
        nativeSetFlags(mNativePtr, canceled ? flags | FLAG_CANCELED : flags & ~FLAG_CANCELED);
    }

    /** @hide */
    public  boolean isTargetAccessibilityFocus() {
        final int flags = getFlags();
@@ -3510,6 +3518,14 @@ public final class MotionEvent extends InputEvent implements Parcelable {
     * Sets this event's action.
     */
    public final void setAction(int action) {
        final int actionMasked = action & ACTION_MASK;
        if (actionMasked == ACTION_CANCEL) {
            setCanceled(true);
        } else if (actionMasked == ACTION_POINTER_UP) {
            // Do nothing - we don't know what the real intent here is
        } else {
            setCanceled(false);
        }
        nativeSetAction(mNativePtr, action);
    }

@@ -4157,6 +4173,7 @@ public final class MotionEvent extends InputEvent implements Parcelable {
    /** @hide */
    @Override
    public final void cancel() {
        setCanceled(true);
        setAction(ACTION_CANCEL);
    }