From 7335c594bee161230baa6b27a4dc89ad8c6c3f9e Mon Sep 17 00:00:00 2001 From: lucaslin Date: Wed, 20 Mar 2019 11:41:21 +0800 Subject: [PATCH] Modify dialog message for partial connectivity In some networks, network validation may only get success result for http probe but fail result for https probe. For this kind of network, it may still work at some websites or apps, but user didn't know about that. In order to fix this issue, we will check if network has partial connectivity and notify user to make a choice if they want to use this partial connectivity or not. Bug: 113450764 Bug: 128489091 Test: 1. Build pass. 2. make -j44 RunSettingsRoboTests ROBOTEST_FILTER=WifiDetailPreferenceControllerTest 3. Change captive_portal_https_url to https://invalid.com to simulate partial connectivity. Change-Id: I0e87f6f2ede173f45a7b6fcf842b4f9a83d8efa1 --- AndroidManifest.xml | 2 +- res/values/strings.xml | 2 ++ .../settings/wifi/WifiNoInternetDialog.java | 19 ++++++++++++++++--- .../WifiDetailPreferenceController.java | 13 ++++++++----- .../WifiDetailPreferenceControllerTest.java | 13 +++++++++++++ 5 files changed, 40 insertions(+), 9 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 5b786813069..6744b41a86a 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -340,7 +340,7 @@ android:clearTaskOnLaunch="true" android:excludeFromRecents="true" android:exported="true" - android:permission="android.permission.CONNECTIVITY_INTERNAL" + android:permission="android.permission.NETWORK_STACK" android:theme="@*android:style/Theme.DeviceDefault.Light.Dialog.Alert"> diff --git a/res/values/strings.xml b/res/values/strings.xml index 631d9120cad..c10c9588b56 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -2213,6 +2213,8 @@ This network has no internet access. Stay connected? + + Some apps and services may not work due to limited connectivity. Use anyway? Don\u2019t ask again for this network diff --git a/src/com/android/settings/wifi/WifiNoInternetDialog.java b/src/com/android/settings/wifi/WifiNoInternetDialog.java index e12529d42d5..e33cab6de29 100644 --- a/src/com/android/settings/wifi/WifiNoInternetDialog.java +++ b/src/com/android/settings/wifi/WifiNoInternetDialog.java @@ -17,6 +17,7 @@ package com.android.settings.wifi; import static android.net.ConnectivityManager.ACTION_PROMPT_LOST_VALIDATION; +import static android.net.ConnectivityManager.ACTION_PROMPT_PARTIAL_CONNECTIVITY; import static android.net.ConnectivityManager.ACTION_PROMPT_UNVALIDATED; import static android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED; @@ -53,8 +54,9 @@ public final class WifiNoInternetDialog extends AlertActivity implements private String mAction; private boolean isKnownAction(Intent intent) { - return intent.getAction().equals(ACTION_PROMPT_UNVALIDATED) || - intent.getAction().equals(ACTION_PROMPT_LOST_VALIDATION); + return intent.getAction().equals(ACTION_PROMPT_UNVALIDATED) + || intent.getAction().equals(ACTION_PROMPT_LOST_VALIDATION) + || intent.getAction().equals(ACTION_PROMPT_PARTIAL_CONNECTIVITY); } @Override @@ -131,6 +133,11 @@ public final class WifiNoInternetDialog extends AlertActivity implements ap.mMessage = getString(R.string.no_internet_access_text); ap.mPositiveButtonText = getString(R.string.yes); ap.mNegativeButtonText = getString(R.string.no); + } else if (ACTION_PROMPT_PARTIAL_CONNECTIVITY.equals(mAction)) { + ap.mTitle = mNetworkName; + ap.mMessage = getString(R.string.partial_connectivity_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); @@ -146,7 +153,8 @@ public final class WifiNoInternetDialog extends AlertActivity implements ap.mView = checkbox; mAlwaysAllow = (CheckBox) checkbox.findViewById(com.android.internal.R.id.alwaysUse); - if (ACTION_PROMPT_UNVALIDATED.equals(mAction)) { + if (ACTION_PROMPT_UNVALIDATED.equals(mAction) + || ACTION_PROMPT_PARTIAL_CONNECTIVITY.equals(mAction)) { mAlwaysAllow.setText(getString(R.string.no_internet_access_remember)); } else { mAlwaysAllow.setText(getString(R.string.lost_internet_access_persist)); @@ -174,6 +182,11 @@ public final class WifiNoInternetDialog extends AlertActivity implements final boolean accept = (which == BUTTON_POSITIVE); action = (accept ? "Connect" : "Ignore"); mCM.setAcceptUnvalidated(mNetwork, accept, always); + } else if (ACTION_PROMPT_PARTIAL_CONNECTIVITY.equals(mAction)) { + what = "PARTIAL_CONNECTIVITY"; + final boolean accept = (which == BUTTON_POSITIVE); + action = (accept ? "Connect" : "Ignore"); + mCM.setAcceptPartialConnectivity(mNetwork, accept, always); } else { what = "LOST_INTERNET"; final boolean avoid = (which == BUTTON_POSITIVE); diff --git a/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java b/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java index 5588977554b..f328dba1b40 100644 --- a/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java +++ b/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java @@ -16,6 +16,7 @@ package com.android.settings.wifi.details; import static android.net.NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL; +import static android.net.NetworkCapabilities.NET_CAPABILITY_PARTIAL_CONNECTIVITY; import static android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED; import static android.net.NetworkCapabilities.TRANSPORT_WIFI; @@ -210,12 +211,14 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController @Override public void onCapabilitiesChanged(Network network, NetworkCapabilities nc) { - // If the network just validated or lost Internet access, refresh network state. - // Don't do this on every NetworkCapabilities change because update accesspoint notify - // changed for accesspoint changed on the main thread, which can cause jank. + // If the network just validated or lost Internet access or detected partial internet + // connectivity, refresh network state. Don't do this on every NetworkCapabilities + // change because refreshNetworkState sends IPCs to the system server from the UI + // thread, which can cause jank. if (network.equals(mNetwork) && !nc.equals(mNetworkCapabilities)) { - if (hasCapabilityChanged(nc, NET_CAPABILITY_VALIDATED) || - hasCapabilityChanged(nc, NET_CAPABILITY_CAPTIVE_PORTAL)) { + if (hasCapabilityChanged(nc, NET_CAPABILITY_VALIDATED) + || hasCapabilityChanged(nc, NET_CAPABILITY_CAPTIVE_PORTAL) + || hasCapabilityChanged(nc, NET_CAPABILITY_PARTIAL_CONNECTIVITY)) { mAccessPoint.update(mWifiConfig, mWifiInfo, mNetworkInfo); refreshEntityHeader(); } diff --git a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java index db767224d7d..574d0d651cc 100644 --- a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java @@ -649,6 +649,19 @@ public class WifiDetailPreferenceControllerTest { nc.removeCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED); updateNetworkCapabilities(nc); inOrder.verify(mockHeaderController).setSummary(summary); + + // UI will be refreshed when device connects to a partial connectivity network. + summary = "Limited connection"; + when(mockAccessPoint.getSettingsSummary()).thenReturn(summary); + nc.addCapability(NetworkCapabilities.NET_CAPABILITY_PARTIAL_CONNECTIVITY); + updateNetworkCapabilities(nc); + inOrder.verify(mockHeaderController).setSummary(summary); + + // Although UI will be refreshed when network become validated. The Settings should + // continue to display "Limited connection" if network still provides partial connectivity. + nc.addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED); + updateNetworkCapabilities(nc); + inOrder.verify(mockHeaderController).setSummary(summary); } @Test