From a16607f421ecfbf37ef8fb2fa96d4d285df9e77b Mon Sep 17 00:00:00 2001 From: Chalard Jean Date: Tue, 27 Jun 2023 19:16:00 +0900 Subject: [PATCH] Never create native network immediately. This patch flags off the functionality added by aosp/2162425 in the wake of b/286649301 where a race in ConnectivityService breaks WiFi connectivity until reboot. Bug: 286649301 Test: NetworkAgentTest ConnectivityServiceTest Change-Id: I96d755445f6e1f88bb71a7d32742e87dae185250 --- .../android/server/ConnectivityService.java | 8 +++++--- .../src/android/net/cts/NetworkAgentTest.kt | 20 ++++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java index 32c3b190d1..83afa83d07 100755 --- a/service/src/com/android/server/ConnectivityService.java +++ b/service/src/com/android/server/ConnectivityService.java @@ -4548,9 +4548,11 @@ public class ConnectivityService extends IConnectivityManager.Stub @VisibleForTesting protected static boolean shouldCreateNetworksImmediately() { - // Before U, physical networks are only created when the agent advances to CONNECTED. - // In U and above, all networks are immediately created when the agent is registered. - return SdkLevel.isAtLeastU(); + // The feature of creating the networks immediately was slated for U, but race conditions + // detected late required this was flagged off. + // TODO : enable this in a Mainline update or in V, and re-enable the test for this + // in NetworkAgentTest. + return false; } private static boolean shouldCreateNativeNetwork(@NonNull NetworkAgentInfo nai, diff --git a/tests/cts/net/src/android/net/cts/NetworkAgentTest.kt b/tests/cts/net/src/android/net/cts/NetworkAgentTest.kt index cf5fc50f04..98ea2248bd 100644 --- a/tests/cts/net/src/android/net/cts/NetworkAgentTest.kt +++ b/tests/cts/net/src/android/net/cts/NetworkAgentTest.kt @@ -164,6 +164,12 @@ private fun Message(what: Int, arg1: Int, arg2: Int, obj: Any?) = Message.obtain it.obj = obj } +// On T and below, the native network is only created when the agent connects. +// Starting in U, the native network was to be created as soon as the agent is registered, +// but this has been flagged off for now pending resolution of race conditions. +// TODO : enable this in a Mainline update or in V. +private const val SHOULD_CREATE_NETWORKS_IMMEDIATELY = false + @RunWith(DevSdkIgnoreRunner::class) // NetworkAgent is not updatable in R-, so this test does not need to be compatible with older // versions. NetworkAgent was also based on AsyncChannel before S so cannot be tested the same way. @@ -1302,7 +1308,7 @@ class NetworkAgentTest { requestNetwork(makeTestNetworkRequest(specifier = specifier6), callback) val agent6 = createNetworkAgent(specifier = specifier6) val network6 = agent6.register() - if (SdkLevel.isAtLeastU()) { + if (SHOULD_CREATE_NETWORKS_IMMEDIATELY) { agent6.expectCallback() } else { // No callbacks are sent, so check LinkProperties to wait for the network to be created. @@ -1316,9 +1322,10 @@ class NetworkAgentTest { val timeoutMs = agent6.DEFAULT_TIMEOUT_MS.toInt() + 1_000 agent6.unregisterAfterReplacement(timeoutMs) agent6.expectCallback() - if (!SdkLevel.isAtLeastT() || SdkLevel.isAtLeastU()) { + if (!SdkLevel.isAtLeastT() || SHOULD_CREATE_NETWORKS_IMMEDIATELY) { // Before T, onNetworkDestroyed is called even if the network was never created. - // On U+, the network was created by register(). Destroying it sends onNetworkDestroyed. + // If immediate native network creation is supported, the network was created by + // register(). Destroying it sends onNetworkDestroyed. agent6.expectCallback() } // Poll for LinkProperties becoming null, because when onNetworkUnwanted is called, the @@ -1477,10 +1484,9 @@ class NetworkAgentTest { @Test fun testNativeNetworkCreation_PhysicalNetwork() { - // On T and below, the native network is only created when the agent connects. - // Starting in U, the native network is created as soon as the agent is registered. - doTestNativeNetworkCreation(expectCreatedImmediately = SdkLevel.isAtLeastU(), - intArrayOf(TRANSPORT_CELLULAR)) + doTestNativeNetworkCreation( + expectCreatedImmediately = SHOULD_CREATE_NETWORKS_IMMEDIATELY, + intArrayOf(TRANSPORT_CELLULAR)) } @Test