Add a "Don't ask again" checkbox to the avoid bad wifi dialog. am: c179f33c87 am: bd1936e9e9 am: f6a0fda0e5

am: c2dd47e331

Change-Id: I363d6dc94add9c0ab0f13a26626010a386d8373a
This commit is contained in:
Lorenzo Colitti
2016-09-21 06:07:59 +00:00
committed by android-build-merger
2 changed files with 20 additions and 25 deletions

View File

@@ -170,8 +170,8 @@ public class ConfigureWifiSettings extends SettingsPreferenceFragment
}
private boolean avoidBadWifiCurrentSettings() {
return Settings.Global.getInt(getContentResolver(),
Settings.Global.NETWORK_AVOID_BAD_WIFI, 0) == 1;
return "1".equals(Settings.Global.getString(getContentResolver(),
Settings.Global.NETWORK_AVOID_BAD_WIFI));
}
@Override
@@ -183,17 +183,10 @@ public class ConfigureWifiSettings extends SettingsPreferenceFragment
Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
((SwitchPreference) preference).isChecked() ? 1 : 0);
} else if (KEY_CELLULAR_FALLBACK.equals(key)) {
// On: avoid bad wifi. Off: prompt.
String settingName = Settings.Global.NETWORK_AVOID_BAD_WIFI;
if (((SwitchPreference) preference).isChecked()) {
// The user wants to avoid bad wifi networks. Remember the choice.
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);
}
Settings.Global.putString(getContentResolver(), settingName,
((SwitchPreference) preference).isChecked() ? "1" : null);
} else {
return super.onPreferenceTreeClick(preference);
}

View File

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