Add SkipNativeNetworkCreation flag in NetworkAgentConfig

This flag allows ConnectivityService to skip native network creation,
deferring this responsibility to Tethering. This is necessary because:

- ConnectivityService requires the NetworkAgent to be in the CONNECTED
  state to configure routing and invokes NetworkCallback#onAvailable
  once ready.
- Tethering requires lower-layer interactions to be completed before
  notifying applications.

This approach ensures proper synchronization between ConnectivityService
and Tethering during network setup.

Long-term, all netd operations should be handled by ConnectivityService
when it supports early native network creation in the CONNECTING state.

As a mid-term solution, this flag enables Tethering to manage native
network creation within the IpServer.

Test: atest ConnectivityCoverageTests:android.net.connectivity.android.net.NetworkAgentConfigTest
Bug: 349487600
Change-Id: I84da9c74dc4d40c7cd36c6657f17a158affed689
This commit is contained in:
Junyu Lai 2024-12-04 13:52:35 +08:00
commit fef111ce47

View file

@ -20,6 +20,7 @@ import androidx.test.filters.SmallTest
import androidx.test.runner.AndroidJUnit4
import com.android.modules.utils.build.SdkLevel.isAtLeastS
import com.android.modules.utils.build.SdkLevel.isAtLeastT
import com.android.modules.utils.build.SdkLevel.isAtLeastV
import com.android.testutils.ConnectivityModuleTest
import com.android.testutils.assertParcelingIsLossless
import org.junit.Assert.assertEquals
@ -47,6 +48,9 @@ class NetworkAgentConfigTest {
setLocalRoutesExcludedForVpn(true)
setVpnRequiresValidation(true)
}
if (isAtLeastV()) {
setSkipNativeNetworkCreation(true)
}
}.build()
assertParcelingIsLossless(config)
}
@ -71,6 +75,9 @@ class NetworkAgentConfigTest {
setLocalRoutesExcludedForVpn(true)
setVpnRequiresValidation(true)
}
if (isAtLeastV()) {
setSkipNativeNetworkCreation(true)
}
}.build()
assertTrue(config.isExplicitlySelected())
@ -79,6 +86,9 @@ class NetworkAgentConfigTest {
assertFalse(config.isPartialConnectivityAcceptable())
assertTrue(config.isUnvalidatedConnectivityAcceptable())
assertEquals("TEST_NETWORK", config.getLegacyTypeName())
if (isAtLeastV()) {
assertTrue(config.shouldSkipNativeNetworkCreation())
}
if (isAtLeastT()) {
assertTrue(config.areLocalRoutesExcludedForVpn())
assertTrue(config.isVpnValidationRequired())