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

Commit 57c7fd5a authored by Svetoslav Ganov's avatar Svetoslav Ganov
Browse files

Fixing issues with the AccessibilityNodeInfo cache.

1. Before there were two caches one in the app process that
   kept track only the ids of infos that were given to a
   querying client and one in the querying client that
   holds the infos. This design requires precise sync
   between the caches. Doing that is somehow complicated
   since the app has cache for each window and it has
   to intercept all accessibility events from that window
   to manage the cache. Each app has to have a cache for
   each querying client. This approach would guarantee that
   no infos are fetched twice but due to its stateful nature
   and the two caches is tricky to implement and adds
   unnecessary complexity. Now there is only one cache in
   the client and the apps are stateless. The client is
   passing flags to the app that are a clue what nodes to
   prefetch. This approach may occasionally fetch a node
   twice but it is considerably simpler and stateless
   from the app perspective - there is only one cache.
   Fetching a node more than once does not cause much
   overhead compared to the IPC.

Change-Id: Ia02f6fe4f82cff9a9c2e21f4a36747de0f414c6f
parent 0d04e245
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -42,11 +42,12 @@ interface IAccessibilityServiceConnection {
     * @param interactionId The id of the interaction for matching with the callback result.
     * @param interactionId The id of the interaction for matching with the callback result.
     * @param callback Callback which to receive the result.
     * @param callback Callback which to receive the result.
     * @param threadId The id of the calling thread.
     * @param threadId The id of the calling thread.
     * @param prefetchFlags flags to guide prefetching.
     * @return The current window scale, where zero means a failure.
     * @return The current window scale, where zero means a failure.
     */
     */
    float findAccessibilityNodeInfoByAccessibilityId(int accessibilityWindowId,
    float findAccessibilityNodeInfoByAccessibilityId(int accessibilityWindowId,
        long accessibilityNodeId, int interactionId,
        long accessibilityNodeId, int interactionId,
        IAccessibilityInteractionConnectionCallback callback, long threadId);
        IAccessibilityInteractionConnectionCallback callback, long threadId, int prefetchFlags);


    /**
    /**
     * Finds {@link android.view.accessibility.AccessibilityNodeInfo}s by View text.
     * Finds {@link android.view.accessibility.AccessibilityNodeInfo}s by View text.
+10 −2
Original line number Original line Diff line number Diff line
@@ -57,6 +57,11 @@ public class UiTestAutomationBridge {


    public static final int UNDEFINED = -1;
    public static final int UNDEFINED = -1;


    private static final int FIND_ACCESSIBILITY_NODE_INFO_PREFETCH_FLAGS =
        AccessibilityNodeInfo.FLAG_PREFETCH_PREDECESSORS
        | AccessibilityNodeInfo.FLAG_PREFETCH_SIBLINGS
        | AccessibilityNodeInfo.FLAG_PREFETCH_DESCENDANTS;

    private final Object mLock = new Object();
    private final Object mLock = new Object();


    private volatile int mConnectionId = AccessibilityInteractionClient.NO_ID;
    private volatile int mConnectionId = AccessibilityInteractionClient.NO_ID;
@@ -351,13 +356,15 @@ public class UiTestAutomationBridge {
        ensureValidConnection(connectionId);
        ensureValidConnection(connectionId);
        return AccessibilityInteractionClient.getInstance()
        return AccessibilityInteractionClient.getInstance()
                .findAccessibilityNodeInfoByAccessibilityId(mConnectionId,
                .findAccessibilityNodeInfoByAccessibilityId(mConnectionId,
                        accessibilityWindowId, accessibilityNodeId);
                        accessibilityWindowId, accessibilityNodeId,
                        FIND_ACCESSIBILITY_NODE_INFO_PREFETCH_FLAGS);
    }
    }


    /**
    /**
     * Finds an {@link AccessibilityNodeInfo} by View id in the active
     * Finds an {@link AccessibilityNodeInfo} by View id in the active
     * window. The search is performed from the root node.
     * window. The search is performed from the root node.
     *
     *
     * @param viewId The id of a View.
     * @return The current window scale, where zero means a failure.
     * @return The current window scale, where zero means a failure.
     */
     */
    public AccessibilityNodeInfo findAccessibilityNodeInfoByViewIdInActiveWindow(int viewId) {
    public AccessibilityNodeInfo findAccessibilityNodeInfoByViewIdInActiveWindow(int viewId) {
@@ -373,6 +380,7 @@ public class UiTestAutomationBridge {
     *     {@link  #ACTIVE_WINDOW_ID} to query the currently active window.
     *     {@link  #ACTIVE_WINDOW_ID} to query the currently active window.
     * @param accessibilityNodeId A unique view id or virtual descendant id from
     * @param accessibilityNodeId A unique view id or virtual descendant id from
     *     where to start the search. Use {@link  #ROOT_NODE_ID} to start from the root.
     *     where to start the search. Use {@link  #ROOT_NODE_ID} to start from the root.
     * @param viewId The id of a View.
     * @return The current window scale, where zero means a failure.
     * @return The current window scale, where zero means a failure.
     */
     */
    public AccessibilityNodeInfo findAccessibilityNodeInfoByViewId(int accessibilityWindowId,
    public AccessibilityNodeInfo findAccessibilityNodeInfoByViewId(int accessibilityWindowId,
@@ -460,7 +468,7 @@ public class UiTestAutomationBridge {
        ensureValidConnection(connectionId);
        ensureValidConnection(connectionId);
        return AccessibilityInteractionClient.getInstance()
        return AccessibilityInteractionClient.getInstance()
                .findAccessibilityNodeInfoByAccessibilityId(connectionId, ACTIVE_WINDOW_ID,
                .findAccessibilityNodeInfoByAccessibilityId(connectionId, ACTIVE_WINDOW_ID,
                        ROOT_NODE_ID);
                        ROOT_NODE_ID, AccessibilityNodeInfo.FLAG_PREFETCH_DESCENDANTS);
    }
    }


    private void ensureValidConnection(int connectionId) {
    private void ensureValidConnection(int connectionId) {
+212 −87

File changed.

Preview size limit exceeded, changes collapsed.

+4 −4

File changed.

Preview size limit exceeded, changes collapsed.

+40 −12

File changed.

Preview size limit exceeded, changes collapsed.

Loading