summaryrefslogtreecommitdiffstats
path: root/packages/ExternalStorageProvider
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2014-05-21 22:22:03 -0700
committerJeff Sharkey <jsharkey@android.com>2014-05-21 22:24:45 -0700
commitb7e1255d5c8d9e4fa8dd389afb9f5aab35434df3 (patch)
tree9dc25a4e712ca3bcef16a555484d2e17ae37bb00 /packages/ExternalStorageProvider
parent05ad48206a082057e17723d32493c153faa6881e (diff)
downloadframeworks_base-b7e1255d5c8d9e4fa8dd389afb9f5aab35434df3.zip
frameworks_base-b7e1255d5c8d9e4fa8dd389afb9f5aab35434df3.tar.gz
frameworks_base-b7e1255d5c8d9e4fa8dd389afb9f5aab35434df3.tar.bz2
Support for renaming documents.
DocumentsProviders can mark documents as supporting rename, and they have the opportunity to change the DOCUMENT_ID as a side effect of the rename. This supports providers that embed the display name into DOCUMENT_ID. Issues a URI permission grant to the new document, if any. Adds renaming support to platform ExternalStorageProvider. Also adds directory deletion support. Bug: 12350110 Change-Id: Ica4b1ae6769ee994f70f6b6b2402213eebd064e0
Diffstat (limited to 'packages/ExternalStorageProvider')
-rw-r--r--packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java26
1 files changed, 25 insertions, 1 deletions
diff --git a/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java b/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java
index 16fc3e5..d388ab7 100644
--- a/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java
+++ b/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java
@@ -35,6 +35,7 @@ import android.provider.DocumentsContract;
import android.provider.DocumentsContract.Document;
import android.provider.DocumentsContract.Root;
import android.provider.DocumentsProvider;
+import android.text.TextUtils;
import android.util.Log;
import android.webkit.MimeTypeMap;
@@ -239,9 +240,12 @@ public class ExternalStorageProvider extends DocumentsProvider {
if (file.canWrite()) {
if (file.isDirectory()) {
flags |= Document.FLAG_DIR_SUPPORTS_CREATE;
+ flags |= Document.FLAG_SUPPORTS_DELETE;
+ flags |= Document.FLAG_SUPPORTS_RENAME;
} else {
flags |= Document.FLAG_SUPPORTS_WRITE;
flags |= Document.FLAG_SUPPORTS_DELETE;
+ flags |= Document.FLAG_SUPPORTS_RENAME;
}
}
@@ -332,9 +336,29 @@ public class ExternalStorageProvider extends DocumentsProvider {
}
@Override
+ public String renameDocument(String docId, String displayName) throws FileNotFoundException {
+ final File before = getFileForDocId(docId);
+ final File after = new File(before.getParentFile(), displayName);
+ if (after.exists()) {
+ throw new IllegalStateException("Already exists " + after);
+ }
+ if (!before.renameTo(after)) {
+ throw new IllegalStateException("Failed to rename to " + after);
+ }
+ final String afterDocId = getDocIdForFile(after);
+ if (!TextUtils.equals(docId, afterDocId)) {
+ return afterDocId;
+ } else {
+ return null;
+ }
+ }
+
+ @Override
public void deleteDocument(String docId) throws FileNotFoundException {
- // TODO: extend to delete directories
final File file = getFileForDocId(docId);
+ if (file.isDirectory()) {
+ FileUtils.deleteContents(file);
+ }
if (!file.delete()) {
throw new IllegalStateException("Failed to delete " + file);
}