From 550b48fa18f8b392be1aab46c5bb4ec92ac3328b Mon Sep 17 00:00:00 2001 From: Svetoslav Date: Tue, 12 Feb 2013 14:56:29 -0800 Subject: [PATCH] Adding public event callback instead of the internal one to UiAutomation. It appears that com.android.internal.util.Predicate is in the public APIs but it is in the internal package. Leaking the predicate APIs is a mistake and while we cannot fix that, this change is adding legit public filter interface. bug:8183223 Change-Id: I3e2c0ef685d7a832630aaa3ec2e8eae3fb058289 --- api/current.txt | 6 +++++- core/java/android/app/UiAutomation.java | 21 +++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/api/current.txt b/api/current.txt index d1155c4d191d7..64a711e5db982 100644 --- a/api/current.txt +++ b/api/current.txt @@ -4153,7 +4153,7 @@ package android.app { } public final class UiAutomation { - method public android.view.accessibility.AccessibilityEvent executeAndWaitForEvent(java.lang.Runnable, com.android.internal.util.Predicate, long) throws java.util.concurrent.TimeoutException; + method public android.view.accessibility.AccessibilityEvent executeAndWaitForEvent(java.lang.Runnable, android.app.UiAutomation.AccessibilityEventFilter, long) throws java.util.concurrent.TimeoutException; method public android.view.accessibility.AccessibilityNodeInfo getRootInActiveWindow(); method public final android.accessibilityservice.AccessibilityServiceInfo getServiceInfo(); method public boolean injectInputEvent(android.view.InputEvent, boolean); @@ -4171,6 +4171,10 @@ package android.app { field public static final int ROTATION_UNFREEZE = -2; // 0xfffffffe } + public static abstract interface UiAutomation.AccessibilityEventFilter { + method public abstract boolean accept(android.view.accessibility.AccessibilityEvent); + } + public static abstract interface UiAutomation.OnAccessibilityEventListener { method public abstract void onAccessibilityEvent(android.view.accessibility.AccessibilityEvent); } diff --git a/core/java/android/app/UiAutomation.java b/core/java/android/app/UiAutomation.java index 8d865da02f078..7d02342ca59cc 100644 --- a/core/java/android/app/UiAutomation.java +++ b/core/java/android/app/UiAutomation.java @@ -37,8 +37,6 @@ import android.view.accessibility.AccessibilityInteractionClient; import android.view.accessibility.AccessibilityNodeInfo; import android.view.accessibility.IAccessibilityInteractionConnection; -import com.android.internal.util.Predicate; - import java.util.ArrayList; import java.util.concurrent.TimeoutException; @@ -134,6 +132,21 @@ public final class UiAutomation { public void onAccessibilityEvent(AccessibilityEvent event); } + /** + * Listener for filtering accessibility events. + */ + public static interface AccessibilityEventFilter { + + /** + * Callback for determining whether an event is accepted or + * it is filtered out. + * + * @param event The event to process. + * @return True if the event is accepted, false to filter it out. + */ + public boolean accept(AccessibilityEvent event); + } + /** * Creates a new instance that will handle callbacks from the accessibility * layer on the thread of the provided looper and perform requests for privileged @@ -428,7 +441,7 @@ public final class UiAutomation { * @throws TimeoutException If the expected event is not received within the timeout. */ public AccessibilityEvent executeAndWaitForEvent(Runnable command, - Predicate filter, long timeoutMillis) throws TimeoutException { + AccessibilityEventFilter filter, long timeoutMillis) throws TimeoutException { synchronized (mLock) { throwIfNotConnectedLocked(); @@ -452,7 +465,7 @@ public final class UiAutomation { if (event.getEventTime() <= executionStartTimeMillis) { continue; } - if (filter.apply(event)) { + if (filter.accept(event)) { return event; } event.recycle();