diff options
author | Ben Kwa <kenobi@google.com> | 2015-04-22 15:50:14 -0700 |
---|---|---|
committer | Ben Kwa <kenobi@google.com> | 2015-04-22 15:50:14 -0700 |
commit | a09378b08f12c6c331f5eac65120f406e11dcaad (patch) | |
tree | 546ae3c1a27574be4f0525d25cf4e65b30e0e3e9 /src | |
parent | 98cb05472fb27f77d0fc2233e39c80278652276b (diff) | |
download | android_packages_providers_DownloadProvider-a09378b08f12c6c331f5eac65120f406e11dcaad.tar.gz android_packages_providers_DownloadProvider-a09378b08f12c6c331f5eac65120f406e11dcaad.tar.bz2 android_packages_providers_DownloadProvider-a09378b08f12c6c331f5eac65120f406e11dcaad.zip |
Sanitize display names, keep extensions intact.
Use the newly factored FileUtils sanitize the requested display names to
be valid FAT filenames, and also allow any extension that maps to the
requested MIME type.
BUG=20157955
Change-Id: Ic37863a3362a941d81632bd4a7562dae40053652
Diffstat (limited to 'src')
-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()) { |