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

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: Don't monitor RSSI if there is no permission to act on it 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..86e621eab41a4f7a9e7c8ab46e5f681c6a14c6d2 100644
--- a/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java
+++ b/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java
@@ -130,12 +130,15 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver
// though the connection type hasn't changed.
return wifiInfo.getLinkSpeed();
}
+
+ boolean getHasWifiPermission() {
+ return mHasWifiPermission;
+ }
}
private static final String TAG = "NetworkChangeNotifierAutoDetect";
private static final int UNKNOWN_LINK_SPEED = -1;
- private final NetworkConnectivityIntentFilter mIntentFilter =
- new NetworkConnectivityIntentFilter();
+ private final NetworkConnectivityIntentFilter mIntentFilter;
private final Observer mObserver;
@@ -145,12 +148,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,11 +172,14 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver
mWifiManagerDelegate = new WifiManagerDelegate(context);
mConnectionType = getCurrentConnectionType();
mWifiSSID = getCurrentWifiSSID();
+ mMaxBandwidthMbps = getCurrentMaxBandwidthInMbps();
if (alwaysWatchForChanges) {
registerReceiver();
} else {
ApplicationStatus.registerApplicationStateListener(this);
}
+ mIntentFilter = new NetworkConnectivityIntentFilter(
+ mWifiManagerDelegate.getHasWifiPermission());
}
/**
@@ -261,10 +270,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) {
pauljensen 2014/12/11 16:13:56 There are several IPCs over to ConnectivityService
jkarlin 2014/12/15 19:43:55 Done.
@@ -340,7 +345,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 +376,19 @@ 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() {
+ NetworkConnectivityIntentFilter(boolean monitorRSSI) {
addAction(ConnectivityManager.CONNECTIVITY_ACTION);
+ if (monitorRSSI) {
+ addAction(WifiManager.RSSI_CHANGED_ACTION);
+ }
}
}
}

Powered by Google App Engine
This is Rietveld 408576698