From d2bd9db36a817cb41bfa6045ce8a8e6904977526 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Thu, 17 Feb 2022 17:58:18 +0900 Subject: [PATCH] Don't check validation state in waitForAvailable(..., Network). The version of ConnectivityManagerTest#waitForAvailable that takes a callback and a Network implicitly requires that the network be validated, because it calls expectAvailableCallbacks with validated=true. This is incorrect because a network can become available without being validated. In particular, testMobileDataPreferredUids is flaky due to this problem, because it calls connectToCell, which does not wait for validation, and then calls waitForAvailable, which expects that the network is already validated. Fix it by not requiring any particular validation state. This method is only used by a few tests and they should not be affected by this change: - The first two calls in testSetOemNetworkPreferenceForTestPref happen after waiting for validation, so the network is validated already. The third call waits for a test network, and test networks are always validated. - The first call in testSetOemNetworkPreferenceForTestOnlyPref waits for a test network, which is always validated. The second is incorrect because ensureWifiConnected does not wait for validation, and is fixed by this CL. - The calls in testMobileDataPreferredUids similarly incorrectly assume that wifi is validated and are fixed by this CL. Test: atest CtsNetTestCases:android.net.cts.ConnectivityManagerTest#testMobileDataPreferredUids Change-Id: I614d0ba87c3931fcbe4011fed379e1736f5c4a44 --- tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java index ea64252200..dcaad519e0 100644 --- a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java +++ b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java @@ -2174,7 +2174,7 @@ public class ConnectivityManagerTest { private void waitForAvailable( @NonNull final TestableNetworkCallback cb, @NonNull final Network expectedNetwork) { cb.expectAvailableCallbacks(expectedNetwork, false /* suspended */, - true /* validated */, + null /* validated */, false /* blocked */, NETWORK_CALLBACK_TIMEOUT_MS); }