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();
+ }
}
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiInfo;
import android.os.Bundle;
/**
// 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;
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);
}
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) {
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,
public TestAccessPointBuilder setSaved(boolean saved){
if (saved) {
- networkId = 1;
+ mNetworkId = 1;
} else {
- networkId = WifiConfiguration.INVALID_NETWORK_ID;
+ mNetworkId = WifiConfiguration.INVALID_NETWORK_ID;
}
return this;
}
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;
+ }
}