From a5eacc0ac48cdf3fc5c78b0cdca6a301f1cda607 Mon Sep 17 00:00:00 2001 From: Hiroki Sato Date: Thu, 9 Feb 2023 20:31:46 +0900 Subject: [PATCH] Fix UiAutomation to correctly wait for idleness Currently, everytime onAccessibilityEvent is called, "lastEventTime" is updated with the event timestamp. However, accessibility framework doesn't always sends events by the order of the timestamp, so it's possible that the timestamp is updated with an older event's timestamp. This fixes the issue by updating the variable with maximum of the current value and the event time. Test: CtsCompanionDeviceManagerUiAutomationTestCases (fixes flakiness) Test: UiAutomationTest Bug: 262184630 Bug: 268464095 Change-Id: If3306c6a6624a8b76a17d2c7b745143e5f9c1ed3 --- core/java/android/app/UiAutomation.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/java/android/app/UiAutomation.java b/core/java/android/app/UiAutomation.java index 249937a72d740..cda2397533fb1 100644 --- a/core/java/android/app/UiAutomation.java +++ b/core/java/android/app/UiAutomation.java @@ -1623,7 +1623,9 @@ public final class UiAutomation { if (isGenerationChangedLocked()) { return; } - mLastEventTimeMillis = event.getEventTime(); + // It is not guaranteed that the accessibility framework sends events by the + // order of event timestamp. + mLastEventTimeMillis = Math.max(mLastEventTimeMillis, event.getEventTime()); if (mWaitingForEventDelivery) { mEventQueue.add(AccessibilityEvent.obtain(event)); }