summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Howard <showard@google.com>2010-07-27 17:29:53 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2010-07-27 17:29:53 -0700
commit19161bd7add08748c1559f40452d26ded6045b4d (patch)
treecebcacef651fc794c68f729a06171d82bd2a7cde
parent21bb2b72765a0e7996b8631dea9a9a4300462d2e (diff)
parent7a8bf08fe936a1fdb0408dea1ec2f39b83acc5d7 (diff)
downloadandroid_packages_providers_DownloadProvider-19161bd7add08748c1559f40452d26ded6045b4d.tar.gz
android_packages_providers_DownloadProvider-19161bd7add08748c1559f40452d26ded6045b4d.tar.bz2
android_packages_providers_DownloadProvider-19161bd7add08748c1559f40452d26ded6045b4d.zip
am 7a8bf08f: am f6b4c24b: Fix bug with closing output stream for external downloads.
Merge commit '7a8bf08fe936a1fdb0408dea1ec2f39b83acc5d7' * commit '7a8bf08fe936a1fdb0408dea1ec2f39b83acc5d7': Fix bug with closing output stream for external downloads.
-rw-r--r--src/com/android/providers/downloads/DownloadThread.java1
-rw-r--r--src/com/android/providers/downloads/Helpers.java7
-rw-r--r--tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java16
3 files changed, 19 insertions, 5 deletions
diff --git a/src/com/android/providers/downloads/DownloadThread.java b/src/com/android/providers/downloads/DownloadThread.java
index 431a19ee..d79e026d 100644
--- a/src/com/android/providers/downloads/DownloadThread.java
+++ b/src/com/android/providers/downloads/DownloadThread.java
@@ -325,6 +325,7 @@ public class DownloadThread extends Thread {
// close the file
if (state.mStream != null) {
state.mStream.close();
+ state.mStream = null;
}
} catch (IOException ex) {
if (Constants.LOGV) {
diff --git a/src/com/android/providers/downloads/Helpers.java b/src/com/android/providers/downloads/Helpers.java
index 58ab578a..f2988954 100644
--- a/src/com/android/providers/downloads/Helpers.java
+++ b/src/com/android/providers/downloads/Helpers.java
@@ -513,10 +513,9 @@ public class Helpers {
* Checks whether the filename looks legitimate
*/
public static boolean isFilenameValid(String filename) {
- File dir = new File(filename).getParentFile();
- return dir.equals(Environment.getDownloadCacheDirectory())
- || dir.equals(new File(Environment.getExternalStorageDirectory()
- + Constants.DEFAULT_DL_SUBDIR));
+ filename = filename.replaceFirst("/+", "/"); // normalize leading slashes
+ return filename.startsWith(Environment.getDownloadCacheDirectory().toString())
+ || filename.startsWith(Environment.getExternalStorageDirectory().toString());
}
/**
diff --git a/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java b/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java
index ba3059b6..b02844fa 100644
--- a/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java
+++ b/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java
@@ -148,6 +148,16 @@ public class PublicApiFunctionalTest extends AbstractPublicApiTest {
assertTrue("No ETag header: " + headers, headers.contains("If-Match: " + ETAG));
}
+ public void testInterruptedExternalDownload() throws Exception {
+ enqueueInterruptedDownloadResponses(5);
+ Uri destination = getExternalUri();
+ Download download = enqueueRequest(getRequest().setDestinationUri(destination));
+ download.runUntilStatus(DownloadManager.STATUS_PAUSED);
+ mSystemFacade.incrementTimeMillis(RETRY_DELAY_MILLIS);
+ download.runUntilStatus(DownloadManager.STATUS_SUCCESSFUL);
+ assertEquals(FILE_CONTENT, download.getContents());
+ }
+
private void enqueueInterruptedDownloadResponses(int initialLength) {
int totalLength = FILE_CONTENT.length();
// the first response has normal headers but unexpectedly closes after initialLength bytes
@@ -225,7 +235,7 @@ public class PublicApiFunctionalTest extends AbstractPublicApiTest {
public void testDestination() throws Exception {
enqueueResponse(HTTP_OK, FILE_CONTENT);
- Uri destination = Uri.fromFile(mTestDirectory).buildUpon().appendPath("testfile").build();
+ Uri destination = getExternalUri();
Download download = enqueueRequest(getRequest().setDestinationUri(destination));
download.runUntilStatus(DownloadManager.STATUS_SUCCESSFUL);
@@ -240,6 +250,10 @@ public class PublicApiFunctionalTest extends AbstractPublicApiTest {
}
}
+ private Uri getExternalUri() {
+ return Uri.fromFile(mTestDirectory).buildUpon().appendPath("testfile").build();
+ }
+
public void testRequestHeaders() throws Exception {
enqueueEmptyResponse(HTTP_OK);
Download download = enqueueRequest(getRequest().setRequestHeader("Header1", "value1")