Add ability to rename a downloaded file.
Ben Lin [Wed, 27 Apr 2016 18:45:01 +0000 (11:45 -0700)]
Bug: 28359663
Change-Id: Id74ab041717f553bbd81ab2f69b1b8fa0d4d230d

src/com/android/providers/downloads/DownloadStorageProvider.java

index bb78215..e0bb7cd 100644 (file)
@@ -155,6 +155,25 @@ public class DownloadStorageProvider extends DocumentsProvider {
     }
 
     @Override
+    public String renameDocument(String documentId, String displayName)
+            throws FileNotFoundException {
+        displayName = FileUtils.buildValidFatFilename(displayName);
+
+        final long token = Binder.clearCallingIdentity();
+        try {
+            final long id = Long.parseLong(documentId);
+
+            if (!mDm.rename(getContext(), id, displayName)) {
+                throw new IllegalStateException(
+                        "Failed to rename to " + displayName + " in downloadsManager");
+            }
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+        return null;
+    }
+
+    @Override
     public Cursor queryDocument(String docId, String[] projection) throws FileNotFoundException {
         if (mArchiveHelper.isArchivedDocument(docId)) {
             return mArchiveHelper.queryDocument(docId, projection);
@@ -331,7 +350,7 @@ public class DownloadStorageProvider extends DocumentsProvider {
                 cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_STATUS));
         switch (status) {
             case DownloadManager.STATUS_SUCCESSFUL:
-                extraFlags = 0;  // only successful is non-partial
+                extraFlags = Document.FLAG_SUPPORTS_RENAME;  // only successful is non-partial
                 break;
             case DownloadManager.STATUS_PAUSED:
                 summary = getContext().getString(R.string.download_queued);