summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/index.html1
-rw-r--r--src/com/android/providers/downloads/DownloadThread.java8
-rw-r--r--src/com/android/providers/downloads/Helpers.java54
3 files changed, 60 insertions, 3 deletions
diff --git a/docs/index.html b/docs/index.html
index 0004b729..9bd6a51f 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -1,5 +1,4 @@
<html>
-
<head>
<title>Download Provider</title>
</head>
diff --git a/src/com/android/providers/downloads/DownloadThread.java b/src/com/android/providers/downloads/DownloadThread.java
index 7c102481..0da950ba 100644
--- a/src/com/android/providers/downloads/DownloadThread.java
+++ b/src/com/android/providers/downloads/DownloadThread.java
@@ -16,11 +16,15 @@
package com.android.providers.downloads;
+import org.apache.http.conn.params.ConnRouteParams;
+
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.drm.mobile1.DrmRawContent;
import android.net.http.AndroidHttpClient;
+import android.net.Proxy;
+import android.net.Uri;
import android.os.FileUtils;
import android.os.PowerManager;
import android.os.Process;
@@ -162,6 +166,10 @@ public class DownloadThread extends Thread {
boolean finished = false;
while(!finished) {
Log.i(Constants.TAG, "Initiating request for download " + mInfo.mId);
+ // Set or unset proxy, which may have changed since last GET request.
+ // setDefaultProxy() supports null as proxy parameter.
+ ConnRouteParams.setDefaultProxy(client.getParams(),
+ Proxy.getPreferredHttpHost(mContext, state.mRequestUri));
HttpGet request = new HttpGet(state.mRequestUri);
try {
executeDownload(state, client, request);
diff --git a/src/com/android/providers/downloads/Helpers.java b/src/com/android/providers/downloads/Helpers.java
index 855cba28..a20a7592 100644
--- a/src/com/android/providers/downloads/Helpers.java
+++ b/src/com/android/providers/downloads/Helpers.java
@@ -360,8 +360,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;
}
@@ -802,6 +803,55 @@ public class Helpers {
}
/**
+ * 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();
+ }
+
+ /*
* Delete the given file from device
* and delete its row from the downloads database.
*/