Add a "Don't ask again" checkbox to the avoid bad wifi dialog.

Also update the settings code to reflect the new tristate
semantics of the NETWORK_AVOID_BAD_WIFI setting.

Bug: 31075769
Change-Id: Icd21d8272abe6afd42ee8a41e2c7e1a6af77f0b3
This commit is contained in:
Lorenzo Colitti
2016-09-19 01:08:07 +09:00
parent 0d00554d62
commit c179f33c87
2 changed files with 20 additions and 25 deletions

View File

@@ -170,8 +170,8 @@ public class ConfigureWifiSettings extends SettingsPreferenceFragment
} }
private boolean avoidBadWifiCurrentSettings() { private boolean avoidBadWifiCurrentSettings() {
return Settings.Global.getInt(getContentResolver(), return "1".equals(Settings.Global.getString(getContentResolver(),
Settings.Global.NETWORK_AVOID_BAD_WIFI, 0) == 1; Settings.Global.NETWORK_AVOID_BAD_WIFI));
} }
@Override @Override
@@ -183,17 +183,10 @@ public class ConfigureWifiSettings extends SettingsPreferenceFragment
Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
((SwitchPreference) preference).isChecked() ? 1 : 0); ((SwitchPreference) preference).isChecked() ? 1 : 0);
} else if (KEY_CELLULAR_FALLBACK.equals(key)) { } else if (KEY_CELLULAR_FALLBACK.equals(key)) {
// On: avoid bad wifi. Off: prompt.
String settingName = Settings.Global.NETWORK_AVOID_BAD_WIFI; String settingName = Settings.Global.NETWORK_AVOID_BAD_WIFI;
if (((SwitchPreference) preference).isChecked()) { Settings.Global.putString(getContentResolver(), settingName,
// The user wants to avoid bad wifi networks. Remember the choice. ((SwitchPreference) preference).isChecked() ? "1" : null);
Settings.Global.putInt(getContentResolver(), settingName, 1);
} else {
// Unset the setting. ConnectivityService interprets null to mean "use the carrier
// default". We don't set the setting to 0 because if we do, and the user switches
// to a carrier that does not restrict cellular fallback, then there is no way to
// set it to 1 again because on such a carrier the toggle is never shown.
Settings.Global.putString(getContentResolver(), settingName, null);
}
} else { } else {
return super.onPreferenceTreeClick(preference); return super.onPreferenceTreeClick(preference);
} }

View File

@@ -164,24 +164,26 @@ public final class WifiNoInternetDialog extends AlertActivity implements
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if (which != BUTTON_NEGATIVE && which != BUTTON_POSITIVE) return; if (which != BUTTON_NEGATIVE && which != BUTTON_POSITIVE) return;
final boolean accept = (which == BUTTON_POSITIVE); final boolean always = mAlwaysAllow.isChecked();
final String what, action;
if (ACTION_PROMPT_UNVALIDATED.equals(mAction)) { if (ACTION_PROMPT_UNVALIDATED.equals(mAction)) {
final String action = (accept ? "Connect" : "Ignore"); what = "NO_INTERNET";
final boolean always = mAlwaysAllow.isChecked(); final boolean accept = (which == BUTTON_POSITIVE);
action = (accept ? "Connect" : "Ignore");
mCM.setAcceptUnvalidated(mNetwork, accept, always); mCM.setAcceptUnvalidated(mNetwork, accept, always);
Log.d(TAG, "NO_INTERNET: " + action + " network=" + mNetwork +
(always ? " and remember" : ""));
} else { } else {
final String action = (accept ? "Switch" : "Cancel"); what = "LOST_INTERNET";
Log.d(TAG, "LOST_INTERNET: " + action); final boolean avoid = (which == BUTTON_POSITIVE);
// Only ever set the setting to 1. The values understood by ConnectivityService are null action = (avoid ? "Switch away" : "Get stuck");
// (use carrier default) or 1 (avoid bad networks regardless of carrier). if (always) {
// TODO: Use a value other than 1 here to indicate a persisted "yes" or "no" given mAlwaysAllow. Settings.Global.putString(mAlertParams.mContext.getContentResolver(),
if (accept) { Settings.Global.NETWORK_AVOID_BAD_WIFI, avoid ? "1" : "0");
Settings.Global.putInt(mAlertParams.mContext.getContentResolver(), } else if (avoid) {
Settings.Global.NETWORK_AVOID_BAD_WIFI, 1); mCM.setAvoidUnvalidated(mNetwork);
} }
} }
Log.d(TAG, what + ": " + action + " network=" + mNetwork +
(always ? " and remember" : ""));
} }
} }