Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 550b48fa authored by Svetoslav's avatar Svetoslav
Browse files

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
parent bbfa585d
Loading
Loading
Loading
Loading
+5 −1
Original line number Original line Diff line number Diff line
@@ -4153,7 +4153,7 @@ package android.app {
  }
  }
  public final class UiAutomation {
  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 android.view.accessibility.AccessibilityNodeInfo getRootInActiveWindow();
    method public final android.accessibilityservice.AccessibilityServiceInfo getServiceInfo();
    method public final android.accessibilityservice.AccessibilityServiceInfo getServiceInfo();
    method public boolean injectInputEvent(android.view.InputEvent, boolean);
    method public boolean injectInputEvent(android.view.InputEvent, boolean);
@@ -4171,6 +4171,10 @@ package android.app {
    field public static final int ROTATION_UNFREEZE = -2; // 0xfffffffe
    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 {
  public static abstract interface UiAutomation.OnAccessibilityEventListener {
    method public abstract void onAccessibilityEvent(android.view.accessibility.AccessibilityEvent);
    method public abstract void onAccessibilityEvent(android.view.accessibility.AccessibilityEvent);
  }
  }
+17 −4
Original line number Original line Diff line number Diff line
@@ -37,8 +37,6 @@ import android.view.accessibility.AccessibilityInteractionClient;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.IAccessibilityInteractionConnection;
import android.view.accessibility.IAccessibilityInteractionConnection;


import com.android.internal.util.Predicate;

import java.util.ArrayList;
import java.util.ArrayList;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.TimeoutException;


@@ -134,6 +132,21 @@ public final class UiAutomation {
        public void onAccessibilityEvent(AccessibilityEvent event);
        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
     * Creates a new instance that will handle callbacks from the accessibility
     * layer on the thread of the provided looper and perform requests for privileged
     * 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.
     * @throws TimeoutException If the expected event is not received within the timeout.
     */
     */
    public AccessibilityEvent executeAndWaitForEvent(Runnable command,
    public AccessibilityEvent executeAndWaitForEvent(Runnable command,
            Predicate<AccessibilityEvent> filter, long timeoutMillis) throws TimeoutException {
            AccessibilityEventFilter filter, long timeoutMillis) throws TimeoutException {
        synchronized (mLock) {
        synchronized (mLock) {
            throwIfNotConnectedLocked();
            throwIfNotConnectedLocked();


@@ -452,7 +465,7 @@ public final class UiAutomation {
                        if (event.getEventTime() <= executionStartTimeMillis) {
                        if (event.getEventTime() <= executionStartTimeMillis) {
                            continue;
                            continue;
                        }
                        }
                        if (filter.apply(event)) {
                        if (filter.accept(event)) {
                            return event;
                            return event;
                        }
                        }
                        event.recycle();
                        event.recycle();