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

Commit 8f749f45 authored by Josh Simmons's avatar Josh Simmons Committed by Android (Google) Code Review
Browse files

Merge "Allow client (DocumentsUI) to specify search result limit" into main

parents edfad2f6 bbe68bfd
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ aconfig_declarations_group {
        "com.android.hardware.input-aconfig-java",
        "com.android.input.flags-aconfig-java",
        "com.android.internal.compat.flags-aconfig-java",
        "com.android.internal.content.storage.flags-aconfig-java",
        "com.android.internal.foldables.flags-aconfig-java",
        "com.android.internal.os.flags-aconfig-java",
        "com.android.internal.pm.pkg.component.flags-aconfig-java",
@@ -1024,6 +1025,12 @@ java_aconfig_library {
    defaults: ["framework-minus-apex-aconfig-java-defaults"],
}

java_aconfig_library {
    name: "com.android.internal.content.storage.flags-aconfig-java",
    aconfig_declarations: "com.android.internal.content.storage.flags-aconfig",
    defaults: ["framework-minus-apex-aconfig-java-defaults"],
}

// Multi user
aconfig_declarations {
    name: "android.multiuser.flags-aconfig",
+7 −2
Original line number Diff line number Diff line
@@ -1184,8 +1184,9 @@ public final class DocumentsContract {
     * {@link DocumentsContract#QUERY_ARG_EXCLUDE_MEDIA},
     * {@link DocumentsContract#QUERY_ARG_DISPLAY_NAME},
     * {@link DocumentsContract#QUERY_ARG_MIME_TYPES},
     * {@link DocumentsContract#QUERY_ARG_FILE_SIZE_OVER} and
     * {@link DocumentsContract#QUERY_ARG_LAST_MODIFIED_AFTER}.
     * {@link DocumentsContract#QUERY_ARG_FILE_SIZE_OVER},
     * {@link DocumentsContract#QUERY_ARG_LAST_MODIFIED_AFTER} and
     * {@link ContentResolver#QUERY_ARG_LIMIT}.
     *
     * @param queryArgs the query arguments to be parsed.
     * @return the handled query arguments
@@ -1217,6 +1218,10 @@ public final class DocumentsContract {
        if (queryArgs.keySet().contains(QUERY_ARG_MIME_TYPES)) {
            args.add(QUERY_ARG_MIME_TYPES);
        }

        if (queryArgs.keySet().contains(ContentResolver.QUERY_ARG_LIMIT)) {
            args.add(ContentResolver.QUERY_ARG_LIMIT);
        }
        return args.toArray(new String[0]);
    }

+0 −2
Original line number Diff line number Diff line
# Bug component: 36137
include /core/java/android/content/pm/OWNERS

per-file FileSystemProvider.java = file:/core/java/android/os/storage/OWNERS

per-file ReferrerIntent.aidl = file:/services/core/java/com/android/server/am/OWNERS
per-file ReferrerIntent.java = file:/services/core/java/com/android/server/am/OWNERS
+8 −0
Original line number Diff line number Diff line
aconfig_declarations {
    name: "com.android.internal.content.storage.flags-aconfig",
    package: "com.android.internal.content.storage.flags",
    container: "system",
    srcs: [
        "flags.aconfig",
    ],
}
+20 −6
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import android.util.Log;
import android.webkit.MimeTypeMap;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.content.storage.flags.Flags;
import com.android.internal.util.ArrayUtils;

import libcore.io.IoUtils;
@@ -85,9 +86,11 @@ public abstract class FileSystemProvider extends DocumentsProvider {
            DocumentsContract.QUERY_ARG_DISPLAY_NAME,
            DocumentsContract.QUERY_ARG_FILE_SIZE_OVER,
            DocumentsContract.QUERY_ARG_LAST_MODIFIED_AFTER,
            DocumentsContract.QUERY_ARG_MIME_TYPES);
            DocumentsContract.QUERY_ARG_MIME_TYPES,
            ContentResolver.QUERY_ARG_LIMIT);

    private static final int MAX_RESULTS_NUMBER = 23;
    private static final int DEFAULT_SEARCH_RESULT_LIMIT = 23;
    private static final int MAX_SEARCH_RESULT_LIMIT = 1000;

    private static String joinNewline(String... args) {
        return TextUtils.join("\n", args);
@@ -431,10 +434,10 @@ public abstract class FileSystemProvider extends DocumentsProvider {
    /**
     * Searches documents under the given folder.
     *
     * To avoid runtime explosion only returns the at most 23 items.
     * To avoid runtime explosion only returns the at most 23 items unless the caller
     * (DocumentsUI) explicitly asks for up to MAX_SEARCH_RESULT_LIMIT using a non-negative limit.
     *
     * @param folder the root folder where recursive search begins
     * @param query the search condition used to match file names
     * @param projection projection of the returned cursor
     * @param exclusion absolute file paths to exclude from result
     * @param queryArgs the query arguments for search
@@ -450,11 +453,22 @@ public abstract class FileSystemProvider extends DocumentsProvider {
            Set<String> exclusion, Bundle queryArgs) throws FileNotFoundException {
        final MatrixCursor result = new MatrixCursor(resolveProjection(projection));

        int maxResults = DEFAULT_SEARCH_RESULT_LIMIT;
        if (Flags.useFileSystemProviderSearchLimits()) {
            maxResults = queryArgs.getInt(ContentResolver.QUERY_ARG_LIMIT,
                    DEFAULT_SEARCH_RESULT_LIMIT);
            if (maxResults > MAX_SEARCH_RESULT_LIMIT) {
                maxResults = MAX_SEARCH_RESULT_LIMIT;
            } else if (maxResults < 0) {
                maxResults = DEFAULT_SEARCH_RESULT_LIMIT;
            }
        }

        // We'll be a running a BFS here.
        final Queue<File> pending = new ArrayDeque<>();
        pending.offer(folder);

        while (!pending.isEmpty() && result.getCount() < MAX_RESULTS_NUMBER) {
        while (!pending.isEmpty() && result.getCount() < maxResults) {
            final File file = pending.poll();

            // Skip hidden documents (both files and directories)
Loading