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
diff --git a/api/current.txt b/api/current.txt
index d1155c4..64a711e 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();