summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/current.txt7
-rw-r--r--core/java/android/provider/DocumentsContract.java74
2 files changed, 76 insertions, 5 deletions
diff --git a/api/current.txt b/api/current.txt
index 3943695..c0cb9f0 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -20607,22 +20607,27 @@ package android.provider {
method public static android.net.Uri buildRootsUri(java.lang.String);
method public static android.net.Uri buildSearchUri(java.lang.String, java.lang.String, java.lang.String, java.lang.String);
method public static android.net.Uri buildSearchUri(android.net.Uri, java.lang.String);
+ method public static android.net.Uri createDocument(android.content.ContentResolver, android.net.Uri, java.lang.String, java.lang.String);
method public static java.lang.String getDocId(android.net.Uri);
method public static android.net.Uri[] getOpenDocuments(android.content.Context);
method public static java.lang.String getRootId(android.net.Uri);
method public static java.lang.String getSearchQuery(android.net.Uri);
method public static android.graphics.Bitmap getThumbnail(android.content.ContentResolver, android.net.Uri, android.graphics.Point);
+ method public static boolean isLocalOnly(android.net.Uri);
+ method public static void notifyRootsChanged(android.content.Context, java.lang.String);
method public static boolean renameDocument(android.content.ContentResolver, android.net.Uri, java.lang.String);
+ method public static android.net.Uri setLocalOnly(android.net.Uri);
field public static final java.lang.String EXTRA_HAS_MORE = "has_more";
field public static final java.lang.String EXTRA_REQUEST_MORE = "request_more";
field public static final java.lang.String EXTRA_THUMBNAIL_SIZE = "thumbnail_size";
+ field public static final int FLAG_PREFERS_GRID = 64; // 0x40
field public static final int FLAG_SUPPORTS_CREATE = 1; // 0x1
field public static final int FLAG_SUPPORTS_DELETE = 4; // 0x4
field public static final int FLAG_SUPPORTS_RENAME = 2; // 0x2
field public static final int FLAG_SUPPORTS_SEARCH = 16; // 0x10
field public static final int FLAG_SUPPORTS_THUMBNAIL = 8; // 0x8
+ field public static final int FLAG_SUPPORTS_WRITE = 32; // 0x20
field public static final java.lang.String MIME_TYPE_DIRECTORY = "vnd.android.cursor.dir/doc";
- field public static final java.lang.String PARAM_QUERY = "query";
field public static final java.lang.String ROOT_DOC_ID = "0";
field public static final int ROOT_TYPE_DEVICE = 3; // 0x3
field public static final int ROOT_TYPE_DEVICE_ADVANCED = 4; // 0x4
diff --git a/core/java/android/provider/DocumentsContract.java b/core/java/android/provider/DocumentsContract.java
index 53f5d58..0a16d73 100644
--- a/core/java/android/provider/DocumentsContract.java
+++ b/core/java/android/provider/DocumentsContract.java
@@ -57,13 +57,16 @@ public final class DocumentsContract {
* MIME type of a document which is a directory that may contain additional
* documents.
*
- * @see #buildContentsUri(Uri)
+ * @see #buildContentsUri(String, String, String)
*/
public static final String MIME_TYPE_DIRECTORY = "vnd.android.cursor.dir/doc";
/** {@hide} */
public static final String META_DATA_DOCUMENT_PROVIDER = "android.content.DOCUMENT_PROVIDER";
+ /** {@hide} */
+ public static final String ACTION_ROOTS_CHANGED = "android.provider.action.ROOTS_CHANGED";
+
/**
* {@link DocumentColumns#DOC_ID} value representing the root directory of a
* storage root.
@@ -75,7 +78,7 @@ public final class DocumentsContract {
* new files within it.
*
* @see DocumentColumns#FLAGS
- * @see #buildContentsUri(Uri)
+ * @see #createDocument(ContentResolver, Uri, String, String)
*/
public static final int FLAG_SUPPORTS_CREATE = 1;
@@ -109,7 +112,21 @@ public final class DocumentsContract {
*/
public static final int FLAG_SUPPORTS_SEARCH = 1 << 4;
- // TODO: flag indicating that document is writable?
+ /**
+ * Flag indicating that a document is writable.
+ *
+ * @see DocumentColumns#FLAGS
+ */
+ public static final int FLAG_SUPPORTS_WRITE = 1 << 5;
+
+ /**
+ * Flag indicating that a document is a directory that prefers its contents
+ * be shown in a larger format grid. Usually suitable when a directory
+ * contains mostly pictures.
+ *
+ * @see DocumentColumns#FLAGS
+ */
+ public static final int FLAG_PREFERS_GRID = 1 << 6;
/**
* Optimal dimensions for a document thumbnail request, stored as a
@@ -144,7 +161,8 @@ public final class DocumentsContract {
private static final String PATH_CONTENTS = "contents";
private static final String PATH_SEARCH = "search";
- public static final String PARAM_QUERY = "query";
+ private static final String PARAM_QUERY = "query";
+ private static final String PARAM_LOCAL_ONLY = "localOnly";
/**
* Build URI representing the roots in a storage backend.
@@ -228,11 +246,32 @@ public final class DocumentsContract {
return paths.get(3);
}
+ /**
+ * Return requested search query from the given Uri.
+ */
public static String getSearchQuery(Uri documentUri) {
return documentUri.getQueryParameter(PARAM_QUERY);
}
/**
+ * Mark the given Uri to indicate that only locally-available contents
+ * should be returned.
+ */
+ public static Uri setLocalOnly(Uri documentUri) {
+ return documentUri.buildUpon()
+ .appendQueryParameter(PARAM_LOCAL_ONLY, String.valueOf(true)).build();
+ }
+
+ /**
+ * Return if the given Uri is requesting that only locally-available content
+ * be returned. That is, no network connections should be initiated to
+ * provide the metadata or content.
+ */
+ public static boolean isLocalOnly(Uri documentUri) {
+ return documentUri.getBooleanQueryParameter(PARAM_LOCAL_ONLY, false);
+ }
+
+ /**
* These are standard columns for document URIs. Storage backend providers
* <em>must</em> support at least these columns when queried.
*
@@ -423,6 +462,23 @@ public final class DocumentsContract {
}
/**
+ * Create a new document under a specific parent document with the given
+ * display name and MIME type.
+ *
+ * @param parentDocumentUri document with {@link #FLAG_SUPPORTS_CREATE}
+ * @param displayName name for new document
+ * @param mimeType MIME type for new document, which cannot be changed
+ * @return newly created document Uri, or {@code null} if failed
+ */
+ public static Uri createDocument(
+ ContentResolver resolver, Uri parentDocumentUri, String displayName, String mimeType) {
+ final ContentValues values = new ContentValues();
+ values.put(DocumentColumns.MIME_TYPE, mimeType);
+ values.put(DocumentColumns.DISPLAY_NAME, displayName);
+ return resolver.insert(parentDocumentUri, values);
+ }
+
+ /**
* Rename the document at the given URI. Given document must have
* {@link #FLAG_SUPPORTS_RENAME} set.
*
@@ -434,4 +490,14 @@ public final class DocumentsContract {
values.put(DocumentColumns.DISPLAY_NAME, displayName);
return (resolver.update(documentUri, values, null, null) == 1);
}
+
+ /**
+ * Notify the system that roots have changed for the given storage provider.
+ * This signal is used to invalidate internal caches.
+ */
+ public static void notifyRootsChanged(Context context, String authority) {
+ final Intent intent = new Intent(ACTION_ROOTS_CHANGED);
+ intent.setData(buildRootsUri(authority));
+ context.sendBroadcast(intent);
+ }
}