summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-18 17:39:49 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-18 17:39:49 -0700
commit63ef384e15c40fdd4646157cb40b71e87b2062a6 (patch)
treef9a0ec1d167313be4c1cf2a1ac384214b21e943c /src/com/android
parentd311b453a4ea32dcc01e766da972c6837b7705ec (diff)
downloadandroid_packages_providers_DownloadProvider-63ef384e15c40fdd4646157cb40b71e87b2062a6.tar.gz
android_packages_providers_DownloadProvider-63ef384e15c40fdd4646157cb40b71e87b2062a6.tar.bz2
android_packages_providers_DownloadProvider-63ef384e15c40fdd4646157cb40b71e87b2062a6.zip
auto import from //branches/cupcake_rel/...@140373
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/providers/downloads/DownloadThread.java31
1 files changed, 24 insertions, 7 deletions
diff --git a/src/com/android/providers/downloads/DownloadThread.java b/src/com/android/providers/downloads/DownloadThread.java
index 923e36d1..9c748d5e 100644
--- a/src/com/android/providers/downloads/DownloadThread.java
+++ b/src/com/android/providers/downloads/DownloadThread.java
@@ -48,6 +48,7 @@ import java.io.InputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
+import java.util.Locale;
/**
* Runs an actual download
@@ -88,7 +89,7 @@ public class DownloadThread extends Thread {
String newUri = null;
boolean gotData = false;
String filename = null;
- String mimeType = mInfo.mimetype;
+ String mimeType = sanitizeMimeType(mInfo.mimetype);
FileOutputStream stream = null;
AndroidHttpClient client = null;
PowerManager.WakeLock wakeLock = null;
@@ -337,11 +338,7 @@ http_request_loop:
if (mimeType == null) {
header = response.getFirstHeader("Content-Type");
if (header != null) {
- mimeType = header.getValue();
- final int semicolonIndex = mimeType.indexOf(';');
- if (semicolonIndex != -1) {
- mimeType = mimeType.substring(0, semicolonIndex);
- }
+ mimeType = sanitizeMimeType(header.getValue());
}
}
header = response.getFirstHeader("ETag");
@@ -657,7 +654,7 @@ http_request_loop:
}
}
notifyDownloadCompleted(finalStatus, countRetry, retryAfter, redirectCount,
- gotData, filename, newUri, mimeType);
+ gotData, filename, newUri, mInfo.mimetype);
}
}
@@ -707,4 +704,24 @@ http_request_loop:
mInfo.sendIntentIfRequested(uri, mContext);
}
+ /**
+ * Clean up a mimeType string so it can be used to dispatch an intent to
+ * view a downloaded asset.
+ * @param mimeType either null or one or more mime types (semi colon separated).
+ * @return null if mimeType was null. Otherwise a string which represents a
+ * single mimetype in lowercase and with surrounding whitespaces trimmed.
+ */
+ private String sanitizeMimeType(String mimeType) {
+ try {
+ mimeType = mimeType.trim().toLowerCase(Locale.ENGLISH);
+
+ final int semicolonIndex = mimeType.indexOf(';');
+ if (semicolonIndex != -1) {
+ mimeType = mimeType.substring(0, semicolonIndex);
+ }
+ return mimeType;
+ } catch (NullPointerException npe) {
+ return null;
+ }
+ }
}