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

Commit 4a53edcf authored by Ryan Lin's avatar Ryan Lin Committed by Android (Google) Code Review
Browse files

Merge "Fix sometime couldn't trigger A11y button with 3-finger"

parents 8c438343 ae92e25c
Loading
Loading
Loading
Loading
+69 −0
Original line number Diff line number Diff line
@@ -256,6 +256,7 @@ class EventDispatcher {
                return actionMasked;
        }
    }

    /**
     * Sends down events to the view hierarchy for all pointers which are not already being
     * delivered i.e. pointers that are not yet injected.
@@ -285,6 +286,74 @@ class EventDispatcher {
    }

    /**
     * Sends down events to the view hierarchy for all pointers which are not already being
     * delivered with original down location. i.e. pointers that are not yet injected.
     *
     * @param prototype The prototype from which to create the injected events.
     * @param policyFlags The policy flags associated with the event.
     */
    void sendDownForAllNotInjectedPointersWithOriginalDown(MotionEvent prototype, int policyFlags) {
        // Inject the injected pointers.
        int pointerIdBits = 0;
        final int pointerCount = prototype.getPointerCount();
        final MotionEvent event = computeEventWithOriginalDown(prototype);
        for (int i = 0; i < pointerCount; i++) {
            final int pointerId = prototype.getPointerId(i);
            // Do not send event for already delivered pointers.
            if (!mState.isInjectedPointerDown(pointerId)) {
                pointerIdBits |= (1 << pointerId);
                final int action = computeInjectionAction(MotionEvent.ACTION_DOWN, i);
                sendMotionEvent(
                        event,
                        action,
                        mState.getLastReceivedEvent(),
                        pointerIdBits,
                        policyFlags);
            }
        }
    }

    private MotionEvent computeEventWithOriginalDown(MotionEvent prototype) {
        final int pointerCount = prototype.getPointerCount();
        if (pointerCount != mState.getReceivedPointerTracker().getReceivedPointerDownCount()) {
            Slog.w(LOG_TAG, "The pointer count doesn't match the received count.");
            return MotionEvent.obtain(prototype);
        }
        MotionEvent.PointerCoords[] coords = new MotionEvent.PointerCoords[pointerCount];
        MotionEvent.PointerProperties[] properties =
                new MotionEvent.PointerProperties[pointerCount];
        for (int i = 0; i < pointerCount; ++i) {
            final int pointerId = prototype.getPointerId(i);
            final float x = mState.getReceivedPointerTracker().getReceivedPointerDownX(pointerId);
            final float y = mState.getReceivedPointerTracker().getReceivedPointerDownY(pointerId);
            coords[i] = new MotionEvent.PointerCoords();
            coords[i].x = x;
            coords[i].y = y;
            properties[i] = new MotionEvent.PointerProperties();
            properties[i].id = pointerId;
            properties[i].toolType = MotionEvent.TOOL_TYPE_FINGER;
        }
        MotionEvent event =
                MotionEvent.obtain(
                        prototype.getDownTime(),
                        prototype.getEventTime(),
                        prototype.getAction(),
                        pointerCount,
                        properties,
                        coords,
                        prototype.getMetaState(),
                        prototype.getButtonState(),
                        prototype.getXPrecision(),
                        prototype.getYPrecision(),
                        prototype.getDeviceId(),
                        prototype.getEdgeFlags(),
                        prototype.getSource(),
                        prototype.getFlags());
        return event;
    }

    /**
     *
     * Sends up events to the view hierarchy for all pointers which are already being delivered i.e.
     * pointers that are injected.
     *
+7 −1
Original line number Diff line number Diff line
@@ -651,7 +651,13 @@ public class TouchExplorer extends BaseEventStreamTransformation
                                    Slog.d(LOG_TAG, "Three-finger edge swipe detected.");
                                }
                                mState.startDelegating();
                                mDispatcher.sendDownForAllNotInjectedPointers(event, policyFlags);
                                if (mState.isTouchExploring()) {
                                    mDispatcher.sendDownForAllNotInjectedPointers(event,
                                            policyFlags);
                                } else {
                                    mDispatcher.sendDownForAllNotInjectedPointersWithOriginalDown(
                                            event, policyFlags);
                                }
                            }
                        }
                    }