Index: net/android/java/src/org/chromium/net/NetworkChangeNotifier.java |
diff --git a/net/android/java/src/org/chromium/net/NetworkChangeNotifier.java b/net/android/java/src/org/chromium/net/NetworkChangeNotifier.java |
index 1008b7e41e89976f2054e7d853e3819a9b81c0e1..928af78e55e7a201e7fedc8b752fefee40a6b4a8 100644 |
--- a/net/android/java/src/org/chromium/net/NetworkChangeNotifier.java |
+++ b/net/android/java/src/org/chromium/net/NetworkChangeNotifier.java |
@@ -33,21 +33,12 @@ public class NetworkChangeNotifier { |
public void onConnectionTypeChanged(int connectionType); |
} |
- // These constants must always match the ones in network_change_notifier.h. |
- public static final int CONNECTION_UNKNOWN = 0; |
- public static final int CONNECTION_ETHERNET = 1; |
- public static final int CONNECTION_WIFI = 2; |
- public static final int CONNECTION_2G = 3; |
- public static final int CONNECTION_3G = 4; |
- public static final int CONNECTION_4G = 5; |
- public static final int CONNECTION_NONE = 6; |
- public static final int CONNECTION_BLUETOOTH = 7; |
- |
private final Context mContext; |
private final ArrayList<Long> mNativeChangeNotifiers; |
private final ObserverList<ConnectionTypeObserver> mConnectionTypeObservers; |
private NetworkChangeNotifierAutoDetect mAutoDetector; |
- private int mCurrentConnectionType = CONNECTION_UNKNOWN; |
+ private int mCurrentConnectionType = ConnectionType.CONNECTION_UNKNOWN; |
+ private double mCurrentMaxBandwidth = Double.POSITIVE_INFINITY; |
private static NetworkChangeNotifier sInstance; |
@@ -81,6 +72,18 @@ public class NetworkChangeNotifier { |
return mCurrentConnectionType; |
} |
+ @CalledByNative |
+ public double getCurrentMaxBandwidth() { |
+ return mCurrentMaxBandwidth; |
+ } |
+ |
+ /** |
+ * Calls a native map lookup of subtype to max bandwidth. |
+ */ |
+ public static double getMaxBandwidthForConnectionSubtype(int subtype) { |
+ return nativeGetMaxBandwidthForConnectionSubtype(subtype); |
+ } |
+ |
/** |
* Adds a native-side observer. |
*/ |
@@ -144,11 +147,13 @@ public class NetworkChangeNotifier { |
new NetworkChangeNotifierAutoDetect.Observer() { |
@Override |
public void onConnectionTypeChanged(int newConnectionType) { |
+ updateCurrentMaxBandwidth(mAutoDetector.getCurrentMaxBandwidthInMbps()); |
updateCurrentConnectionType(newConnectionType); |
} |
}, |
mContext, |
alwaysWatchForChanges); |
+ updateCurrentMaxBandwidth(mAutoDetector.getCurrentMaxBandwidthInMbps()); |
updateCurrentConnectionType(mAutoDetector.getCurrentConnectionType()); |
} |
} else { |
@@ -169,9 +174,12 @@ public class NetworkChangeNotifier { |
} |
private void forceConnectivityStateInternal(boolean forceOnline) { |
- boolean connectionCurrentlyExists = mCurrentConnectionType != CONNECTION_NONE; |
+ boolean connectionCurrentlyExists = |
+ mCurrentConnectionType != ConnectionType.CONNECTION_NONE; |
if (connectionCurrentlyExists != forceOnline) { |
- updateCurrentConnectionType(forceOnline ? CONNECTION_UNKNOWN : CONNECTION_NONE); |
+ updateCurrentMaxBandwidth(forceOnline ? Double.POSITIVE_INFINITY : 0.0); |
+ updateCurrentConnectionType(forceOnline ? ConnectionType.CONNECTION_UNKNOWN |
+ : ConnectionType.CONNECTION_NONE); |
} |
} |
@@ -180,6 +188,10 @@ public class NetworkChangeNotifier { |
notifyObserversOfConnectionTypeChange(newConnectionType); |
} |
+ private void updateCurrentMaxBandwidth(double maxBandwidth) { |
+ mCurrentMaxBandwidth = maxBandwidth; |
+ } |
+ |
/** |
* Alerts all observers of a connection change. |
*/ |
@@ -217,6 +229,8 @@ public class NetworkChangeNotifier { |
@NativeClassQualifiedName("NetworkChangeNotifierDelegateAndroid") |
private native void nativeNotifyConnectionTypeChanged(long nativePtr, int newConnectionType); |
+ private static native double nativeGetMaxBandwidthForConnectionSubtype(int subtype); |
+ |
// For testing only. |
public static NetworkChangeNotifierAutoDetect getAutoDetectorForTest() { |
return getInstance().mAutoDetector; |
@@ -227,6 +241,7 @@ public class NetworkChangeNotifier { |
*/ |
public static boolean isOnline() { |
int connectionType = getInstance().getCurrentConnectionType(); |
- return connectionType != CONNECTION_UNKNOWN && connectionType != CONNECTION_NONE; |
+ return connectionType != ConnectionType.CONNECTION_UNKNOWN |
+ && connectionType != ConnectionType.CONNECTION_NONE; |
} |
} |