diff options
author | Steve Howard <showard@google.com> | 2010-07-15 15:57:31 -0700 |
---|---|---|
committer | Steve Howard <showard@google.com> | 2010-07-15 16:22:52 -0700 |
commit | af28400b74de05862b470412a5c92f68e99f59f8 (patch) | |
tree | 9bed7e915f12354803cba98c51d81cac82c94e9a /src/com/android/providers/downloads/RealSystemFacade.java | |
parent | 88ea0b39bb74c7f8204ba74d3e83bce440a59d88 (diff) | |
download | android_packages_providers_DownloadProvider-af28400b74de05862b470412a5c92f68e99f59f8.tar.gz android_packages_providers_DownloadProvider-af28400b74de05862b470412a5c92f68e99f59f8.tar.bz2 android_packages_providers_DownloadProvider-af28400b74de05862b470412a5c92f68e99f59f8.zip |
Introduce a seam to ConnectivityManager and TelephonyManager
This change abstracts access to ConnectivityManager and
TelephonyManager behind methods on SystemFacade, moving the code from
Helpers into RealSystemFacade and adding fake implementations to
FakeSystemFacade. This facilitates new connectivity tests.
Change-Id: Id6c6b861e1d4ca45b3c1572bfb8ae0aa26af756b
Diffstat (limited to 'src/com/android/providers/downloads/RealSystemFacade.java')
-rw-r--r-- | src/com/android/providers/downloads/RealSystemFacade.java | 58 |
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; + } } |