Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Unified Diff: net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java

Issue 11628008: Provide NetworkChangeNotifierAndroid with the actual initial connection type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Ryan's comments + fix Java comment Created 7 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);

Powered by Google App Engine
This is Rietveld 408576698