summaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
authorSteve Howard <showard@google.com>2010-07-15 19:59:40 -0700
committerSteve Howard <showard@google.com>2010-07-19 11:04:38 -0700
commit071bd7acb3185f4f1e807855605c5e6018e9742f (patch)
tree85e1d36689bb632b20b74faaac9596d660a7a46d /tests/src
parent1aa26989047495ff58d3e2598d3f9549465cbb65 (diff)
downloadandroid_packages_providers_DownloadProvider-071bd7acb3185f4f1e807855605c5e6018e9742f.tar.gz
android_packages_providers_DownloadProvider-071bd7acb3185f4f1e807855605c5e6018e9742f.tar.bz2
android_packages_providers_DownloadProvider-071bd7acb3185f4f1e807855605c5e6018e9742f.zip
Support for max download size that may go over mobile
This change introduces support for a maximum download size that may go over a mobile connection. Downloads above this limit will wait for a wifi connection. To accomplish this, I moved a lot of the logic for checking connectivity info into DownloadInfo itself. I then moved the code to call these checks from DownloadService, where it would call the checks before spawning a DownloadThread, into DownloadThread itself. This makes it simpler to check connectivity after we get Content-Length info. It also eliminates the risk of a race condition where connectivity changes between the check and the actual request execution. I realize this change reduces efficiency, because we now call into ConnectivityManager/TelephonyManager twice per DownloadThread, rather than once per DownloadService "tick". I feel that it's OK since its a small amount of computation running relatively infrequently. If we feel that it's a serious concern, and that the efficiency issues outweigh the race problem, I can go easily back to the old approach. I've left out the code to actually fetch the limit. I think this will come from system settings, but I want to double-check, so I'll put it in a separate change. Other changes: * simplify SystemFacade's interface to get connectivity info - rather than returning all connected types, just return the active type, since that should be all we care about * adding @LargeTest to PublicApiFunctionalTest Change-Id: Id1faa2c45bf2dade9fe779440721a1d42cbdfcd1
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/com/android/providers/downloads/FakeSystemFacade.java15
-rw-r--r--tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java19
2 files changed, 25 insertions, 9 deletions
diff --git a/tests/src/com/android/providers/downloads/FakeSystemFacade.java b/tests/src/com/android/providers/downloads/FakeSystemFacade.java
index c48f815d..4ff313ab 100644
--- a/tests/src/com/android/providers/downloads/FakeSystemFacade.java
+++ b/tests/src/com/android/providers/downloads/FakeSystemFacade.java
@@ -2,12 +2,11 @@ package com.android.providers.downloads;
import android.net.ConnectivityManager;
-import java.util.BitSet;
-
public class FakeSystemFacade implements SystemFacade {
long mTimeMillis = 0;
Integer mActiveNetworkType = ConnectivityManager.TYPE_WIFI;
boolean mIsRoaming = false;
+ Integer mMaxBytesOverMobile = null;
void incrementTimeMillis(long delta) {
mTimeMillis += delta;
@@ -17,15 +16,15 @@ public class FakeSystemFacade implements SystemFacade {
return mTimeMillis;
}
- public BitSet getConnectedNetworkTypes() {
- BitSet connectedTypes = new BitSet();
- if (mActiveNetworkType != null) {
- connectedTypes.set(mActiveNetworkType);
- }
- return connectedTypes;
+ public Integer getActiveNetworkType() {
+ return mActiveNetworkType;
}
public boolean isNetworkRoaming() {
return mIsRoaming;
}
+
+ public Integer getMaxBytesOverMobile() {
+ return mMaxBytesOverMobile ;
+ }
}
diff --git a/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java b/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java
index e9195609..a9810fc1 100644
--- a/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java
+++ b/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java
@@ -17,10 +17,11 @@
package com.android.providers.downloads;
import android.database.Cursor;
+import android.net.ConnectivityManager;
import android.net.DownloadManager;
import android.net.Uri;
import android.os.Environment;
-import android.util.Log;
+import android.test.suitebuilder.annotation.LargeTest;
import tests.http.RecordedRequest;
import java.io.File;
@@ -28,6 +29,7 @@ import java.io.FileInputStream;
import java.io.InputStream;
import java.net.MalformedURLException;
+@LargeTest
public class PublicApiFunctionalTest extends AbstractDownloadManagerFunctionalTest {
private static final String REQUEST_PATH = "/path";
@@ -293,6 +295,21 @@ public class PublicApiFunctionalTest extends AbstractDownloadManagerFunctionalTe
}
}
+ public void testSizeLimitOverMobile() throws Exception {
+ mSystemFacade.mMaxBytesOverMobile = FILE_CONTENT.length() - 1;
+
+ mSystemFacade.mActiveNetworkType = ConnectivityManager.TYPE_MOBILE;
+ enqueueResponse(HTTP_OK, FILE_CONTENT);
+ Download download = enqueueRequest(getRequest());
+ download.runUntilStatus(DownloadManager.STATUS_PAUSED);
+
+ mSystemFacade.mActiveNetworkType = ConnectivityManager.TYPE_WIFI;
+ // first response was read, but aborted after the DL manager processed the Content-Length
+ // header, so we need to enqueue a second one
+ enqueueResponse(HTTP_OK, FILE_CONTENT);
+ download.runUntilStatus(DownloadManager.STATUS_SUCCESSFUL);
+ }
+
private DownloadManager.Request getRequest() throws MalformedURLException {
return getRequest(getServerUri(REQUEST_PATH));
}