Ensure default network before testing
The testBlockedStatusCallback will get the default network,
and use it to verify upcoming callbacks. However, sometimes
the wifi network will be disconnected by previous executed
tests and becoming connected during the test, and fail the
test.
Thus, ensure wifi is the default network if it is supported
before testing.
Test: atest CtsNetTestCases:android.net.cts.ConnectivityManagerTest#testBlockedStatusCallback \
--rerun-until-failure 200
Fix: 260560020
Change-Id: Icd79005dbcf5966beb2f2caf271a32b3f772f475
diff --git a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java
index 96acac3..7624f9c 100644
--- a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java
+++ b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java
@@ -2408,6 +2408,15 @@
}
private void doTestBlockedStatusCallback() throws Exception {
+ // The test will need a stable active network that is persistent during the test.
+ // Try to connect to a wifi network and wait for it becomes the default network before
+ // starting the test to prevent from sudden active network change caused by previous
+ // executed tests.
+ if (mPackageManager.hasSystemFeature(FEATURE_WIFI)) {
+ final Network expectedDefaultNetwork = mCtsNetUtils.ensureWifiConnected();
+ mCtsNetUtils.expectNetworkIsSystemDefault(expectedDefaultNetwork);
+ }
+
final DetailedBlockedStatusCallback myUidCallback = new DetailedBlockedStatusCallback();
final DetailedBlockedStatusCallback otherUidCallback = new DetailedBlockedStatusCallback();
diff --git a/tests/cts/net/util/java/android/net/cts/util/CtsNetUtils.java b/tests/cts/net/util/java/android/net/cts/util/CtsNetUtils.java
index 3f2ff9d..df3a4aa 100644
--- a/tests/cts/net/util/java/android/net/cts/util/CtsNetUtils.java
+++ b/tests/cts/net/util/java/android/net/cts/util/CtsNetUtils.java
@@ -170,7 +170,7 @@
}
}
- private Network expectNetworkIsSystemDefault(Network network)
+ public Network expectNetworkIsSystemDefault(Network network)
throws Exception {
final CompletableFuture<Network> future = new CompletableFuture();
final NetworkCallback cb = new NetworkCallback() {