diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java index cb209e8ae7..3c9886c2cd 100755 --- a/service/src/com/android/server/ConnectivityService.java +++ b/service/src/com/android/server/ConnectivityService.java @@ -357,7 +357,10 @@ public class ConnectivityService extends IConnectivityManager.Stub // of connectivity (valid, partial, captive portal). If none has been detected after this // delay, the stack considers this network bad, which may affect how it's handled in ranking // according to config_networkAvoidBadWifi. - private static final int INITIAL_EVALUATION_TIMEOUT_MS = 20 * 1000; + // Timeout in case the "actively prefer bad wifi" feature is on + private static final int ACTIVELY_PREFER_BAD_WIFI_INITIAL_TIMEOUT_MS = 20 * 1000; + // Timeout in case the "actively prefer bad wifi" feature is off + private static final int DONT_ACTIVELY_PREFER_BAD_WIFI_INITIAL_TIMEOUT_MS = 8 * 1000; // Default to 30s linger time-out, and 5s for nascent network. Modifiable only for testing. private static final String LINGER_DELAY_PROPERTY = "persist.netmon.linger"; @@ -3800,6 +3803,11 @@ public class ConnectivityService extends IConnectivityManager.Stub // the first time this ever happened. final boolean someConnectivity = (valid || partial || captive); final boolean becameEvaluated = someConnectivity && nai.setEvaluated(); + // Because of b/245893397, if the score is updated when updateCapabilities is called, + // any callback that receives onAvailable for that rematch receives an extra caps + // callback. To prevent that, update the score in the agent so the updates below won't + // see an update to both caps and score at the same time. + // TODO : fix b/245893397 and remove this. if (becameEvaluated) nai.updateScoreForNetworkAgentUpdate(); if (!valid && shouldIgnoreValidationFailureAfterRoam(nai)) { @@ -9234,7 +9242,10 @@ public class ConnectivityService extends IConnectivityManager.Stub networkAgent.networkMonitor().notifyNetworkConnected(params.linkProperties, params.networkCapabilities); } - scheduleEvaluationTimeout(networkAgent.network, INITIAL_EVALUATION_TIMEOUT_MS); + final long delay = activelyPreferBadWifi() + ? ACTIVELY_PREFER_BAD_WIFI_INITIAL_TIMEOUT_MS + : DONT_ACTIVELY_PREFER_BAD_WIFI_INITIAL_TIMEOUT_MS; + scheduleEvaluationTimeout(networkAgent.network, delay); // Whether a particular NetworkRequest listen should cause signal strength thresholds to // be communicated to a particular NetworkAgent depends only on the network's immutable,