Support ignoring penalty for bad wifi networks

am: c9048bc556

Change-Id: I6666ee45e9a08c02444c6268b2232bbe8aa2adec
This commit is contained in:
Hugo Benichi
2016-09-15 15:23:57 +00:00
committed by android-build-merger
2 changed files with 18 additions and 1 deletions

View File

@@ -2735,6 +2735,15 @@ public class ConnectivityService extends IConnectivityManager.Stub
PROMPT_UNVALIDATED_DELAY_MS); 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) { private void handlePromptUnvalidated(Network network) {
if (VDBG) log("handlePromptUnvalidated " + network); if (VDBG) log("handlePromptUnvalidated " + network);
NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network); NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network);

View File

@@ -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 // is satisfying one or more background NetworkRequests it is kept up in the background. If it is
// not, ConnectivityService disconnects the NetworkAgent's AsyncChannel. // not, ConnectivityService disconnects the NetworkAgent's AsyncChannel.
public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> { public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
public NetworkInfo networkInfo; public NetworkInfo networkInfo;
// This Network object should always be used if possible, so as to encourage reuse of the // 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. // enclosed socket factory and connection pool. Avoid creating other Network objects.
@@ -415,13 +416,20 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
} }
int score = currentScore; int score = currentScore;
if (!lastValidated && !pretendValidated) { if (!lastValidated && !pretendValidated && !ignoreWifiUnvalidationPenalty()) {
score -= UNVALIDATED_SCORE_PENALTY; score -= UNVALIDATED_SCORE_PENALTY;
} }
if (score < 0) score = 0; if (score < 0) score = 0;
return score; 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 // Get the current score for this Network. This may be modified from what the
// NetworkAgent sent, as it has modifiers applied to it. // NetworkAgent sent, as it has modifiers applied to it.
public int getCurrentScore() { public int getCurrentScore() {