From 0141d82c2ded3a2272ccb076ef3d0c75363ba8d4 Mon Sep 17 00:00:00 2001 From: Satish Yalla Date: Wed, 19 Mar 2025 20:18:37 -0700 Subject: [PATCH] Revert "Immediately create networks unless chickened out" Revert submission 3548747 Reason for revert: Droidmonitor created revert due to b/404956859. Will be verified through ABTD for standard investigation. Reverted changes: /q/submissionid:3548747 Change-Id: Ic4226f2f1a20965f80b554967568a4450e460da2 --- .../android/server/ConnectivityService.java | 14 +++++------- .../src/android/net/cts/NetworkAgentTest.kt | 22 +++++-------------- 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java index e27b72d2ce..48a825aa25 100644 --- a/service/src/com/android/server/ConnectivityService.java +++ b/service/src/com/android/server/ConnectivityService.java @@ -113,7 +113,6 @@ import static android.net.NetworkCapabilities.RES_ID_MATCH_ALL_RESERVATIONS; import static android.net.NetworkCapabilities.RES_ID_UNSET; import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR; import static android.net.NetworkCapabilities.TRANSPORT_TEST; -import static android.net.NetworkCapabilities.TRANSPORT_THREAD; import static android.net.NetworkCapabilities.TRANSPORT_VPN; import static android.net.NetworkCapabilities.TRANSPORT_WIFI; import static android.net.NetworkRequest.Type.LISTEN_FOR_BEST; @@ -5449,18 +5448,15 @@ public class ConnectivityService extends IConnectivityManager.Stub { } @VisibleForTesting - protected boolean shouldCreateNetworksImmediately(@NonNull NetworkCapabilities caps) { + protected static boolean shouldCreateNetworksImmediately(@NonNull NetworkCapabilities caps) { // The feature of creating the networks immediately was slated for U, but race conditions // detected late required this was flagged off. - // TODO : remove when it's determined that the code is stable - return mQueueNetworkAgentEventsInSystemServer - // Local network agents for Thread used to not create networks immediately, - // but other local agents (tethering, P2P) require this to function. - || (caps.hasCapability(NET_CAPABILITY_LOCAL_NETWORK) - && !caps.hasTransport(TRANSPORT_THREAD)); + // TODO : enable this in a Mainline update or in V, and re-enable the test for this + // in NetworkAgentTest. + return caps.hasCapability(NET_CAPABILITY_LOCAL_NETWORK); } - private boolean shouldCreateNativeNetwork(@NonNull NetworkAgentInfo nai, + private static boolean shouldCreateNativeNetwork(@NonNull NetworkAgentInfo nai, @NonNull NetworkInfo.State state) { if (nai.isCreated()) return false; if (state == NetworkInfo.State.CONNECTED) return true; diff --git a/tests/cts/net/src/android/net/cts/NetworkAgentTest.kt b/tests/cts/net/src/android/net/cts/NetworkAgentTest.kt index 4c3bce0baf..92155c3287 100644 --- a/tests/cts/net/src/android/net/cts/NetworkAgentTest.kt +++ b/tests/cts/net/src/android/net/cts/NetworkAgentTest.kt @@ -179,10 +179,6 @@ private const val TAG = "NetworkAgentTest" // without affecting the run time of successful runs. Thus, set a very high timeout. private const val DEFAULT_TIMEOUT_MS = 5000L -private const val QUEUE_NETWORK_AGENT_EVENTS_IN_SYSTEM_SERVER = - "queue_network_agent_events_in_system_server" - - // When waiting for a NetworkCallback to determine there was no timeout, waiting is the // only possible thing (the relevant handler is the one in the real ConnectivityService, // and then there is the Binder call), so have a short timeout for this as it will be @@ -207,6 +203,12 @@ private val REMOTE_ADDRESS = InetAddresses.parseNumericAddress("2001:db8::123") private val PREFIX = IpPrefix("2001:db8::/64") private val NEXTHOP = InetAddresses.parseNumericAddress("fe80::abcd") +// 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 + @AppModeFull(reason = "Instant apps can't use NetworkAgent because it needs NETWORK_FACTORY'.") // NetworkAgent is updated as part of the connectivity module, and running NetworkAgent tests in MTS // for modules other than Connectivity does not provide much value. Only run them in connectivity @@ -232,18 +234,6 @@ class NetworkAgentTest { private var qosTestSocket: Closeable? = null // either Socket or DatagramSocket private val ifacesToCleanUp = mutableListOf() - // Unless the queuing in system server feature is chickened out, native networks are created - // immediately. Historically they would only created as they'd connect, which would force - // the code to apply link properties multiple times and suffer errors early on. Creating - // them early required that ordering between the client and the system server is guaranteed - // (at least to some extent), which has been done by moving the event queue from the client - // to the system server. When that feature is not chickened out, create networks immediately. - private val SHOULD_CREATE_NETWORKS_IMMEDIATELY - get() = mCM.isConnectivityServiceFeatureEnabledForTesting( - QUEUE_NETWORK_AGENT_EVENTS_IN_SYSTEM_SERVER - ) - - @Before fun setUp() { instrumentation.getUiAutomation().adoptShellPermissionIdentity()