Commit 8788690b authored by pauljensen's avatar pauljensen Committed by Commit bot

Remove WiFi link speed tracking from Android NetworkChangeNotifier

Chrome has eschewed ACCESS_WIFI_STATE permission so this code is
disabled.  Chrome is also the only user of this NetworkChangeNotifier
signal so remove the code as it is consequently dead.

BUG=647691
R=jkarlin

Review-Url: https://codereview.chromium.org/2359173002
Cr-Commit-Position: refs/heads/master@{#420692}
parent 060d1d53
......@@ -285,24 +285,6 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver {
}
}
}
/*
* Requires ACCESS_WIFI_STATE permission to get the real link speed, else returns
* UNKNOWN_LINK_SPEED.
*/
int getLinkSpeedInMbps() {
if (!mHasWifiPermission || mWifiManager == null) return UNKNOWN_LINK_SPEED;
final WifiInfo wifiInfo = getWifiInfo();
if (wifiInfo == null) return UNKNOWN_LINK_SPEED;
// wifiInfo.getLinkSpeed returns the current wifi linkspeed, which can change even
// though the connection type hasn't changed.
return wifiInfo.getLinkSpeed();
}
boolean getHasWifiPermission() {
return mHasWifiPermission;
}
}
// This class gets called back by ConnectivityManager whenever networks come
......@@ -592,8 +574,7 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver {
mWifiSSID = getCurrentWifiSSID(networkState);
mMaxBandwidthMbps = getCurrentMaxBandwidthInMbps(networkState);
mMaxBandwidthConnectionType = mConnectionType;
mIntentFilter =
new NetworkConnectivityIntentFilter(mWifiManagerDelegate.getHasWifiPermission());
mIntentFilter = new NetworkConnectivityIntentFilter();
mRegistrationPolicy = policy;
mRegistrationPolicy.init(this);
}
......@@ -860,17 +841,10 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver {
/**
* Returns the bandwidth of the current connection in Mbps. The result is
* 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/.
* max link speed. In cases where more information is available that is used
* instead. For more on NetInfo, see http://w3c.github.io/netinfo/.
*/
public double getCurrentMaxBandwidthInMbps(NetworkState networkState) {
if (convertToConnectionType(networkState) == ConnectionType.CONNECTION_WIFI) {
final int link_speed = mWifiManagerDelegate.getLinkSpeedInMbps();
if (link_speed != UNKNOWN_LINK_SPEED) {
return link_speed;
}
}
return NetworkChangeNotifier.getMaxBandwidthForConnectionSubtype(
convertToConnectionSubtype(networkState));
}
......@@ -887,8 +861,6 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver {
if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
connectionTypeChanged(networkState);
maxBandwidthChanged(networkState);
} else if (WifiManager.RSSI_CHANGED_ACTION.equals(intent.getAction())) {
maxBandwidthChanged(networkState);
}
}
......@@ -916,9 +888,8 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver {
}
private static class NetworkConnectivityIntentFilter extends IntentFilter {
NetworkConnectivityIntentFilter(boolean monitorRSSI) {
NetworkConnectivityIntentFilter() {
addAction(ConnectivityManager.CONNECTIVITY_ACTION);
if (monitorRSSI) addAction(WifiManager.RSSI_CHANGED_ACTION);
}
}
......
......@@ -17,7 +17,6 @@ import android.net.ConnectivityManager.NetworkCallback;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkRequest;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.test.InstrumentationTestCase;
......@@ -258,7 +257,6 @@ public class NetworkChangeNotifierTest extends InstrumentationTestCase {
private static class MockWifiManagerDelegate
extends NetworkChangeNotifierAutoDetect.WifiManagerDelegate {
private String mWifiSSID;
private int mLinkSpeedMbps;
@Override
public String getWifiSSID() {
......@@ -268,15 +266,6 @@ public class NetworkChangeNotifierTest extends InstrumentationTestCase {
public void setWifiSSID(String wifiSSID) {
mWifiSSID = wifiSSID;
}
@Override
public int getLinkSpeedInMbps() {
return mLinkSpeedMbps;
}
public void setLinkSpeedInMbps(int linkSpeedInMbps) {
mLinkSpeedMbps = linkSpeedInMbps;
}
}
private static int demungeNetId(long netId) {
......@@ -492,37 +481,6 @@ public class NetworkChangeNotifierTest extends InstrumentationTestCase {
assertTrue(mReceiver.isReceiverRegisteredForTesting());
}
/**
* Tests that changing the RSSI_CHANGED_ACTION intent updates MaxBandwidth.
*/
@UiThreadTest
@MediumTest
@Feature({"Android-AppBase"})
public void testNetworkChangeNotifierRSSIEventUpdatesMaxBandwidthForWiFi()
throws InterruptedException {
NetworkChangeNotifier notifier = NetworkChangeNotifier.getInstance();
mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_WIFI);
mWifiDelegate.setLinkSpeedInMbps(42);
Intent intent = new Intent(WifiManager.RSSI_CHANGED_ACTION);
mReceiver.onReceive(getInstrumentation().getTargetContext(), intent);
assertEquals(42.0, notifier.getCurrentMaxBandwidthInMbps());
// Changing the link speed has no effect until the intent fires.
mWifiDelegate.setLinkSpeedInMbps(80);
assertEquals(42.0, notifier.getCurrentMaxBandwidthInMbps());
// Fire the intent.
mReceiver.onReceive(getInstrumentation().getTargetContext(), intent);
assertEquals(80.0, notifier.getCurrentMaxBandwidthInMbps());
// Firing a network type change intent also causes max bandwidth to update.
mWifiDelegate.setLinkSpeedInMbps(20);
intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
mReceiver.onReceive(getInstrumentation().getTargetContext(), intent);
assertEquals(20.0, notifier.getCurrentMaxBandwidthInMbps());
}
/**
* Tests that changing the network type changes the maxBandwidth.
*/
......@@ -540,11 +498,10 @@ public class NetworkChangeNotifierTest extends InstrumentationTestCase {
@MediumTest
@Feature({"Android-AppBase"})
public void testNetworkChangeNotifierMaxBandwidthWifi() throws InterruptedException {
// Test that for wifi types the link speed is read from the WifiManager.
mWifiDelegate.setLinkSpeedInMbps(42);
// Show that for WiFi the link speed is unknown (+Infinity).
mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_WIFI);
assertEquals(ConnectionType.CONNECTION_WIFI, getCurrentConnectionType());
assertEquals(42.0, getCurrentMaxBandwidthInMbps());
assertEquals(Double.POSITIVE_INFINITY, getCurrentMaxBandwidthInMbps());
}
@UiThreadTest
......@@ -648,7 +605,6 @@ public class NetworkChangeNotifierTest extends InstrumentationTestCase {
// Initialize the NetworkChangeNotifier with a connection.
mConnectivityDelegate.setActiveNetworkExists(true);
mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_WIFI);
mWifiDelegate.setLinkSpeedInMbps(1);
Intent connectivityIntent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
mReceiver.onReceive(getInstrumentation().getTargetContext(), connectivityIntent);
assertTrue(mNotifier.hasReceivedMaxBandwidthNotification());
......@@ -660,12 +616,6 @@ public class NetworkChangeNotifierTest extends InstrumentationTestCase {
mReceiver.onReceive(getInstrumentation().getTargetContext(), connectivityIntent);
assertFalse(mNotifier.hasReceivedMaxBandwidthNotification());
// We should be notified if the bandwidth changed but not the connection type.
mWifiDelegate.setLinkSpeedInMbps(2);
mReceiver.onReceive(getInstrumentation().getTargetContext(), connectivityIntent);
assertTrue(mNotifier.hasReceivedMaxBandwidthNotification());
mNotifier.resetHasReceivedMaxBandwidthNotification();
// We should be notified if bandwidth and connection type changed.
mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_ETHERNET);
mReceiver.onReceive(getInstrumentation().getTargetContext(), connectivityIntent);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment