Merge "Evaluation delay = 8 secs for explicitly selected networks"
diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java
index 53127d1..4f27a8a 100755
--- a/service/src/com/android/server/ConnectivityService.java
+++ b/service/src/com/android/server/ConnectivityService.java
@@ -389,7 +389,7 @@
// 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;
+ private static final int DEFAULT_EVALUATION_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";
@@ -9940,10 +9940,25 @@
networkAgent.networkMonitor().notifyNetworkConnected(params.linkProperties,
params.networkCapabilities);
}
- final long delay = !avoidBadWifi() && activelyPreferBadWifi()
- ? ACTIVELY_PREFER_BAD_WIFI_INITIAL_TIMEOUT_MS
- : DONT_ACTIVELY_PREFER_BAD_WIFI_INITIAL_TIMEOUT_MS;
- scheduleEvaluationTimeout(networkAgent.network, delay);
+ final long evaluationDelay;
+ if (!networkAgent.networkCapabilities.hasSingleTransport(TRANSPORT_WIFI)) {
+ // If the network is anything other than pure wifi, use the default timeout.
+ evaluationDelay = DEFAULT_EVALUATION_TIMEOUT_MS;
+ } else if (networkAgent.networkAgentConfig.isExplicitlySelected()) {
+ // If the network is explicitly selected, use the default timeout because it's
+ // shorter and the user is likely staring at the screen expecting it to validate
+ // right away.
+ evaluationDelay = DEFAULT_EVALUATION_TIMEOUT_MS;
+ } else if (avoidBadWifi() || !activelyPreferBadWifi()) {
+ // If avoiding bad wifi, or if not avoiding but also not preferring bad wifi
+ evaluationDelay = DEFAULT_EVALUATION_TIMEOUT_MS;
+ } else {
+ // It's wifi, automatically connected, and bad wifi is preferred : use the
+ // longer timeout to avoid the device switching to captive portals with bad
+ // signal or very slow response.
+ evaluationDelay = ACTIVELY_PREFER_BAD_WIFI_INITIAL_TIMEOUT_MS;
+ }
+ scheduleEvaluationTimeout(networkAgent.network, evaluationDelay);
// Whether a particular NetworkRequest listen should cause signal strength thresholds to
// be communicated to a particular NetworkAgent depends only on the network's immutable,
diff --git a/tests/unit/java/com/android/server/ConnectivityServiceTest.java b/tests/unit/java/com/android/server/ConnectivityServiceTest.java
index 8de6a31..4bbd3c8 100755
--- a/tests/unit/java/com/android/server/ConnectivityServiceTest.java
+++ b/tests/unit/java/com/android/server/ConnectivityServiceTest.java
@@ -2274,12 +2274,12 @@
mDestroySocketsWrapper.destroyLiveTcpSocketsByOwnerUids(ownerUids);
}
- final ArrayTrackRecord<Long>.ReadHead mScheduledEvaluationTimeouts =
- new ArrayTrackRecord<Long>().newReadHead();
+ final ArrayTrackRecord<Pair<Integer, Long>>.ReadHead mScheduledEvaluationTimeouts =
+ new ArrayTrackRecord<Pair<Integer, Long>>().newReadHead();
@Override
public void scheduleEvaluationTimeout(@NonNull Handler handler,
@NonNull final Network network, final long delayMs) {
- mScheduledEvaluationTimeouts.add(delayMs);
+ mScheduledEvaluationTimeouts.add(new Pair<>(network.netId, delayMs));
super.scheduleEvaluationTimeout(handler, network, delayMs);
}
}
@@ -6153,7 +6153,7 @@
}
public void doTestPreferBadWifi(final boolean avoidBadWifi,
- final boolean preferBadWifi,
+ final boolean preferBadWifi, final boolean explicitlySelected,
@NonNull Predicate<Long> checkUnvalidationTimeout) throws Exception {
// Pretend we're on a carrier that restricts switching away from bad wifi, and
// depending on the parameter one that may indeed prefer bad wifi.
@@ -6177,10 +6177,13 @@
mDefaultNetworkCallback.expectAvailableThenValidatedCallbacks(mCellAgent);
mWiFiAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI);
+ mWiFiAgent.explicitlySelected(explicitlySelected, false /* acceptUnvalidated */);
mWiFiAgent.connect(false);
wifiCallback.expectAvailableCallbacksUnvalidated(mWiFiAgent);
- mDeps.mScheduledEvaluationTimeouts.poll(TIMEOUT_MS, t -> checkUnvalidationTimeout.test(t));
+ assertNotNull(mDeps.mScheduledEvaluationTimeouts.poll(TIMEOUT_MS,
+ t -> t.first == mWiFiAgent.getNetwork().netId
+ && checkUnvalidationTimeout.test(t.second)));
if (!avoidBadWifi && preferBadWifi) {
expectUnvalidationCheckWillNotify(mWiFiAgent, NotificationType.LOST_INTERNET);
@@ -6196,27 +6199,33 @@
// Starting with U this mode is no longer supported and can't actually be tested
assumeFalse(mDeps.isAtLeastU());
doTestPreferBadWifi(false /* avoidBadWifi */, false /* preferBadWifi */,
- timeout -> timeout < 14_000);
+ false /* explicitlySelected */, timeout -> timeout < 14_000);
}
@Test
- public void testPreferBadWifi_doNotAvoid_doPrefer() throws Exception {
+ public void testPreferBadWifi_doNotAvoid_doPrefer_notExplicit() throws Exception {
doTestPreferBadWifi(false /* avoidBadWifi */, true /* preferBadWifi */,
- timeout -> timeout > 14_000);
+ false /* explicitlySelected */, timeout -> timeout > 14_000);
+ }
+
+ @Test
+ public void testPreferBadWifi_doNotAvoid_doPrefer_explicitlySelected() throws Exception {
+ doTestPreferBadWifi(false /* avoidBadWifi */, true /* preferBadWifi */,
+ true /* explicitlySelected */, timeout -> timeout < 14_000);
}
@Test
public void testPreferBadWifi_doAvoid_doNotPrefer() throws Exception {
// If avoidBadWifi=true, then preferBadWifi should be irrelevant. Test anyway.
doTestPreferBadWifi(true /* avoidBadWifi */, false /* preferBadWifi */,
- timeout -> timeout < 14_000);
+ false /* explicitlySelected */, timeout -> timeout < 14_000);
}
@Test
public void testPreferBadWifi_doAvoid_doPrefer() throws Exception {
// If avoidBadWifi=true, then preferBadWifi should be irrelevant. Test anyway.
doTestPreferBadWifi(true /* avoidBadWifi */, true /* preferBadWifi */,
- timeout -> timeout < 14_000);
+ false /* explicitlySelected */, timeout -> timeout < 14_000);
}
@Test