Add a more flexible queryRecentDocuments
The existing queryRecentDocuments have a hard limit 64. However, case
like ARC++ wishes to have a more flexible limit that can be passed as an
extra parameter. This new API will gracefully degrade to the old API to
maintain backward compatibility with old providers.
Bug: 111288304
Test: manual test (patched the MediaDocumentsProvider, and test calling
the new API):
1. Test that passing Bundle with QUERY_ARG_LIMIT=5 is honored and
returned is limited to 5.
2. Test that passing null will release the limit to default 64.
3. Test that removing MediaProvider implementation for new method and
implement the old method will automatically redirect the call to old
method (backward compatible with old providers).
Change-Id: I37b1785b94f3e9cf09128fbf1e8779a4447fe7a9
diff --git a/api/current.txt b/api/current.txt
index a6ee08b..f091409 100755
--- a/api/current.txt
+++ b/api/current.txt
@@ -36296,6 +36296,7 @@
method public android.database.Cursor queryChildDocuments(java.lang.String, java.lang.String[], android.os.Bundle) throws java.io.FileNotFoundException;
method public abstract android.database.Cursor queryDocument(java.lang.String, java.lang.String[]) throws java.io.FileNotFoundException;
method public android.database.Cursor queryRecentDocuments(java.lang.String, java.lang.String[]) throws java.io.FileNotFoundException;
+ method public android.database.Cursor queryRecentDocuments(java.lang.String, java.lang.String[], android.os.Bundle, android.os.CancellationSignal) throws java.io.FileNotFoundException;
method public abstract android.database.Cursor queryRoots(java.lang.String[]) throws java.io.FileNotFoundException;
method public android.database.Cursor querySearchDocuments(java.lang.String, java.lang.String, java.lang.String[]) throws java.io.FileNotFoundException;
method public void removeDocument(java.lang.String, java.lang.String) throws java.io.FileNotFoundException;
diff --git a/core/java/android/provider/DocumentsProvider.java b/core/java/android/provider/DocumentsProvider.java
index 81b1921..c7d37ad 100644
--- a/core/java/android/provider/DocumentsProvider.java
+++ b/core/java/android/provider/DocumentsProvider.java
@@ -461,6 +461,41 @@
}
/**
+ * Return recently modified documents under the requested root. This will
+ * only be called for roots that advertise
+ * {@link Root#FLAG_SUPPORTS_RECENTS}. The returned documents should be
+ * sorted by {@link Document#COLUMN_LAST_MODIFIED} in descending order of
+ * the most recently modified documents.
+ * <p>
+ * If this method is overriden by the concrete DocumentsProvider and
+ * QUERY_ARGS_LIMIT is specified with a nonnegative int under queryArgs, the
+ * result will be limited by that number and QUERY_ARG_LIMIT will be
+ * specified under EXTRA_HONORED_ARGS. Otherwise, a default 64 limit will
+ * be used and no QUERY_ARG* will be specified under EXTRA_HONORED_ARGS.
+ * <p>
+ * Recent documents do not support change notifications.
+ *
+ * @param projection list of {@link Document} columns to put into the
+ * cursor. If {@code null} all supported columns should be
+ * included.
+ * @param queryArgs the extra query arguments.
+ * @param signal used by the caller to signal if the request should be
+ * cancelled. May be null.
+ * @see DocumentsContract#EXTRA_LOADING
+ */
+ @SuppressWarnings("unused")
+ public Cursor queryRecentDocuments(
+ String rootId, String[] projection, @Nullable Bundle queryArgs,
+ @Nullable CancellationSignal signal)
+ throws FileNotFoundException {
+ Cursor c = queryRecentDocuments(rootId, projection);
+ Bundle extras = new Bundle();
+ c.setExtras(extras);
+ extras.putStringArray(ContentResolver.EXTRA_HONORED_ARGS, new String[0]);
+ return c;
+ }
+
+ /**
* Return metadata for the single requested document. You should avoid
* making network requests to keep this request fast.
*
@@ -774,7 +809,7 @@
* Implementation is provided by the parent class. Cannot be overriden.
*
* @see #queryRoots(String[])
- * @see #queryRecentDocuments(String, String[])
+ * @see #queryRecentDocuments(String, String[], Bundle, CancellationSignal)
* @see #queryDocument(String, String[])
* @see #queryChildDocuments(String, String[], String)
* @see #querySearchDocuments(String, String, String[])
@@ -787,7 +822,8 @@
case MATCH_ROOTS:
return queryRoots(projection);
case MATCH_RECENT:
- return queryRecentDocuments(getRootId(uri), projection);
+ return queryRecentDocuments(
+ getRootId(uri), projection, queryArgs, cancellationSignal);
case MATCH_SEARCH:
return querySearchDocuments(
getRootId(uri), getSearchDocumentsQuery(uri), projection);