Merge "Adding public event callback instead of the internal one to UiAutomation."
diff --git a/api/current.txt b/api/current.txt
index a1118ae..c9a0029 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -4153,7 +4153,7 @@
   }
 
   public final class UiAutomation {
-    method public android.view.accessibility.AccessibilityEvent executeAndWaitForEvent(java.lang.Runnable, com.android.internal.util.Predicate<android.view.accessibility.AccessibilityEvent>, 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 @@
     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 8d865da..7d02342 100644
--- a/core/java/android/app/UiAutomation.java
+++ b/core/java/android/app/UiAutomation.java
@@ -37,8 +37,6 @@
 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;
 
@@ -135,6 +133,21 @@
     }
 
     /**
+     * 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
      * operations on the provided connection.
@@ -428,7 +441,7 @@
      * @throws TimeoutException If the expected event is not received within the timeout.
      */
     public AccessibilityEvent executeAndWaitForEvent(Runnable command,
-            Predicate<AccessibilityEvent> filter, long timeoutMillis) throws TimeoutException {
+            AccessibilityEventFilter filter, long timeoutMillis) throws TimeoutException {
         synchronized (mLock) {
             throwIfNotConnectedLocked();
 
@@ -452,7 +465,7 @@
                         if (event.getEventTime() <= executionStartTimeMillis) {
                             continue;
                         }
-                        if (filter.apply(event)) {
+                        if (filter.accept(event)) {
                             return event;
                         }
                         event.recycle();