Allow open password dialog for wrong-password wifi access points

When we're failing to connect to a wifi access point due to an incorrect
password, we want to allow an intent from a notification to open up the
wifi settings page and bring up the dialog for entering a different
password. We already have code in settings to do this for not-yet-saved
access points, so this CL just changes it slightly to also allow it for
saved access points.

Unfortunately WifiSettings can't be tested with Robolectric due to it
not supporting PreferenceScreen, so this adds a test to
WifiSettingsUiTest. There were some existing test failures in that file
which I've fixed while I was in there:

-The TestAccessPointBuilder class wasn't being found at runtime because
 it was getting stripped out at build time due to not being used in
 settings.

-The changingSecurityStateOnApShouldNotCauseMultipleListItems test was
 asserting that we don't end up with multiple entries for the same SSID
 in the access point list when changing the security state for the AP,
 but it was accidentally passing multiple AP's with the same name the
 first time.

Bug: 33245941
Test: runtest --path WifiSettingsUiTest.java
Change-Id: I16c9c8b0d8380a0e26f9b23df6a8d012af6a2476
Merged-In: I929ca6892242059df157c01d6e9ea30e8d1c5e78
This commit is contained in:
Antony Sargent
2017-07-18 15:33:18 -07:00
parent f7d3537fcd
commit c00fedc639
2 changed files with 134 additions and 30 deletions

View File

@@ -146,8 +146,9 @@ public class WifiSettings extends RestrictedSettingsFragment
// account creation outside of setup wizard.
private static final String EXTRA_ENABLE_NEXT_ON_CONNECT = "wifi_enable_next_on_connect";
// This string extra specifies a network to open the connect dialog on, so the user can enter
// network credentials. This is used by quick settings for secured networks.
private static final String EXTRA_START_CONNECT_SSID = "wifi_start_connect_ssid";
// network credentials. This is used by quick settings for secured networks, among other
// things.
public static final String EXTRA_START_CONNECT_SSID = "wifi_start_connect_ssid";
// should Next button only be enabled when we have a connection?
private boolean mEnableNextOnConnection;
@@ -726,6 +727,21 @@ public class WifiSettings extends RestrictedSettingsFragment
changeNextButtonState(mWifiTracker.isConnected());
}
/** Helper method to return whether an AccessPoint is disabled due to a wrong password */
private static boolean isDisabledByWrongPassword(AccessPoint accessPoint) {
WifiConfiguration config = accessPoint.getConfig();
if (config == null) {
return false;
}
WifiConfiguration.NetworkSelectionStatus networkStatus =
config.getNetworkSelectionStatus();
if (networkStatus == null || networkStatus.isNetworkEnabled()) {
return false;
}
int reason = networkStatus.getNetworkSelectionDisableReason();
return WifiConfiguration.NetworkSelectionStatus.DISABLED_BY_WRONG_PASSWORD == reason;
}
private void updateAccessPointPreferences() {
// in case state has changed
if (!mWifiManager.isWifiEnabled()) {
@@ -761,10 +777,11 @@ public class WifiSettings extends RestrictedSettingsFragment
preference.setKey(key);
preference.setOrder(index);
if (mOpenSsid != null && mOpenSsid.equals(accessPoint.getSsidStr())
&& !accessPoint.isSaved()
&& accessPoint.getSecurity() != AccessPoint.SECURITY_NONE) {
onPreferenceTreeClick(preference);
mOpenSsid = null;
if (!accessPoint.isSaved() || isDisabledByWrongPassword(accessPoint)) {
onPreferenceTreeClick(preference);
mOpenSsid = null;
}
}
mAccessPointsPreferenceCategory.addPreference(preference);
accessPoint.setListener(WifiSettings.this);