From 5456b596a259e1657e6987a9cf17e9b552b336d6 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Fri, 7 Jun 2019 15:18:21 +0900 Subject: [PATCH] Disconnect if the user cancels the no/partial connectivity dialog If the user exits the no Internet or partial connectivity dialog without taking any action, there is no longer any way to use the network. So, disconnect the network. Bug: 130766237 Test: clicking outside dialog disconnects network Test: orientation changes do not disconnect network Change-Id: I80c2c98c994dc01e53b32f40332b3f1bd03b6012 --- .../settings/wifi/WifiNoInternetDialog.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/com/android/settings/wifi/WifiNoInternetDialog.java b/src/com/android/settings/wifi/WifiNoInternetDialog.java index e33cab6de29..eb42097fa16 100644 --- a/src/com/android/settings/wifi/WifiNoInternetDialog.java +++ b/src/com/android/settings/wifi/WifiNoInternetDialog.java @@ -52,6 +52,7 @@ public final class WifiNoInternetDialog extends AlertActivity implements private ConnectivityManager.NetworkCallback mNetworkCallback; private CheckBox mAlwaysAllow; private String mAction; + private boolean mButtonClicked; private boolean isKnownAction(Intent intent) { return intent.getAction().equals(ACTION_PROMPT_UNVALIDATED) @@ -169,14 +170,31 @@ public final class WifiNoInternetDialog extends AlertActivity implements mCM.unregisterNetworkCallback(mNetworkCallback); mNetworkCallback = null; } + + // If the user exits the no Internet or partial connectivity dialog without taking any + // action, disconnect the network, because once the dialog has been dismissed there is no + // way to use the network. + // + // Unfortunately, AlertDialog does not seem to offer any good way to get an onCancel or + // onDismiss callback. So we implement this ourselves. + if (isFinishing() && !mButtonClicked) { + if (ACTION_PROMPT_PARTIAL_CONNECTIVITY.equals(mAction)) { + mCM.setAcceptPartialConnectivity(mNetwork, false /* accept */, false /* always */); + } else if (ACTION_PROMPT_UNVALIDATED.equals(mAction)) { + mCM.setAcceptUnvalidated(mNetwork, false /* accept */, false /* always */); + } + } super.onDestroy(); } + @Override public void onClick(DialogInterface dialog, int which) { if (which != BUTTON_NEGATIVE && which != BUTTON_POSITIVE) return; final boolean always = mAlwaysAllow.isChecked(); final String what, action; + mButtonClicked = true; + if (ACTION_PROMPT_UNVALIDATED.equals(mAction)) { what = "NO_INTERNET"; final boolean accept = (which == BUTTON_POSITIVE);