summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/downloads/RealSystemFacade.java
diff options
context:
space:
mode:
authorSteve Howard <showard@google.com>2010-07-19 10:58:58 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-07-19 10:58:58 -0700
commit1aa26989047495ff58d3e2598d3f9549465cbb65 (patch)
tree78826ba7ac8cd747f1fa695eb7d747f78e958920 /src/com/android/providers/downloads/RealSystemFacade.java
parentabb997df34680a8b2b733acbc2313991226c69d6 (diff)
parentaf28400b74de05862b470412a5c92f68e99f59f8 (diff)
downloadandroid_packages_providers_DownloadProvider-1aa26989047495ff58d3e2598d3f9549465cbb65.tar.gz
android_packages_providers_DownloadProvider-1aa26989047495ff58d3e2598d3f9549465cbb65.tar.bz2
android_packages_providers_DownloadProvider-1aa26989047495ff58d3e2598d3f9549465cbb65.zip
Merge "Introduce a seam to ConnectivityManager and TelephonyManager" into gingerbread
Diffstat (limited to 'src/com/android/providers/downloads/RealSystemFacade.java')
-rw-r--r--src/com/android/providers/downloads/RealSystemFacade.java58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/com/android/providers/downloads/RealSystemFacade.java b/src/com/android/providers/downloads/RealSystemFacade.java
index 88f10d8c..41ca6b6e 100644
--- a/src/com/android/providers/downloads/RealSystemFacade.java
+++ b/src/com/android/providers/downloads/RealSystemFacade.java
@@ -1,7 +1,65 @@
package com.android.providers.downloads;
+import android.content.Context;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+import android.telephony.TelephonyManager;
+import android.util.Log;
+
+import java.util.BitSet;
+
class RealSystemFacade implements SystemFacade {
+ private Context mContext;
+
+ public RealSystemFacade(Context context) {
+ mContext = context;
+ }
+
public long currentTimeMillis() {
return System.currentTimeMillis();
}
+
+ public BitSet getConnectedNetworkTypes() {
+ BitSet connectedTypes = new BitSet();
+
+ ConnectivityManager connectivity =
+ (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
+ if (connectivity == null) {
+ Log.w(Constants.TAG, "couldn't get connectivity manager");
+ return connectedTypes;
+ }
+
+ NetworkInfo[] infos = connectivity.getAllNetworkInfo();
+ if (infos != null) {
+ for (NetworkInfo info : infos) {
+ if (info.getState() == NetworkInfo.State.CONNECTED) {
+ connectedTypes.set(info.getType());
+ }
+ }
+ }
+
+ if (Constants.LOGVV) {
+ boolean isConnected = !connectedTypes.isEmpty();
+ Log.v(Constants.TAG, "network is " + (isConnected ? "" : "not ") + "available");
+ }
+ return connectedTypes;
+ }
+
+ public boolean isNetworkRoaming() {
+ ConnectivityManager connectivity =
+ (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
+ if (connectivity == null) {
+ Log.w(Constants.TAG, "couldn't get connectivity manager");
+ return false;
+ }
+
+ 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);
+ }
+ return isMobile && isRoaming;
+ }
}