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

Commit 21bc5c91 authored by Jeff Brown's avatar Jeff Brown
Browse files

Add a little input event consistency verifier.

The idea is to assist with debugging by identifying cases in which
the input event stream is corrupted.

Change-Id: I0a00e52bbe2716be1b3dfc7c02a754492d8e7f1f
parent 0029c662
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -245,6 +245,13 @@ public class GestureDetector {
     */
    private VelocityTracker mVelocityTracker;

    /**
     * Consistency verifier for debugging purposes.
     */
    private final InputEventConsistencyVerifier mInputEventConsistencyVerifier =
            InputEventConsistencyVerifier.isInstrumentationEnabled() ?
                    new InputEventConsistencyVerifier(this, 0) : null;

    private class GestureHandler extends Handler {
        GestureHandler() {
            super();
@@ -443,6 +450,10 @@ public class GestureDetector {
     *              else false.
     */
    public boolean onTouchEvent(MotionEvent ev) {
        if (mInputEventConsistencyVerifier != null) {
            mInputEventConsistencyVerifier.onTouchEvent(ev, 0);
        }

        final int action = ev.getAction();
        final float y = ev.getY();
        final float x = ev.getX();
+30 −0
Original line number Diff line number Diff line
@@ -67,6 +67,14 @@ public abstract class InputEvent implements Parcelable {
     */
    public abstract void setSource(int source);

    /**
     * Copies the event.
     *
     * @return A deep copy of the event.
     * @hide
     */
    public abstract InputEvent copy();

    /**
     * Recycles the event.
     * This method should only be used by the system since applications do not
@@ -76,6 +84,28 @@ public abstract class InputEvent implements Parcelable {
     */
    public abstract void recycle();

    /**
     * Gets a private flag that indicates when the system has detected that this input event
     * may be inconsistent with respect to the sequence of previously delivered input events,
     * such as when a key up event is sent but the key was not down or when a pointer
     * move event is sent but the pointer is not down.
     *
     * @return True if this event is tainted.
     * @hide
     */
    public abstract boolean isTainted();

    /**
     * Sets a private flag that indicates when the system has detected that this input event
     * may be inconsistent with respect to the sequence of previously delivered input events,
     * such as when a key up event is sent but the key was not down or when a pointer
     * move event is sent but the pointer is not down.
     *
     * @param tainted True if this event is tainted.
     * @hide
     */
    public abstract void setTainted(boolean tainted);

    public int describeContents() {
        return 0;
    }
+638 −0

File added.

Preview size limit exceeded, changes collapsed.

+52 −2
Original line number Diff line number Diff line
@@ -1171,6 +1171,17 @@ public class KeyEvent extends InputEvent implements Parcelable {
     */
    public static final int FLAG_START_TRACKING = 0x40000000;

    /**
     * Private flag that indicates when the system has detected that this key event
     * may be inconsistent with respect to the sequence of previously delivered key events,
     * such as when a key up event is sent but the key was not down.
     *
     * @hide
     * @see #isTainted
     * @see #setTainted
     */
    public static final int FLAG_TAINTED = 0x80000000;

    /**
     * Returns the maximum keycode.
     */
@@ -1534,6 +1545,33 @@ public class KeyEvent extends InputEvent implements Parcelable {
        return ev;
    }

    /**
     * Obtains a (potentially recycled) copy of another key event.
     *
     * @hide
     */
    public static KeyEvent obtain(KeyEvent other) {
        KeyEvent ev = obtain();
        ev.mDownTime = other.mDownTime;
        ev.mEventTime = other.mEventTime;
        ev.mAction = other.mAction;
        ev.mKeyCode = other.mKeyCode;
        ev.mRepeatCount = other.mRepeatCount;
        ev.mMetaState = other.mMetaState;
        ev.mDeviceId = other.mDeviceId;
        ev.mScanCode = other.mScanCode;
        ev.mFlags = other.mFlags;
        ev.mSource = other.mSource;
        ev.mCharacters = other.mCharacters;
        return ev;
    }

    /** @hide */
    @Override
    public KeyEvent copy() {
        return obtain(this);
    }

    /**
     * Recycles a key event.
     * Key events should only be recycled if they are owned by the system since user
@@ -1636,6 +1674,18 @@ public class KeyEvent extends InputEvent implements Parcelable {
        return event;
    }

    /** @hide */
    @Override
    public final boolean isTainted() {
        return (mFlags & FLAG_TAINTED) != 0;
    }

    /** @hide */
    @Override
    public final void setTainted(boolean tainted) {
        mFlags = tainted ? mFlags | FLAG_TAINTED : mFlags & ~FLAG_TAINTED;
    }

    /**
     * Don't use in new code, instead explicitly check
     * {@link #getAction()}.
+32 −0
Original line number Diff line number Diff line
@@ -307,6 +307,17 @@ public final class MotionEvent extends InputEvent implements Parcelable {
     */
    public static final int FLAG_WINDOW_IS_OBSCURED = 0x1;

    /**
     * Private flag that indicates when the system has detected that this motion event
     * may be inconsistent with respect to the sequence of previously delivered motion events,
     * such as when a pointer move event is sent but the pointer is not down.
     *
     * @hide
     * @see #isTainted
     * @see #setTainted
     */
    public static final int FLAG_TAINTED = 0x80000000;

    /**
     * Flag indicating the motion event intersected the top edge of the screen.
     */
@@ -1054,6 +1065,7 @@ public final class MotionEvent extends InputEvent implements Parcelable {
    private static native void nativeSetAction(int nativePtr, int action);
    private static native boolean nativeIsTouchEvent(int nativePtr);
    private static native int nativeGetFlags(int nativePtr);
    private static native void nativeSetFlags(int nativePtr, int flags);
    private static native int nativeGetEdgeFlags(int nativePtr);
    private static native void nativeSetEdgeFlags(int nativePtr, int action);
    private static native int nativeGetMetaState(int nativePtr);
@@ -1290,6 +1302,12 @@ public final class MotionEvent extends InputEvent implements Parcelable {
        return ev;
    }

    /** @hide */
    @Override
    public MotionEvent copy() {
        return obtain(this);
    }

    /**
     * Recycle the MotionEvent, to be re-used by a later caller.  After calling
     * this function you must not ever touch the event again.
@@ -1403,6 +1421,20 @@ public final class MotionEvent extends InputEvent implements Parcelable {
        return nativeGetFlags(mNativePtr);
    }

    /** @hide */
    @Override
    public final boolean isTainted() {
        final int flags = getFlags();
        return (flags & FLAG_TAINTED) != 0;
    }

    /** @hide */
    @Override
    public final void setTainted(boolean tainted) {
        final int flags = getFlags();
        nativeSetFlags(mNativePtr, tainted ? flags | FLAG_TAINTED : flags & ~FLAG_TAINTED);
    }

    /**
     * Returns the time (in ms) when the user originally pressed down to start
     * a stream of position events.
Loading