Chromium Code Reviews| 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.
|
| } |
| } |
| } |