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

Commit 9f5a0590 authored by Ivan Chiang's avatar Ivan Chiang
Browse files

Add isRootsUri method to check whether the roots uri is valid

Base on the buildRootsUri method to provide isRootsUri to check
whether the uri is valid.

Change-Id: I626de4a67670d165436ae51154fc7fec3c9b424b
Fix: 116180469
Test: atest ActionHandlerTest
parent 453e851d
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()