Support displaying a dialog when Wi-Fi loses Internet access. am: 1449ecd460

am: a4aa79bb69

Change-Id: I2558b419cdb5897ed8b3cd2c36c52411eab48936
This commit is contained in:
Lorenzo Colitti
2016-09-15 16:10:46 +00:00
committed by android-build-merger
3 changed files with 55 additions and 24 deletions

View File

@@ -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>

View File

@@ -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>

View File

@@ -26,6 +26,7 @@ import android.net.NetworkCapabilities;
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.AlertActivity;
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 @@ public final class WifiNoInternetDialog extends AlertActivity implements
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,13 +124,21 @@ public final class WifiNoInternetDialog extends AlertActivity implements
mAlert.setIcon(R.drawable.ic_settings_wireless);
final AlertController.AlertParams ap = mAlertParams;
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;
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);
@@ -129,6 +146,7 @@ public final class WifiNoInternetDialog extends AlertActivity implements
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 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);
if (ACTION_PROMPT_UNVALIDATED.equals(mAction)) {
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;
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);
}
}
}