Merge "Updating network info state should return true." into oc-dev
am: 703a233b03
Change-Id: Ib8a36b3880b65ea333a93dc4bd3ab5bca66272e7
This commit is contained in:
@@ -998,9 +998,10 @@ public class AccessPoint implements Comparable<AccessPoint> {
|
||||
if (mRssi != info.getRssi()) {
|
||||
mRssi = info.getRssi();
|
||||
updated = true;
|
||||
} else if (mNetworkInfo.getDetailedState() != networkInfo.getDetailedState()) {
|
||||
updated = true;
|
||||
}
|
||||
mInfo = info;
|
||||
// TODO(b/37289220): compare NetworkInfo states and set updated = true if necessary
|
||||
mNetworkInfo = networkInfo;
|
||||
} else if (mInfo != null) {
|
||||
updated = true;
|
||||
|
||||
@@ -404,4 +404,55 @@ public class AccessPointTest {
|
||||
assertThat(ap.getPasspointFqdn()).isEqualTo(fqdn);
|
||||
assertThat(ap.getConfigName()).isEqualTo(providerFriendlyName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateNetworkInfo_returnsTrue() {
|
||||
int networkId = 123;
|
||||
int rssi = -55;
|
||||
WifiConfiguration config = new WifiConfiguration();
|
||||
config.networkId = networkId;
|
||||
WifiInfo wifiInfo = new WifiInfo();
|
||||
wifiInfo.setNetworkId(networkId);
|
||||
wifiInfo.setRssi(rssi);
|
||||
|
||||
NetworkInfo networkInfo =
|
||||
new NetworkInfo(ConnectivityManager.TYPE_WIFI, 0 /* subtype */, "WIFI", "");
|
||||
networkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTING, "", "");
|
||||
|
||||
AccessPoint ap = new TestAccessPointBuilder(mContext)
|
||||
.setNetworkInfo(networkInfo)
|
||||
.setNetworkId(networkId)
|
||||
.setRssi(rssi)
|
||||
.setWifiInfo(wifiInfo)
|
||||
.build();
|
||||
|
||||
NetworkInfo newInfo = new NetworkInfo(networkInfo);
|
||||
newInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED, "", "");
|
||||
assertThat(ap.update(config, wifiInfo, newInfo)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateNetworkInfoWithSameInfo_returnsFalse() {
|
||||
int networkId = 123;
|
||||
int rssi = -55;
|
||||
WifiConfiguration config = new WifiConfiguration();
|
||||
config.networkId = networkId;
|
||||
WifiInfo wifiInfo = new WifiInfo();
|
||||
wifiInfo.setNetworkId(networkId);
|
||||
wifiInfo.setRssi(rssi);
|
||||
|
||||
NetworkInfo networkInfo =
|
||||
new NetworkInfo(ConnectivityManager.TYPE_WIFI, 0 /* subtype */, "WIFI", "");
|
||||
networkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTING, "", "");
|
||||
|
||||
AccessPoint ap = new TestAccessPointBuilder(mContext)
|
||||
.setNetworkInfo(networkInfo)
|
||||
.setNetworkId(networkId)
|
||||
.setRssi(rssi)
|
||||
.setWifiInfo(wifiInfo)
|
||||
.build();
|
||||
|
||||
NetworkInfo newInfo = new NetworkInfo(networkInfo); // same values
|
||||
assertThat(ap.update(config, wifiInfo, newInfo)).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.os.Bundle;
|
||||
|
||||
/**
|
||||
@@ -36,11 +37,13 @@ public class TestAccessPointBuilder {
|
||||
|
||||
// set some sensible defaults
|
||||
private int mRssi = AccessPoint.UNREACHABLE_RSSI;
|
||||
private int networkId = WifiConfiguration.INVALID_NETWORK_ID;
|
||||
private int mNetworkId = WifiConfiguration.INVALID_NETWORK_ID;
|
||||
private String ssid = "TestSsid";
|
||||
private NetworkInfo mNetworkInfo = null;
|
||||
private String mFqdn = null;
|
||||
private String mProviderFriendlyName = null;
|
||||
private WifiConfiguration mWifiConfig;
|
||||
private WifiInfo mWifiInfo;
|
||||
|
||||
Context mContext;
|
||||
|
||||
@@ -51,12 +54,13 @@ public class TestAccessPointBuilder {
|
||||
public AccessPoint build() {
|
||||
Bundle bundle = new Bundle();
|
||||
|
||||
WifiConfiguration wifiConig = new WifiConfiguration();
|
||||
wifiConig.networkId = networkId;
|
||||
WifiConfiguration wifiConfig = new WifiConfiguration();
|
||||
wifiConfig.networkId = mNetworkId;
|
||||
|
||||
bundle.putString(AccessPoint.KEY_SSID, ssid);
|
||||
bundle.putParcelable(AccessPoint.KEY_CONFIG, wifiConig);
|
||||
bundle.putParcelable(AccessPoint.KEY_CONFIG, wifiConfig);
|
||||
bundle.putParcelable(AccessPoint.KEY_NETWORKINFO, mNetworkInfo);
|
||||
bundle.putParcelable(AccessPoint.KEY_WIFIINFO, mWifiInfo);
|
||||
if (mFqdn != null) {
|
||||
bundle.putString(AccessPoint.KEY_FQDN, mFqdn);
|
||||
}
|
||||
@@ -81,17 +85,12 @@ public class TestAccessPointBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestAccessPointBuilder setRssi(int rssi) {
|
||||
mRssi = rssi;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rssi based upon the desired signal level.
|
||||
* Set the rssi based upon the desired signal level.
|
||||
*
|
||||
* <p>Side effect: if this AccessPoint was previously unreachable,
|
||||
* setting the level will also make it reachable.
|
||||
*/
|
||||
* <p>Side effect: if this AccessPoint was previously unreachable,
|
||||
* setting the level will also make it reachable.
|
||||
*/
|
||||
public TestAccessPointBuilder setLevel(int level) {
|
||||
// Reversal of WifiManager.calculateSignalLevels
|
||||
if (level == 0) {
|
||||
@@ -106,6 +105,16 @@ public class TestAccessPointBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestAccessPointBuilder setNetworkInfo(NetworkInfo info) {
|
||||
mNetworkInfo = info;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestAccessPointBuilder setRssi(int rssi) {
|
||||
mRssi = rssi;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether the AccessPoint is reachable.
|
||||
* Side effect: if the signal level was not previously set,
|
||||
@@ -125,9 +134,9 @@ public class TestAccessPointBuilder {
|
||||
|
||||
public TestAccessPointBuilder setSaved(boolean saved){
|
||||
if (saved) {
|
||||
networkId = 1;
|
||||
mNetworkId = 1;
|
||||
} else {
|
||||
networkId = WifiConfiguration.INVALID_NETWORK_ID;
|
||||
mNetworkId = WifiConfiguration.INVALID_NETWORK_ID;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -146,4 +155,20 @@ public class TestAccessPointBuilder {
|
||||
mProviderFriendlyName = friendlyName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestAccessPointBuilder setWifiInfo(WifiInfo info) {
|
||||
mWifiInfo = info;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the networkId in the WifiConfig.
|
||||
*
|
||||
* <p>Setting this to a value other than {@link WifiConfiguration#INVALID_NETWORK_ID} makes this
|
||||
* AccessPoint a saved network.
|
||||
*/
|
||||
public TestAccessPointBuilder setNetworkId(int networkId) {
|
||||
mNetworkId = networkId;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user