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

Commit 443b8fb8 authored by ryanlwlin's avatar ryanlwlin
Browse files

[DO NOT MERGE] Fix incorrect order of Accessibility events

The Accessibility events order for gesture end and touch interaction
end are exchanged in following conditons:
1. touching duration is very short.
2. Hover exit events comes right away after receving
action_up.
It leads to incorrect state of touchExplorer and sending incorrect
hoverevent in next touch-interaction.

Bug: 150171638
Test: atest FrameworksServicesTests:com.android.server.accessibility.gestures
Test: atest android.accessibilityservice.cts.TouchExplorerTest
Test: manual test
Change-Id: Ia60d51414dd63a2a30be61372e8fbd2e3d9f723f
parent d5763c4c
Loading
Loading
Loading
Loading
+21 −6
Original line number Diff line number Diff line
@@ -274,10 +274,27 @@ public class TouchExplorer extends BaseEventStreamTransformation
    public void onAccessibilityEvent(AccessibilityEvent event) {
        final int eventType = event.getEventType();

        if (eventType == AccessibilityEvent.TYPE_VIEW_HOVER_EXIT) {
            sendsPendingA11yEventsIfNeed();
        }
        super.onAccessibilityEvent(event);
    }

    /*
     * Sends pending {@link AccessibilityEvent#TYPE_TOUCH_EXPLORATION_GESTURE_END} or {@{@link
     * AccessibilityEvent#TYPE_TOUCH_EXPLORATION_GESTURE_END}} after receiving last hover exit
     * event.
     */
    private void sendsPendingA11yEventsIfNeed() {
        // The last hover exit A11y event should be sent by view after receiving hover exit motion
        // event. In some view hierarchy, the ViewGroup transforms hover move motion event to hover
        // exit motion event and than dispatch to itself. It causes unexpected A11y exit events.
        if (mSendHoverExitDelayed.isPending()) {
            return;
        }
        // The event for gesture end should be strictly after the
        // last hover exit event.
        if (mSendTouchExplorationEndDelayed.isPending()
                && eventType == AccessibilityEvent.TYPE_VIEW_HOVER_EXIT) {
        if (mSendTouchExplorationEndDelayed.isPending()) {
            mSendTouchExplorationEndDelayed.cancel();
            mDispatcher.sendAccessibilityEvent(
                    AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_END);
@@ -285,12 +302,10 @@ public class TouchExplorer extends BaseEventStreamTransformation

        // The event for touch interaction end should be strictly after the
        // last hover exit and the touch exploration gesture end events.
        if (mSendTouchInteractionEndDelayed.isPending()
                && eventType == AccessibilityEvent.TYPE_VIEW_HOVER_EXIT) {
        if (mSendTouchInteractionEndDelayed.isPending()) {
            mSendTouchInteractionEndDelayed.cancel();
            mDispatcher.sendAccessibilityEvent(AccessibilityEvent.TYPE_TOUCH_INTERACTION_END);
        }
        super.onAccessibilityEvent(event);
    }

    @Override