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

Commit e8580af4 authored by Ameer Armaly's avatar Ameer Armaly Committed by Android (Google) Code Review
Browse files

Merge "TouchExplorer: pass raw events when sending events."

parents d9a98add 6d70fac9
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -72,10 +72,16 @@ class EventDispatcher {
     *
     * @param prototype The prototype from which to create the injected events.
     * @param action The action of the event.
     * @param rawEvent The original event prior to magnification or other transformations.
     * @param pointerIdBits The bits of the pointers to send.
     * @param policyFlags The policy flags associated with the event.
     */
    void sendMotionEvent(MotionEvent prototype, int action, int pointerIdBits, int policyFlags) {
    void sendMotionEvent(
            MotionEvent prototype,
            int action,
            MotionEvent rawEvent,
            int pointerIdBits,
            int policyFlags) {
        prototype.setAction(action);

        MotionEvent event = null;
@@ -105,11 +111,8 @@ class EventDispatcher {

        // Make sure that the user will see the event.
        policyFlags |= WindowManagerPolicy.FLAG_PASS_TO_USER;
        // TODO: For now pass null for the raw event since the touch
        //       explorer is the last event transformation and it does
        //       not care about the raw event.
        if (mReceiver != null) {
            mReceiver.onMotionEvent(event, null, policyFlags);
            mReceiver.onMotionEvent(event, rawEvent, policyFlags);
        } else {
            Slog.e(LOG_TAG, "Error sending event: no receiver specified.");
        }
@@ -280,7 +283,12 @@ class EventDispatcher {
            if (!isInjectedPointerDown(pointerId)) {
                pointerIdBits |= (1 << pointerId);
                final int action = computeInjectionAction(MotionEvent.ACTION_DOWN, i);
                sendMotionEvent(prototype, action, pointerIdBits, policyFlags);
                sendMotionEvent(
                        prototype,
                        action,
                        mState.getLastReceivedEvent(),
                        pointerIdBits,
                        policyFlags);
            }
        }
    }
@@ -303,7 +311,8 @@ class EventDispatcher {
            }
            pointerIdBits |= (1 << pointerId);
            final int action = computeInjectionAction(MotionEvent.ACTION_UP, i);
            sendMotionEvent(prototype, action, pointerIdBits, policyFlags);
            sendMotionEvent(
                    prototype, action, mState.getLastReceivedEvent(), pointerIdBits, policyFlags);
        }
    }
}
+84 −41

File changed.

Preview size limit exceeded, changes collapsed.

+14 −12
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ public class TouchState {
    // Helper class to track received pointers.
    // Todo: collapse or hide this class so multiple classes don't modify it.
    private final ReceivedPointerTracker mReceivedPointerTracker;
    private MotionEvent mLastReceivedEvent;

    public TouchState() {
        mReceivedPointerTracker = new ReceivedPointerTracker();
@@ -80,6 +81,10 @@ public class TouchState {
    public void clear() {
        setState(STATE_CLEAR);
        // Reset the pointer trackers.
        if (mLastReceivedEvent != null) {
            mLastReceivedEvent.recycle();
            mLastReceivedEvent = null;
        }
        mReceivedPointerTracker.clear();
    }

@@ -89,6 +94,10 @@ public class TouchState {
     * @param rawEvent The raw touch event.
     */
    public void onReceivedMotionEvent(MotionEvent rawEvent) {
        if (mLastReceivedEvent != null) {
            mLastReceivedEvent.recycle();
        }
        mLastReceivedEvent = MotionEvent.obtain(rawEvent);
        mReceivedPointerTracker.onMotionEvent(rawEvent);
    }

@@ -216,6 +225,11 @@ public class TouchState {
        return mReceivedPointerTracker;
    }

    /** @return The last received event. */
    public MotionEvent getLastReceivedEvent() {
        return mLastReceivedEvent;
    }

    /** This class tracks where and when a pointer went down. It does not track its movement. */
    class ReceivedPointerTracker {
        private static final String LOG_TAG_RECEIVED_POINTER_TRACKER = "ReceivedPointerTracker";
@@ -232,8 +246,6 @@ public class TouchState {
        // or if it goes up the next one that most recently went down.
        private int mPrimaryPointerId;

        // Keep track of the last up pointer data.
        private MotionEvent mLastReceivedEvent;

        ReceivedPointerTracker() {
            clear();
@@ -254,11 +266,6 @@ public class TouchState {
         * @param event The event to process.
         */
        public void onMotionEvent(MotionEvent event) {
            if (mLastReceivedEvent != null) {
                mLastReceivedEvent.recycle();
            }
            mLastReceivedEvent = MotionEvent.obtain(event);

            final int action = event.getActionMasked();
            switch (action) {
                case MotionEvent.ACTION_DOWN:
@@ -279,11 +286,6 @@ public class TouchState {
            }
        }

        /** @return The last received event. */
        public MotionEvent getLastReceivedEvent() {
            return mLastReceivedEvent;
        }

        /** @return The number of received pointers that are down. */
        public int getReceivedPointerDownCount() {
            return Integer.bitCount(mReceivedPointersDown);
+2 −51
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@ import android.graphics.Point;
import android.os.Handler;
import android.os.Message;
import android.os.RemoteException;
import android.util.Log;
import android.view.Display;
import android.view.InputDevice;
import android.view.KeyEvent;
@@ -55,6 +54,8 @@ import android.view.accessibility.AccessibilityEvent;

import androidx.test.runner.AndroidJUnit4;

import com.android.server.accessibility.utils.MotionEventMatcher;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
@@ -761,56 +762,6 @@ public class MotionEventInjectorTest {
        return next;
    }

    static class MotionEventMatcher extends TypeSafeMatcher<MotionEvent> {
        long mDownTime;
        long mEventTime;
        long mActionMasked;
        int mX;
        int mY;

        MotionEventMatcher(long downTime, long eventTime, int actionMasked, int x, int y) {
            mDownTime = downTime;
            mEventTime = eventTime;
            mActionMasked = actionMasked;
            mX = x;
            mY = y;
        }

        MotionEventMatcher(MotionEvent event) {
            this(event.getDownTime(), event.getEventTime(), event.getActionMasked(),
                    (int) event.getX(), (int) event.getY());
        }

        void offsetTimesBy(long timeOffset) {
            mDownTime += timeOffset;
            mEventTime += timeOffset;
        }

        @Override
        public boolean matchesSafely(MotionEvent event) {
            if ((event.getDownTime() == mDownTime) && (event.getEventTime() == mEventTime)
                    && (event.getActionMasked() == mActionMasked) && ((int) event.getX() == mX)
                    && ((int) event.getY() == mY)) {
                return true;
            }
            Log.e(LOG_TAG, "MotionEvent match failed");
            Log.e(LOG_TAG, "event.getDownTime() = " + event.getDownTime()
                    + ", expected " + mDownTime);
            Log.e(LOG_TAG, "event.getEventTime() = " + event.getEventTime()
                    + ", expected " + mEventTime);
            Log.e(LOG_TAG, "event.getActionMasked() = " + event.getActionMasked()
                    + ", expected " + mActionMasked);
            Log.e(LOG_TAG, "event.getX() = " + event.getX() + ", expected " + mX);
            Log.e(LOG_TAG, "event.getY() = " + event.getY() + ", expected " + mY);
            return false;
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("Motion event matcher");
        }
    }

    private static class MotionEventActionMatcher extends TypeSafeMatcher<MotionEvent> {
        int mAction;

+5 −0

File changed.

Preview size limit exceeded, changes collapsed.

Loading