Support displaying a dialog when Wi-Fi loses Internet access. am: 1449ecd460
am: a4aa79bb69
Change-Id: I2558b419cdb5897ed8b3cd2c36c52411eab48936
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index d83ac19..78fa324 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -385,6 +385,10 @@
<action android:name="android.net.conn.PROMPT_UNVALIDATED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
+ <intent-filter>
+ <action android:name="android.net.conn.PROMPT_LOST_VALIDATION" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
</activity>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 341e4a3..d1f7f63 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1745,7 +1745,14 @@
<!-- Dialog text to tell the user that the selected network does not have Internet access. -->
<string name="no_internet_access_text">This network has no Internet access. Stay connected?</string>
- <string name="no_internet_access_remember">Don\u2019t ask again for this network</string>
+ <string name="no_internet_access_remember">Don\u2019t ask again</string>
+
+ <!-- Dialog text to tell the user that the selected network has lost Internet access, and asking the usee whether they want to avoid this network. -->
+ <string name="lost_internet_access_title">Wi\u2011Fi has no Internet access</string>
+ <string name="lost_internet_access_text">Your device can automatically switch to other saved Wi\u2011Fi networks or cellular data. Cellular charges may apply.</string>
+ <string name="lost_internet_access_switch">Switch networks</string>
+ <string name="lost_internet_access_cancel">Cancel</string>
+
<!-- Button label to connect to a Wi-Fi network -->
<string name="wifi_connect">Connect</string>
diff --git a/src/com/android/settings/wifi/WifiNoInternetDialog.java b/src/com/android/settings/wifi/WifiNoInternetDialog.java
index b655344..289e0fc 100644
--- a/src/com/android/settings/wifi/WifiNoInternetDialog.java
+++ b/src/com/android/settings/wifi/WifiNoInternetDialog.java
@@ -26,6 +26,7 @@
import android.net.NetworkInfo;
import android.net.NetworkRequest;
import android.os.Bundle;
+import android.provider.Settings;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@@ -35,6 +36,8 @@
import com.android.internal.app.AlertController;
import com.android.settings.R;
+import static android.net.ConnectivityManager.ACTION_PROMPT_LOST_VALIDATION;
+import static android.net.ConnectivityManager.ACTION_PROMPT_UNVALIDATED;
import static android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED;
public final class WifiNoInternetDialog extends AlertActivity implements
@@ -46,20 +49,26 @@
private String mNetworkName;
private ConnectivityManager.NetworkCallback mNetworkCallback;
private CheckBox mAlwaysAllow;
+ private String mAction;
+
+ private boolean isKnownAction(Intent intent) {
+ return intent.getAction().equals(ACTION_PROMPT_UNVALIDATED) ||
+ intent.getAction().equals(ACTION_PROMPT_LOST_VALIDATION);
+ }
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Intent intent = getIntent();
- if (intent == null ||
- !intent.getAction().equals(ConnectivityManager.ACTION_PROMPT_UNVALIDATED) ||
- !"netId".equals(intent.getScheme())) {
+ if (intent == null || !isKnownAction(intent) || !"netId".equals(intent.getScheme())) {
Log.e(TAG, "Unexpected intent " + intent + ", exiting");
finish();
return;
}
+ mAction = intent.getAction();
+
try {
mNetwork = new Network(Integer.parseInt(intent.getData().getSchemeSpecificPart()));
} catch (NullPointerException|NumberFormatException e) {
@@ -115,20 +124,29 @@
mAlert.setIcon(R.drawable.ic_settings_wireless);
final AlertController.AlertParams ap = mAlertParams;
- ap.mTitle = mNetworkName;
- ap.mMessage = getString(R.string.no_internet_access_text);
- ap.mPositiveButtonText = getString(R.string.yes);
- ap.mNegativeButtonText = getString(R.string.no);
+ if (ACTION_PROMPT_UNVALIDATED.equals(mAction)) {
+ ap.mTitle = mNetworkName;
+ ap.mMessage = getString(R.string.no_internet_access_text);
+ ap.mPositiveButtonText = getString(R.string.yes);
+ ap.mNegativeButtonText = getString(R.string.no);
+ } else {
+ ap.mTitle = getString(R.string.lost_internet_access_title);
+ ap.mMessage = getString(R.string.lost_internet_access_text);
+ ap.mPositiveButtonText = getString(R.string.lost_internet_access_switch);
+ ap.mNegativeButtonText = getString(R.string.lost_internet_access_cancel);
+ }
ap.mPositiveButtonListener = this;
ap.mNegativeButtonListener = this;
- final LayoutInflater inflater = LayoutInflater.from(ap.mContext);
- final View checkbox = inflater.inflate(
- com.android.internal.R.layout.always_use_checkbox, null);
- ap.mView = checkbox;
+ if (ACTION_PROMPT_UNVALIDATED.equals(mAction)) {
+ final LayoutInflater inflater = LayoutInflater.from(ap.mContext);
+ final View checkbox = inflater.inflate(
+ com.android.internal.R.layout.always_use_checkbox, null);
+ ap.mView = checkbox;
- mAlwaysAllow = (CheckBox) checkbox.findViewById(com.android.internal.R.id.alwaysUse);
- mAlwaysAllow.setText(getString(R.string.no_internet_access_remember));
+ mAlwaysAllow = (CheckBox) checkbox.findViewById(com.android.internal.R.id.alwaysUse);
+ mAlwaysAllow.setText(getString(R.string.no_internet_access_remember));
+ }
setupAlert();
}
@@ -143,18 +161,20 @@
}
public void onClick(DialogInterface dialog, int which) {
+ if (which != BUTTON_NEGATIVE && which != BUTTON_POSITIVE) return;
final boolean accept = (which == BUTTON_POSITIVE);
- final String action = (accept ? "Connect" : "Ignore");
- final boolean always = mAlwaysAllow.isChecked();
- switch (which) {
- case BUTTON_POSITIVE:
- case BUTTON_NEGATIVE:
- mCM.setAcceptUnvalidated(mNetwork, accept, always);
- Log.d(TAG, action + " network=" + mNetwork + (always ? " and remember" : ""));
- break;
- default:
- break;
+ if (ACTION_PROMPT_UNVALIDATED.equals(mAction)) {
+ final String action = (accept ? "Connect" : "Ignore");
+ final boolean always = mAlwaysAllow.isChecked();
+ 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);
+ Settings.Global.putInt(mAlertParams.mContext.getContentResolver(),
+ Settings.Global.NETWORK_AVOID_BAD_WIFI, accept ? 1 : 0);
}
}
}