Fix NPE when forgetting networks.

- Fixed disablement of ephemeral networks
- Exit out of the fragment when Forget is pressed

Bug: 36723238
Test: m RunSettingsRoboTests and manual testing
Change-Id: I83c09a44dbef0f02a452dc8c3163523a27bd4b63
This commit is contained in:
Amin Shaikh
2017-03-31 13:56:53 -07:00
parent 8fc0d1f948
commit 3c0d5ff3d1
3 changed files with 56 additions and 23 deletions

View File

@@ -106,6 +106,7 @@ public class WifiDetailPreferenceController extends PreferenceController impleme
mSignalStr = context.getResources().getStringArray(R.array.wifi_signal);
mWifiConfig = accessPoint.getConfig();
mWifiManager = wifiManager;
mWifiInfo = wifiManager.getConnectionInfo();
lifecycle.addObserver(this);
}
@@ -265,16 +266,25 @@ public class WifiDetailPreferenceController extends PreferenceController impleme
mDnsPref.setDetailText(builder.toString());
}
/**
* Returns whether the network represented by this preference can be forgotten.
*/
public boolean canForgetNetwork() {
return mWifiInfo != null && mWifiInfo.isEphemeral() || mWifiConfig != null;
}
/**
* Forgets the wifi network associated with this preference.
*/
public void forgetNetwork() {
if (mWifiConfig.ephemeral) {
mWifiManager.disableEphemeralNetwork(mWifiConfig.SSID);
} else if (mWifiConfig.isPasspoint()) {
mWifiManager.removePasspointConfiguration(mWifiConfig.FQDN);
} else {
mWifiManager.forget(mWifiConfig.networkId, null /* action listener */);
if (mWifiInfo != null && mWifiInfo.isEphemeral()) {
mWifiManager.disableEphemeralNetwork(mWifiInfo.getSSID());
} else if (mWifiConfig != null) {
if (mWifiConfig.isPasspoint()) {
mWifiManager.removePasspointConfiguration(mWifiConfig.FQDN);
} else {
mWifiManager.forget(mWifiConfig.networkId, null /* action listener */);
}
}
}
}