| Index: net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java
|
| diff --git a/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java b/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java
|
| index 90aa753186cdcfe49ed4bacb594a89db319c3398..8d953f22f988956fa3d7d7af3335557f51c19f59 100644
|
| --- a/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java
|
| +++ b/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java
|
| @@ -25,18 +25,25 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver
|
|
|
| /** Queries the ConnectivityManager for information about the current connection. */
|
| static class ConnectivityManagerDelegate {
|
| - private ConnectivityManager mConnectivityManager;
|
| + private final ConnectivityManager mConnectivityManager;
|
|
|
| ConnectivityManagerDelegate(Context context) {
|
| - if (context != null) {
|
| - mConnectivityManager = (ConnectivityManager)
|
| - context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
| - }
|
| + mConnectivityManager =
|
| + (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
| + }
|
| +
|
| + // For testing.
|
| + ConnectivityManagerDelegate() {
|
| + // All the methods below should be overridden.
|
| + mConnectivityManager = null;
|
| }
|
|
|
| boolean activeNetworkExists() {
|
| - return mConnectivityManager != null &&
|
| - mConnectivityManager.getActiveNetworkInfo() != null;
|
| + return mConnectivityManager.getActiveNetworkInfo() != null;
|
| + }
|
| +
|
| + boolean isConnected() {
|
| + return mConnectivityManager.getActiveNetworkInfo().isConnected();
|
| }
|
|
|
| int getNetworkType() {
|
| @@ -71,10 +78,10 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver
|
| mObserver = observer;
|
| mContext = context;
|
| mConnectivityManagerDelegate = new ConnectivityManagerDelegate(context);
|
| - mConnectionType = currentConnectionType(context);
|
| + mConnectionType = getCurrentConnectionType();
|
|
|
| if (ActivityStatus.getState() != ActivityStatus.PAUSED) {
|
| - registerReceiver();
|
| + registerReceiver();
|
| }
|
| ActivityStatus.registerStateListener(this);
|
| }
|
| @@ -110,9 +117,10 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver
|
| }
|
| }
|
|
|
| - private int currentConnectionType(Context context) {
|
| + public int getCurrentConnectionType() {
|
| // Track exactly what type of connection we have.
|
| - if (!mConnectivityManagerDelegate.activeNetworkExists()) {
|
| + if (!mConnectivityManagerDelegate.activeNetworkExists() ||
|
| + !mConnectivityManagerDelegate.isConnected()) {
|
| return NetworkChangeNotifier.CONNECTION_NONE;
|
| }
|
|
|
| @@ -155,11 +163,7 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver
|
| // BroadcastReceiver
|
| @Override
|
| public void onReceive(Context context, Intent intent) {
|
| - boolean noConnection =
|
| - intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
|
| - int newConnectionType = noConnection ?
|
| - NetworkChangeNotifier.CONNECTION_NONE : currentConnectionType(context);
|
| -
|
| + int newConnectionType = getCurrentConnectionType();
|
| if (newConnectionType != mConnectionType) {
|
| mConnectionType = newConnectionType;
|
| Log.d(TAG, "Network connectivity changed, type is: " + mConnectionType);
|
|
|