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

Commit 92cc2d8d authored by Jeff Brown's avatar Jeff Brown
Browse files

Remove type tests when recycling input events.

Change-Id: I1c2d5980a763c457a0546bbf601e686c601a4c03
parent 32cbc385
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -111,6 +111,21 @@ public abstract class InputEvent implements Parcelable {
        }
    }

    /**
     * Conditionally recycled the event if it is appropriate to do so after
     * dispatching the event to an application.
     *
     * If the event is a {@link MotionEvent} then it is recycled.
     *
     * If the event is a {@link KeyEvent} then it is NOT recycled, because applications
     * expect key events to be immutable so once the event has been dispatched to
     * the application we can no longer recycle it.
     * @hide
     */
    public void recycleIfNeededAfterDispatch() {
        recycle();
    }

    /**
     * Reinitializes the event on reuse (after recycling).
     * @hide
+1 −11
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ public abstract class InputEventReceiver {
                nativeFinishInputEvent(mReceiverPtr, handled);
            }
        }
        recycleInputEvent(event);
        event.recycleIfNeededAfterDispatch();
    }

    // Called from native code.
@@ -134,16 +134,6 @@ public abstract class InputEventReceiver {
        onInputEvent(event);
    }

    private static void recycleInputEvent(InputEvent event) {
        if (event instanceof MotionEvent) {
            // Event though key events are also recyclable, we only recycle motion events.
            // Historically, key events were not recyclable and applications expect
            // them to be immutable.  We only ever recycle key events behind the
            // scenes where an application never sees them (so, not here).
            event.recycle();
        }
    }

    public static interface Factory {
        public InputEventReceiver createInputEventReceiver(
                InputChannel inputChannel, Looper looper);
+7 −0
Original line number Diff line number Diff line
@@ -1596,6 +1596,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
     *
     * @hide
     */
    @Override
    public final void recycle() {
        super.recycle();
        mCharacters = null;
@@ -1609,6 +1610,12 @@ public class KeyEvent extends InputEvent implements Parcelable {
        }
    }

    /** @hide */
    @Override
    public final void recycleIfNeededAfterDispatch() {
        // Do nothing.
    }

    /**
     * Create a new key event that is the same as the given one, but whose
     * event time and repeat count are replaced with the given value.
+1 −0
Original line number Diff line number Diff line
@@ -1642,6 +1642,7 @@ public final class MotionEvent extends InputEvent implements Parcelable {
     * Recycle the MotionEvent, to be re-used by a later caller.  After calling
     * this function you must not ever touch the event again.
     */
    @Override
    public final void recycle() {
        super.recycle();

+2 −6
Original line number Diff line number Diff line
@@ -3848,12 +3848,8 @@ public final class ViewRootImpl extends Handler implements ViewParent,

        if (q.mReceiver != null) {
            q.mReceiver.finishInputEvent(q.mEvent, handled);
        } else if (q.mEvent instanceof MotionEvent) {
            // Event though key events are also recyclable, we only recycle motion events.
            // Historically, key events were not recyclable and applications expect
            // them to be immutable.  We only ever recycle key events behind the
            // scenes where an application never sees them (so, not here).
            q.mEvent.recycle();
        } else {
            q.mEvent.recycleIfNeededAfterDispatch();
        }

        recycleQueuedInputEvent(q);