OSDN Git Service

Preserve order of a11y events
authorEugene Susla <eugenesusla@google.com>
Mon, 22 May 2017 20:14:57 +0000 (13:14 -0700)
committerEugene Susla <eugenesusla@google.com>
Mon, 22 May 2017 21:16:47 +0000 (14:16 -0700)
Test: cts-tradefed run singleCommand cts -d --module CtsAccessibilityServiceTestCases
cts-tradefed run singleCommand cts -d --module CtsAccessibilityTestCases
cts-tradefed run singleCommand cts -d --module CtsUiAutomationTestCases
Change-Id: I6a9230473f79148a3da9808d67d9e0c80abc8384

core/java/android/view/ViewRootImpl.java

index 28ded55..ded25ab 100644 (file)
@@ -7061,6 +7061,14 @@ public final class ViewRootImpl implements ViewParent,
         if (mView == null || mStopped || mPausedForTransition) {
             return false;
         }
+
+        // Immediately flush pending content changed event (if any) to preserve event order
+        if (event.getEventType() != AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED
+                && mSendWindowContentChangedAccessibilityEvent != null
+                && mSendWindowContentChangedAccessibilityEvent.mSource != null) {
+            mSendWindowContentChangedAccessibilityEvent.removeCallbacksAndRun();
+        }
+
         // Intercept accessibility focus events fired by virtual nodes to keep
         // track of accessibility focus position in such nodes.
         final int eventType = event.getEventType();
@@ -7893,11 +7901,15 @@ public final class ViewRootImpl implements ViewParent,
             final long minEventIntevalMillis =
                     ViewConfiguration.getSendRecurringAccessibilityEventsInterval();
             if (timeSinceLastMillis >= minEventIntevalMillis) {
-                mSource.removeCallbacks(this);
-                run();
+                removeCallbacksAndRun();
             } else {
                 mSource.postDelayed(this, minEventIntevalMillis - timeSinceLastMillis);
             }
         }
+
+        public void removeCallbacksAndRun() {
+            mSource.removeCallbacks(this);
+            run();
+        }
     }
 }