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

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

Issue 780293003: [NetInfo] Add MaxBandwidthChanged notification and implement on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@maxbandwidth_android
Patch Set: Nits Created 6 years 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 12ae4654a20f6c3caa9622dd9f13eeab478dcfd5..573dccc178cd2078f140611141ff5c9eb680e455 100644
--- a/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java
+++ b/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java
@@ -145,12 +145,15 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver
private boolean mRegistered;
private int mConnectionType;
private String mWifiSSID;
+ private double mMaxBandwidthMbps;
/**
- * Observer notified on the UI thread whenever a new connection type was detected.
+ * Observer notified on the UI thread whenever a new connection type was detected or max
+ * bandwidth is changed.
*/
public static interface Observer {
public void onConnectionTypeChanged(int newConnectionType);
+ public void onMaxBandwidthChanged(double maxBandwidthMbps);
}
/**
@@ -166,6 +169,7 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver
mWifiManagerDelegate = new WifiManagerDelegate(context);
mConnectionType = getCurrentConnectionType();
mWifiSSID = getCurrentWifiSSID();
+ mMaxBandwidthMbps = getCurrentMaxBandwidthInMbps();
if (alwaysWatchForChanges) {
registerReceiver();
} else {
@@ -261,10 +265,6 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver
* derived from the NetInfo v3 specification's mapping from network type to
* max link speed. In cases where more information is available, such as wifi,
* that is used instead. For more on NetInfo, see http://w3c.github.io/netinfo/.
- *
- * TODO(jkarlin): Add a notification of bandwidth change to the NetworkChangeNotifier.
- * Without that the MaxBandwidth value will be stale until the network type or address
- * changes again.
*/
public double getCurrentMaxBandwidthInMbps() {
if (getCurrentConnectionType() == ConnectionType.CONNECTION_WIFI) {
@@ -340,7 +340,12 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver
// BroadcastReceiver
@Override
public void onReceive(Context context, Intent intent) {
- connectionTypeChanged();
+ if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
+ connectionTypeChanged();
+ maxBandwidthChanged();
+ } else if (WifiManager.RSSI_CHANGED_ACTION.equals(intent.getAction())) {
+ maxBandwidthChanged();
+ }
}
// ApplicationStatus.ApplicationStateListener
@@ -366,9 +371,17 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver
mObserver.onConnectionTypeChanged(newConnectionType);
}
+ private void maxBandwidthChanged() {
+ double newMaxBandwidthMbps = getCurrentMaxBandwidthInMbps();
+ if (newMaxBandwidthMbps == mMaxBandwidthMbps) return;
+ mMaxBandwidthMbps = newMaxBandwidthMbps;
+ mObserver.onMaxBandwidthChanged(newMaxBandwidthMbps);
+ }
+
private static class NetworkConnectivityIntentFilter extends IntentFilter {
NetworkConnectivityIntentFilter() {
addAction(ConnectivityManager.CONNECTIVITY_ACTION);
+ addAction(WifiManager.RSSI_CHANGED_ACTION);
pauljensen 2014/12/05 19:27:34 We should not be registering for another broadcast
jkarlin 2014/12/08 16:58:43 Done.
}
}
}

Powered by Google App Engine
This is Rietveld 408576698