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
diff --git a/services/accessibility/accessibility.aconfig b/services/accessibility/accessibility.aconfig
index 3709f47..0480c22 100644
--- a/services/accessibility/accessibility.aconfig
+++ b/services/accessibility/accessibility.aconfig
@@ -19,4 +19,11 @@
namespace: "accessibility"
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
diff --git a/services/accessibility/java/com/android/server/accessibility/gestures/TouchExplorer.java b/services/accessibility/java/com/android/server/accessibility/gestures/TouchExplorer.java
index 8060d5a..c418485 100644
--- a/services/accessibility/java/com/android/server/accessibility/gestures/TouchExplorer.java
+++ b/services/accessibility/java/com/android/server/accessibility/gestures/TouchExplorer.java
@@ -58,6 +58,7 @@
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,16 +353,34 @@
}
// The event for gesture end should be strictly after the
// last hover exit event.
- if (mSendTouchExplorationEndDelayed.isPending()) {
- mSendTouchExplorationEndDelayed.cancel();
- mDispatcher.sendAccessibilityEvent(TYPE_TOUCH_EXPLORATION_GESTURE_END);
- }
+ 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();
- mDispatcher.sendAccessibilityEvent(TYPE_TOUCH_INTERACTION_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);
+ }
+
+ // 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();
+ mDispatcher.sendAccessibilityEvent(TYPE_TOUCH_INTERACTION_END);
+ }
}
}
diff --git a/services/tests/servicestests/src/com/android/server/accessibility/gestures/TouchExplorerTest.java b/services/tests/servicestests/src/com/android/server/accessibility/gestures/TouchExplorerTest.java
index 4a06611f..1cd61e9 100644
--- a/services/tests/servicestests/src/com/android/server/accessibility/gestures/TouchExplorerTest.java
+++ b/services/tests/servicestests/src/com/android/server/accessibility/gestures/TouchExplorerTest.java
@@ -253,7 +253,8 @@
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);