From b0e0dec8456b677251e6f97c3e1bec3622f4dec7 Mon Sep 17 00:00:00 2001 From: Ben Lin Date: Wed, 27 Apr 2016 11:45:01 -0700 Subject: Add ability to rename a downloaded file. Bug: 28359663 Change-Id: Id74ab041717f553bbd81ab2f69b1b8fa0d4d230d --- .../downloads/DownloadStorageProvider.java | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/com/android/providers/downloads') diff --git a/src/com/android/providers/downloads/DownloadStorageProvider.java b/src/com/android/providers/downloads/DownloadStorageProvider.java index bb782155..e0bb7cd1 100644 --- a/src/com/android/providers/downloads/DownloadStorageProvider.java +++ b/src/com/android/providers/downloads/DownloadStorageProvider.java @@ -154,6 +154,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)) { @@ -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); -- cgit v1.2.3