summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Hugo Benichi <hugobenichi@google.com> 2016-09-15 15:23:57 +0000
committer android-build-merger <android-build-merger@google.com> 2016-09-15 15:23:57 +0000
commitc53b5964f8ef8a583dfa0f7bf537804b8d84ea65 (patch)
treeaab7fef153204d88b33699547a32e779484c5f22
parentd15fe5cf28d324f4f93198982f9c76aa23ff10b6 (diff)
parentc8e9e1229a91e22d6ab32d491d4c60086fbc9199 (diff)
Support ignoring penalty for bad wifi networks
am: c8e9e1229a Change-Id: I6666ee45e9a08c02444c6268b2232bbe8aa2adec
-rwxr-xr-xcore/java/android/provider/Settings.java6
-rw-r--r--core/res/res/values/config.xml5
-rw-r--r--core/res/res/values/symbols.xml1
-rw-r--r--services/core/java/com/android/server/ConnectivityService.java9
-rw-r--r--services/core/java/com/android/server/connectivity/NetworkAgentInfo.java10
5 files changed, 30 insertions, 1 deletions
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 79f11513e798..1e66c55ada5d 100755
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -7451,6 +7451,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 004b31f3a3ae..b047cdf3c69f 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 39127a43f0a3..4613b7803376 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -1747,6 +1747,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 ee455af5e31a..da08e626b7c6 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -2735,6 +2735,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 ba39ec016674..cb4bb8840b5a 100644
--- a/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java
+++ b/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java
@@ -115,6 +115,7 @@ import java.util.TreeSet;
// is satisfying one or more background NetworkRequests it is kept up in the background. If it is
// not, ConnectivityService disconnects the NetworkAgent's AsyncChannel.
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.
@@ -415,13 +416,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() {