diff options
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/providers/downloads/DownloadStorageProvider.java | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/com/android/providers/downloads/DownloadStorageProvider.java b/src/com/android/providers/downloads/DownloadStorageProvider.java index 80d78551..1b5dc844 100644 --- a/src/com/android/providers/downloads/DownloadStorageProvider.java +++ b/src/com/android/providers/downloads/DownloadStorageProvider.java @@ -29,6 +29,7 @@ import android.net.Uri; import android.os.Binder; import android.os.CancellationSignal; import android.os.Environment; +import android.os.FileUtils; import android.os.ParcelFileDescriptor; import android.provider.DocumentsContract; import android.provider.DocumentsContract.Document; @@ -105,6 +106,8 @@ public class DownloadStorageProvider extends DocumentsProvider { @Override public String createDocument(String docId, String mimeType, String displayName) throws FileNotFoundException { + displayName = FileUtils.buildValidFatFilename(displayName); + if (Document.MIME_TYPE_DIR.equals(mimeType)) { throw new FileNotFoundException("Directory creation not supported"); } @@ -116,14 +119,7 @@ public class DownloadStorageProvider extends DocumentsProvider { // Delegate to real provider final long token = Binder.clearCallingIdentity(); try { - displayName = removeExtension(mimeType, displayName); - File file = new File(parent, addExtension(mimeType, displayName)); - - // If conflicting file, try adding counter suffix - int n = 0; - while (file.exists() && n++ < 32) { - file = new File(parent, addExtension(mimeType, displayName + " (" + n + ")")); - } + final File file = FileUtils.buildUniqueFile(parent, mimeType, displayName); try { if (!file.createNewFile()) { |