code: private static AccessibilityNodeInfoCompat getMatchingAncestor(
              Context context, AccessibilityNodeInfoCompat node, NodeFilter filter) {
          if (node == null) {
              return null;
          }
  
          final HashSet<AccessibilityNodeInfoCompat> ancestors =
                  new HashSet<AccessibilityNodeInfoCompat>();
  
          try {
              ancestors.add(AccessibilityNodeInfoCompat.obtain(node));
              node = node.getParent();
  
              while (node != null) {
                  if (!ancestors.add(node)) {
                      // Already seen this node, so abort!
                      node.recycle();
                      return null;
                  }
  
                  if (filter.accept(context, node)) {
                      // Send a copy since node gets recycled.
                      return AccessibilityNodeInfoCompat.obtain(node);
                  }
  
                  node = node.getParent();
              }
          } finally {
              recycleNodes(ancestors);
          }
  
          return null;
      }
docs: Returns the first ancestor of {@code node} that matches the
  {@code filter}. Returns {@code null} if no nodes match.