Fix NPE on network forget from details page.

Forgetting a network from the wifi network details page throws an NPE in
WifiSettings when the details fragment exits, crashing the app.

Bug: b/63351286
Test: runtest --path
frameworks/base/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/AccessPointTest.java

Change-Id: I749ecbda5654ff7a86ffe4c38ca74ebe338923f0
This commit is contained in:
Sundeep Ghuman
2017-07-05 20:06:05 -07:00
parent 96decad236
commit d911da3adc
2 changed files with 28 additions and 3 deletions

View File

@@ -1053,7 +1053,8 @@ public class AccessPoint implements Comparable<AccessPoint> {
}
/** Attempt to update the AccessPoint and return true if an update occurred. */
public boolean update(WifiConfiguration config, WifiInfo info, NetworkInfo networkInfo) {
public boolean update(
@Nullable WifiConfiguration config, WifiInfo info, NetworkInfo networkInfo) {
boolean updated = false;
final int oldLevel = getLevel();
if (info != null && isInfoForThisAccessPoint(config, info)) {
@@ -1088,9 +1089,9 @@ public class AccessPoint implements Comparable<AccessPoint> {
return updated;
}
void update(WifiConfiguration config) {
void update(@Nullable WifiConfiguration config) {
mConfig = config;
networkId = config.networkId;
networkId = config != null ? config.networkId : WifiConfiguration.INVALID_NETWORK_ID;
if (mAccessPointListener != null) {
mAccessPointListener.onAccessPointChanged(this);
}

View File

@@ -656,4 +656,28 @@ public class AccessPointTest {
assertThat(ap.update(newConfig, wifiInfo, networkInfo)).isFalse();
verify(mockListener).onAccessPointChanged(ap);
}
@Test
public void testUpdateWithNullWifiConfiguration_doesNotThrowNPE() {
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();
ap.update(null, wifiInfo, networkInfo);
}
}