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

Commit 213c13aa authored by Svetoslav's avatar Svetoslav
Browse files

Ensure touch explorer and magnifier get a well-formed event stream.

We use an input filter to manipulate the event stream in accessibility
mode. Some input events, i.e. touch and hover events, are delivered
to a touch explorer, if touch exploration is enabled, and to a magnifier,
if screen magnification is enabled. It is possible that at the moment
each of these features is enabled we are in the middle of a touch or
hover gesture. The touch explorer and screen magnifier expect to receive
an event stream that starts with an event that denotes the stream start.
This change ensures that hover or touch events are dispatched to the
touch explorer and the magnifier only after the start of the first
well-formed hover or touch sequence.

Change-Id: I8cd0ad8e1844c59fd55cf1dfacfb79af6a8916df
parent 3b53da49
Loading
Loading
Loading
Loading
+40 −5
Original line number Diff line number Diff line
@@ -41,8 +41,6 @@ class AccessibilityInputFilter extends InputFilter implements EventStreamTransfo

    private static final boolean DEBUG = false;

    private static final int UNDEFINED_DEVICE_ID = -1;

    /**
     * Flag for enabling the screen magnification feature.
     *
@@ -89,11 +87,17 @@ class AccessibilityInputFilter extends InputFilter implements EventStreamTransfo
    private int mEnabledFeatures;

    private TouchExplorer mTouchExplorer;

    private ScreenMagnifier mScreenMagnifier;

    private EventStreamTransformation mEventHandler;

    private MotionEventHolder mEventQueue;

    private boolean mMotionEventSequenceStarted;

    private boolean mHoverEventSequenceStarted;

    AccessibilityInputFilter(Context context, AccessibilityManagerService service) {
        super(context.getMainLooper());
        mContext = context;
@@ -138,17 +142,46 @@ class AccessibilityInputFilter extends InputFilter implements EventStreamTransfo
            return;
        }
        if ((policyFlags & WindowManagerPolicy.FLAG_PASS_TO_USER) == 0) {
            mMotionEventSequenceStarted = false;
            mHoverEventSequenceStarted = false;
            mEventHandler.clear();
            super.onInputEvent(event, policyFlags);
            return;
        }
        final int deviceId = event.getDeviceId();
        if (mCurrentDeviceId != deviceId) {
            if (mCurrentDeviceId != UNDEFINED_DEVICE_ID) {
            mMotionEventSequenceStarted = false;
            mHoverEventSequenceStarted = false;
            mEventHandler.clear();
            }
            mCurrentDeviceId = deviceId;
        }
        if (mCurrentDeviceId < 0) {
            super.onInputEvent(event, policyFlags);
            return;
        }
        // We do not handle scroll events.
        MotionEvent motionEvent = (MotionEvent) event;
        if (motionEvent.getActionMasked() == MotionEvent.ACTION_SCROLL) {
            super.onInputEvent(event, policyFlags);
            return;
        }
        // Wait for a down touch event to start processing.
        if (motionEvent.isTouchEvent()) {
            if (!mMotionEventSequenceStarted) {
                if (motionEvent.getActionMasked() != MotionEvent.ACTION_DOWN) {
                    return;
                }
                mMotionEventSequenceStarted = true;
            }
        } else {
        // Wait for an enter hover event to start processing.
            if (!mHoverEventSequenceStarted) {
                if (motionEvent.getActionMasked() != MotionEvent.ACTION_HOVER_ENTER) {
                    return;
                }
                mHoverEventSequenceStarted = true;
            }
        }
        batchMotionEvent((MotionEvent) event, policyFlags);
    }

@@ -250,6 +283,8 @@ class AccessibilityInputFilter extends InputFilter implements EventStreamTransfo
    }

    private void enableFeatures() {
        mMotionEventSequenceStarted = false;
        mHoverEventSequenceStarted = false;
        if ((mEnabledFeatures & FLAG_FEATURE_SCREEN_MAGNIFIER) != 0) {
            mEventHandler = mScreenMagnifier = new ScreenMagnifier(mContext,
                    Display.DEFAULT_DISPLAY, mAms);