From bd573236f8f419161c56be72876a0546f650f947 Mon Sep 17 00:00:00 2001 From: Eugene Susla Date: Mon, 26 Feb 2018 10:41:28 -0800 Subject: [DO NOT MERGE] Sort A11yService#getWindows by layer descending This is what A11yService#getWindows promises in the javadoc. Fixes: 71581072 Test: using testback ensure the order is correct Change-Id: I5038c4de29c60e235b65751f7bd7771ef35eb339 (cherry picked from commit f40da1a884493b6af61e3b978fdf7c7ff059b2dc) --- .../android/accessibilityservice/AccessibilityService.java | 2 +- core/java/android/app/UiAutomation.java | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'core/java/android') diff --git a/core/java/android/accessibilityservice/AccessibilityService.java b/core/java/android/accessibilityservice/AccessibilityService.java index 0a4541ba4777..829a94446937 100644 --- a/core/java/android/accessibilityservice/AccessibilityService.java +++ b/core/java/android/accessibilityservice/AccessibilityService.java @@ -537,7 +537,7 @@ public abstract class AccessibilityService extends Service { * anything behind it, then only the modal window will be reported * (assuming it is the top one). For convenience the returned windows * are ordered in a descending layer order, which is the windows that - * are higher in the Z-order are reported first. Since the user can always + * are on top are reported first. Since the user can always * interact with the window that has input focus by typing, the focused * window is always returned (even if covered by a modal window). *

diff --git a/core/java/android/app/UiAutomation.java b/core/java/android/app/UiAutomation.java index bd4933a2081c..c03340e84a85 100644 --- a/core/java/android/app/UiAutomation.java +++ b/core/java/android/app/UiAutomation.java @@ -580,6 +580,8 @@ public final class UiAutomation { // Execute the command *without* the lock being held. command.run(); + List receivedEvents = new ArrayList<>(); + // Acquire the lock and wait for the event. try { // Wait for the event. @@ -600,14 +602,14 @@ public final class UiAutomation { if (filter.accept(event)) { return event; } - event.recycle(); + receivedEvents.add(event); } // Check if timed out and if not wait. final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis; final long remainingTimeMillis = timeoutMillis - elapsedTimeMillis; if (remainingTimeMillis <= 0) { throw new TimeoutException("Expected event not received within: " - + timeoutMillis + " ms."); + + timeoutMillis + " ms among: " + receivedEvents); } synchronized (mLock) { if (mEventQueue.isEmpty()) { @@ -620,6 +622,11 @@ public final class UiAutomation { } } } finally { + int size = receivedEvents.size(); + for (int i = 0; i < size; i++) { + receivedEvents.get(i).recycle(); + } + synchronized (mLock) { mWaitingForEventDelivery = false; mEventQueue.clear(); -- cgit v1.2.3