public static AccessibilityRole getRole(AccessibilityNodeInfoCompat nodeInfo) {
    // NULLSAFE_FIXME[Parameter Not Nullable]
    AccessibilityRole role = AccessibilityRole.fromValue((String) nodeInfo.getClassName());
    if (role.equals(AccessibilityRole.IMAGE_BUTTON) || role.equals(AccessibilityRole.IMAGE)) {
      return nodeInfo.isClickable() ? AccessibilityRole.IMAGE_BUTTON : AccessibilityRole.IMAGE;
    }

    if (role.equals(AccessibilityRole.NONE)) {
      AccessibilityNodeInfoCompat.CollectionInfoCompat collection = nodeInfo.getCollectionInfo();
      if (collection != null) {
        // RecyclerView will be classified as a list or grid.
        if (collection.getRowCount() > 1 && collection.getColumnCount() > 1) {
          return AccessibilityRole.GRID;
        } else {
          return AccessibilityRole.LIST;
        }
      }
    }

    return role;
  }
Gets the role from a given {@link AccessibilityNodeInfoCompat}. If no role is defined it will
return AccessibilityRole.NONE, which has a value of null.

@param nodeInfo The node to check.
@return {@code AccessibilityRole} the defined role.
core/src/main/java/com/facebook/testing/screenshot/layouthierarchy/AccessibilityUtil.java