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

Commit 52ac7e2d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add isRootsUri method to check whether the roots uri is valid"

parents 77460ad1 9f5a0590
Loading
Loading
Loading
Loading
+27 −6
Original line number Diff line number Diff line
@@ -942,13 +942,26 @@ public final class DocumentsContract {
        return false;
    }

    /** {@hide} */
    public static boolean isRootUri(Context context, @Nullable Uri uri) {
        if (isContentUri(uri) && isDocumentsProvider(context, uri.getAuthority())) {
            final List<String> paths = uri.getPathSegments();
            return (paths.size() == 2 && PATH_ROOT.equals(paths.get(0)));
    /**
     * Test if the given URI represents roots backed by {@link DocumentsProvider}.
     *
     * @see #buildRootsUri(String)
     *
     * {@hide}
     */
    public static boolean isRootsUri(Context context, @Nullable Uri uri) {
        return isRootUri(context, uri, 1 /* pathSize */);
    }
        return false;

    /**
     * Test if the given URI represents specific root backed by {@link DocumentsProvider}.
     *
     * @see #buildRootUri(String, String)
     *
     * {@hide}
     */
    public static boolean isRootUri(Context context, @Nullable Uri uri) {
        return isRootUri(context, uri, 2 /* pathSize */);
    }

    /** {@hide} */
@@ -967,6 +980,14 @@ public final class DocumentsContract {
        return (paths.size() >= 2 && PATH_TREE.equals(paths.get(0)));
    }

    private static boolean isRootUri(Context context, @Nullable Uri uri, int pathSize) {
        if (isContentUri(uri) && isDocumentsProvider(context, uri.getAuthority())) {
            final List<String> paths = uri.getPathSegments();
            return (paths.size() == pathSize && PATH_ROOT.equals(paths.get(0)));
        }
        return false;
    }

    private static boolean isDocumentsProvider(Context context, String authority) {
        final Intent intent = new Intent(PROVIDER_INTERFACE);
        final List<ResolveInfo> infos = context.getPackageManager()