summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/android/providers/downloads/Constants.java3
-rw-r--r--src/com/android/providers/downloads/DownloadService.java8
-rw-r--r--src/com/android/providers/downloads/Helpers.java92
3 files changed, 60 insertions, 43 deletions
diff --git a/src/com/android/providers/downloads/Constants.java b/src/com/android/providers/downloads/Constants.java
index 5cf13531..7cfe6bcf 100644
--- a/src/com/android/providers/downloads/Constants.java
+++ b/src/com/android/providers/downloads/Constants.java
@@ -88,6 +88,9 @@ public class Constants {
/** A magic filename that is allowed to exist within the system cache */
public static final String RECOVERY_DIRECTORY = "recovery";
+ /** A magic filename that is allowed to exist within the system cache */
+ public static final String DEX_CACHE_DIRECTORY = "dalvik-cache";
+
/** The default user agent used for downloads */
public static final String DEFAULT_USER_AGENT = "AndroidDownloadManager";
diff --git a/src/com/android/providers/downloads/DownloadService.java b/src/com/android/providers/downloads/DownloadService.java
index 95d07d6f..76a317d1 100644
--- a/src/com/android/providers/downloads/DownloadService.java
+++ b/src/com/android/providers/downloads/DownloadService.java
@@ -430,10 +430,10 @@ public class DownloadService extends Service {
}
HashSet<String> fileSet = new HashSet<String>();
for (int i = 0; i < files.length; i++) {
- if (files[i].getName().equals(Constants.KNOWN_SPURIOUS_FILENAME)) {
- continue;
- }
- if (files[i].getName().equalsIgnoreCase(Constants.RECOVERY_DIRECTORY)) {
+ String filename = files[i].getName();
+ if (Constants.KNOWN_SPURIOUS_FILENAME.equals(filename) ||
+ Constants.RECOVERY_DIRECTORY.equalsIgnoreCase(filename) ||
+ Constants.DEX_CACHE_DIRECTORY.equalsIgnoreCase(filename)) {
continue;
}
fileSet.add(files[i].getPath());
diff --git a/src/com/android/providers/downloads/Helpers.java b/src/com/android/providers/downloads/Helpers.java
index 855cba28..2b88512e 100644
--- a/src/com/android/providers/downloads/Helpers.java
+++ b/src/com/android/providers/downloads/Helpers.java
@@ -173,43 +173,7 @@ public class Helpers {
private static void checkCanHandleDownload(Context context, String mimeType, int destination,
boolean isPublicApi) throws GenerateSaveFileError {
- if (isPublicApi) {
- return;
- }
-
- if (destination == Downloads.Impl.DESTINATION_EXTERNAL
- || destination == Downloads.Impl.DESTINATION_CACHE_PARTITION_PURGEABLE) {
- if (mimeType == null) {
- throw new GenerateSaveFileError(Downloads.Impl.STATUS_NOT_ACCEPTABLE,
- "external download with no mime type not allowed");
- }
- if (!DrmRawContent.DRM_MIMETYPE_MESSAGE_STRING.equalsIgnoreCase(mimeType)) {
- // Check to see if we are allowed to download this file. Only files
- // that can be handled by the platform can be downloaded.
- // special case DRM files, which we should always allow downloading.
- Intent intent = new Intent(Intent.ACTION_VIEW);
-
- // We can provide data as either content: or file: URIs,
- // so allow both. (I think it would be nice if we just did
- // everything as content: URIs)
- // Actually, right now the download manager's UId restrictions
- // prevent use from using content: so it's got to be file: or
- // nothing
-
- PackageManager pm = context.getPackageManager();
- intent.setDataAndType(Uri.fromParts("file", "", null), mimeType);
- ResolveInfo ri = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
- //Log.i(Constants.TAG, "*** FILENAME QUERY " + intent + ": " + list);
-
- if (ri == null) {
- if (Constants.LOGV) {
- Log.v(Constants.TAG, "no handler found for type " + mimeType);
- }
- throw new GenerateSaveFileError(Downloads.Impl.STATUS_NOT_ACCEPTABLE,
- "no handler found for this download type");
- }
- }
- }
+ return;
}
private static File locateDestinationDirectory(Context context, String mimeType,
@@ -360,8 +324,9 @@ public class Helpers {
filename = Constants.DEFAULT_DL_FILENAME;
}
- filename = filename.replaceAll("[^a-zA-Z0-9\\.\\-_]+", "_");
-
+ // The VFAT file system is assumed as target for downloads.
+ // Replace invalid characters according to the specifications of VFAT.
+ filename = replaceInvalidVfatCharacters(filename);
return filename;
}
@@ -815,4 +780,53 @@ public class Helpers {
resolver.delete(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, Downloads.Impl._ID + " = ? ",
new String[]{String.valueOf(id)});
}
+
+ /*
+ * Replace invalid filename characters according to
+ * specifications of the VFAT.
+ * @note Package-private due to testing.
+ */
+ private static String replaceInvalidVfatCharacters(String filename) {
+ final char START_CTRLCODE = 0x00;
+ final char END_CTRLCODE = 0x1f;
+ final char QUOTEDBL = 0x22;
+ final char ASTERISK = 0x2A;
+ final char SLASH = 0x2F;
+ final char COLON = 0x3A;
+ final char LESS = 0x3C;
+ final char GREATER = 0x3E;
+ final char QUESTION = 0x3F;
+ final char BACKSLASH = 0x5C;
+ final char BAR = 0x7C;
+ final char DEL = 0x7F;
+ final char UNDERSCORE = 0x5F;
+
+ StringBuffer sb = new StringBuffer();
+ char ch;
+ boolean isRepetition = false;
+ for (int i = 0; i < filename.length(); i++) {
+ ch = filename.charAt(i);
+ if ((START_CTRLCODE <= ch &&
+ ch <= END_CTRLCODE) ||
+ ch == QUOTEDBL ||
+ ch == ASTERISK ||
+ ch == SLASH ||
+ ch == COLON ||
+ ch == LESS ||
+ ch == GREATER ||
+ ch == QUESTION ||
+ ch == BACKSLASH ||
+ ch == BAR ||
+ ch == DEL){
+ if (!isRepetition) {
+ sb.append(UNDERSCORE);
+ isRepetition = true;
+ }
+ } else {
+ sb.append(ch);
+ isRepetition = false;
+ }
+ }
+ return sb.toString();
+ }
}