diff options
author | Hugo Benichi <hugobenichi@google.com> | 2016-09-14 23:23:08 +0000 |
---|---|---|
committer | gitbuildkicker <android-build@google.com> | 2016-10-12 19:42:03 -0700 |
commit | 1bfa4c5379dff5b95b6549e7286188e2a76b05f4 (patch) | |
tree | 570516120e37ec5af660c388b3f7698968eb5574 | |
parent | ce5bc7f4a1e569fdbfc49a793c440613ccf14493 (diff) | |
download | base-1bfa4c5379dff5b95b6549e7286188e2a76b05f4.tar.gz |
Support ignoring penalty for bad wifi networks
This patch adds a way to configure devices so that a validated network
that becomes unvalidated is not penalized in the network scoring and
selection logic.
The intent is to prevent devices configured to do so from switching to a
lower scoring network such as cellular networks when a higher scoring
network such as wifi networks loses internet connectivity.
Bug: 31075769
Change-Id: Ie7e0f2607d214a178367fedfbef6c44768fa00a4
(cherry picked from commit c8e9e1229a91e22d6ab32d491d4c60086fbc9199)
-rwxr-xr-x | core/java/android/provider/Settings.java | 6 | ||||
-rw-r--r-- | core/res/res/values/config.xml | 5 | ||||
-rw-r--r-- | core/res/res/values/symbols.xml | 1 | ||||
-rw-r--r-- | services/core/java/com/android/server/ConnectivityService.java | 9 | ||||
-rw-r--r-- | services/core/java/com/android/server/connectivity/NetworkAgentInfo.java | 10 |
5 files changed, 30 insertions, 1 deletions
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 515a91c4d422..6949e43d9991 100755 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -7442,6 +7442,12 @@ public final class Settings { "network_switch_notification_rate_limit_millis"; /** + * Whether to automatically switch away from wifi networks that lose Internet access. + * @hide + */ + public static final String NETWORK_AVOID_BAD_WIFI = "network_avoid_bad_wifi"; + + /** * Whether Wifi display is enabled/disabled * 0=disabled. 1=enabled. * @hide diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index b80b0a70a036..3dbcdafcc99b 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -275,6 +275,11 @@ <string-array translatable="false" name="config_networkNotifySwitches"> </string-array> + <!-- Whether the device should automatically switch away from Wi-Fi networks that lose + Internet access. Actual device behaviour is controlled by + Settings.Global.NETWORK_AVOID_BAD_WIFI. This is the default value of that setting. --> + <integer translatable="false" name="config_networkAvoidBadWifi">1</integer> + <!-- List of regexpressions describing the interface (if any) that represent tetherable USB interfaces. If the device doesn't want to support tethering over USB this should be empty. An example would be "usb.*" --> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 924d33809124..def40dbcbd04 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -1746,6 +1746,7 @@ <java-symbol type="integer" name="config_networkTransitionTimeout" /> <java-symbol type="integer" name="config_networkNotifySwitchType" /> <java-symbol type="array" name="config_networkNotifySwitches" /> + <java-symbol type="integer" name="config_networkAvoidBadWifi" /> <java-symbol type="integer" name="config_notificationsBatteryFullARGB" /> <java-symbol type="integer" name="config_notificationsBatteryLedOff" /> <java-symbol type="integer" name="config_notificationsBatteryLedOn" /> diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index 5d0508c56b35..4c30dc2661ec 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -2704,6 +2704,15 @@ public class ConnectivityService extends IConnectivityManager.Stub PROMPT_UNVALIDATED_DELAY_MS); } + @VisibleForTesting + public boolean avoidBadWifi() { + int defaultAvoidBadWifi = + mContext.getResources().getInteger(R.integer.config_networkAvoidBadWifi); + int avoid = Settings.Global.getInt(mContext.getContentResolver(), + Settings.Global.NETWORK_AVOID_BAD_WIFI, defaultAvoidBadWifi); + return avoid == 1; + } + private void handlePromptUnvalidated(Network network) { if (VDBG) log("handlePromptUnvalidated " + network); NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network); diff --git a/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java b/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java index 780be3c4610f..3503eacb0735 100644 --- a/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java +++ b/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java @@ -113,6 +113,7 @@ import java.util.TreeSet; // a NetworkRequest, ConnectivityService will cancel the future disconnection of the NetworkAgent's // AsyncChannel, and the network is no longer considered "lingering". public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> { + public NetworkInfo networkInfo; // This Network object should always be used if possible, so as to encourage reuse of the // enclosed socket factory and connection pool. Avoid creating other Network objects. @@ -354,13 +355,20 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> { } int score = currentScore; - if (!lastValidated && !pretendValidated) { + if (!lastValidated && !pretendValidated && !ignoreWifiUnvalidationPenalty()) { score -= UNVALIDATED_SCORE_PENALTY; } if (score < 0) score = 0; return score; } + // Return true on devices configured to ignore score penalty for wifi networks + // that become unvalidated (b/31075769). + private boolean ignoreWifiUnvalidationPenalty() { + boolean isWifi = networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI); + return isWifi && !mConnService.avoidBadWifi() && everValidated; + } + // Get the current score for this Network. This may be modified from what the // NetworkAgent sent, as it has modifiers applied to it. public int getCurrentScore() { |