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

Commit fb76caf3 authored by Ameer Armaly's avatar Ameer Armaly
Browse files

Fix TouchExplorerTest flakiness.

1) Fix the test behavior to wait 10 milliseconds before sending the up event.
The point is to make sure that the delays for hover enter and exit are not scheduled for the same moment.
Scheduling them for the exact same moment can cause them to fire out of order.
It also causes the test to more closely reflect real-world behavior.
2) Send accessibility events based on the internal state as needed in TouchExplorer#onAccessibilityEvent.
Since accessibility events trigger internal state changes, we determine whether we need to send them  based on the internal state and not by unrelated things like whether we have a pending runnable to send them.

Fix: 295575684
Test: atest FrameworksServicesTests:com.android.server.accessibility.gestures.TouchExplorerTest --rerun-until-failure 300

Change-Id: I008d69add4a59ada8718463970cb66b3f07118ec
parent 5cadfad5
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -20,3 +20,10 @@ flag {
    description: "Whether to enable joystick controls for magnification"
    bug: "297211257"
}

flag {
    name: "send_a11y_events_based_on_state"
    namespace: "accessibility"
    description: "Sends accessibility events in TouchExplorer#onAccessibilityEvent based on internal state to keep it consistent. This reduces test flakiness."
bug: "295575684"
}
 No newline at end of file
+28 −9
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.server.accessibility.AccessibilityManagerService;
import com.android.server.accessibility.BaseEventStreamTransformation;
import com.android.server.accessibility.EventStreamTransformation;
import com.android.server.accessibility.Flags;
import com.android.server.policy.WindowManagerPolicy;

import java.util.ArrayList;
@@ -352,6 +353,23 @@ public class TouchExplorer extends BaseEventStreamTransformation
        }
        // The event for gesture end should be strictly after the
        // last hover exit event.
        if (Flags.sendA11yEventsBasedOnState()) {
            if (mSendTouchExplorationEndDelayed.isPending()) {
                mSendTouchExplorationEndDelayed.cancel();
            }
            if (mState.isTouchExploring()) {
                mDispatcher.sendAccessibilityEvent(TYPE_TOUCH_EXPLORATION_GESTURE_END);
            }

            // The event for touch interaction end should be strictly after the
            // last hover exit and the touch exploration gesture end events.
            if (mSendTouchInteractionEndDelayed.isPending()) {
                mSendTouchInteractionEndDelayed.cancel();
            }
            if (mState.isTouchInteracting()) {
                mDispatcher.sendAccessibilityEvent(TYPE_TOUCH_INTERACTION_END);
            }
        } else {
            if (mSendTouchExplorationEndDelayed.isPending()) {
                mSendTouchExplorationEndDelayed.cancel();
                mDispatcher.sendAccessibilityEvent(TYPE_TOUCH_EXPLORATION_GESTURE_END);
@@ -364,6 +382,7 @@ public class TouchExplorer extends BaseEventStreamTransformation
                mDispatcher.sendAccessibilityEvent(TYPE_TOUCH_INTERACTION_END);
            }
        }
    }

    @Override
    public void onDoubleTapAndHold(MotionEvent event, MotionEvent rawEvent, int policyFlags) {
+2 −1
Original line number Diff line number Diff line
@@ -253,7 +253,8 @@ public class TouchExplorerTest {
        goFromStateClearTo(STATE_TOUCH_EXPLORING_1FINGER);
        moveEachPointers(mLastEvent, p(10, 10));
        send(mLastEvent);

        // Wait 10 ms to make sure that hover enter and exit are not scheduled for the same moment.
        mHandler.fastForward(10);
        send(upEvent());
        // Wait for sending hover exit event to transit to clear state.
        mHandler.fastForward(USER_INTENT_TIMEOUT);