summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/downloads/RealSystemFacade.java
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 /src/com/android/providers/downloads/RealSystemFacade.java
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 'src/com/android/providers/downloads/RealSystemFacade.java')
-rw-r--r--src/com/android/providers/downloads/RealSystemFacade.java37
1 files changed, 15 insertions, 22 deletions
diff --git a/src/com/android/providers/downloads/RealSystemFacade.java b/src/com/android/providers/downloads/RealSystemFacade.java
index 41ca6b6e..89cf3b1d 100644
--- a/src/com/android/providers/downloads/RealSystemFacade.java
+++ b/src/com/android/providers/downloads/RealSystemFacade.java
@@ -6,8 +6,6 @@ import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
import android.util.Log;
-import java.util.BitSet;
-
class RealSystemFacade implements SystemFacade {
private Context mContext;
@@ -19,30 +17,22 @@ class RealSystemFacade implements SystemFacade {
return System.currentTimeMillis();
}
- public BitSet getConnectedNetworkTypes() {
- BitSet connectedTypes = new BitSet();
-
+ public Integer getActiveNetworkType() {
ConnectivityManager connectivity =
(ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
Log.w(Constants.TAG, "couldn't get connectivity manager");
- return connectedTypes;
+ return null;
}
- NetworkInfo[] infos = connectivity.getAllNetworkInfo();
- if (infos != null) {
- for (NetworkInfo info : infos) {
- if (info.getState() == NetworkInfo.State.CONNECTED) {
- connectedTypes.set(info.getType());
- }
+ NetworkInfo activeInfo = connectivity.getActiveNetworkInfo();
+ if (activeInfo == null) {
+ if (Constants.LOGVV) {
+ Log.v(Constants.TAG, "network is not available");
}
+ return null;
}
-
- if (Constants.LOGVV) {
- boolean isConnected = !connectedTypes.isEmpty();
- Log.v(Constants.TAG, "network is " + (isConnected ? "" : "not ") + "available");
- }
- return connectedTypes;
+ return activeInfo.getType();
}
public boolean isNetworkRoaming() {
@@ -56,10 +46,13 @@ class RealSystemFacade implements SystemFacade {
NetworkInfo info = connectivity.getActiveNetworkInfo();
boolean isMobile = (info != null && info.getType() == ConnectivityManager.TYPE_MOBILE);
boolean isRoaming = isMobile && TelephonyManager.getDefault().isNetworkRoaming();
- if (Constants.LOGVV) {
- Log.v(Constants.TAG, "network is mobile: " + isMobile);
- Log.v(Constants.TAG, "network is roaming: " + isRoaming);
+ if (Constants.LOGVV && isRoaming) {
+ Log.v(Constants.TAG, "network is roaming");
}
- return isMobile && isRoaming;
+ return isRoaming;
+ }
+
+ public Integer getMaxBytesOverMobile() {
+ return null;
}
}