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
This commit is contained in:
@@ -4548,9 +4548,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected static boolean shouldCreateNetworksImmediately() {
|
protected static boolean shouldCreateNetworksImmediately() {
|
||||||
// Before U, physical networks are only created when the agent advances to CONNECTED.
|
// The feature of creating the networks immediately was slated for U, but race conditions
|
||||||
// In U and above, all networks are immediately created when the agent is registered.
|
// detected late required this was flagged off.
|
||||||
return SdkLevel.isAtLeastU();
|
// 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,
|
private static boolean shouldCreateNativeNetwork(@NonNull NetworkAgentInfo nai,
|
||||||
|
|||||||
@@ -164,6 +164,12 @@ private fun Message(what: Int, arg1: Int, arg2: Int, obj: Any?) = Message.obtain
|
|||||||
it.obj = obj
|
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)
|
@RunWith(DevSdkIgnoreRunner::class)
|
||||||
// NetworkAgent is not updatable in R-, so this test does not need to be compatible with older
|
// 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.
|
// 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)
|
requestNetwork(makeTestNetworkRequest(specifier = specifier6), callback)
|
||||||
val agent6 = createNetworkAgent(specifier = specifier6)
|
val agent6 = createNetworkAgent(specifier = specifier6)
|
||||||
val network6 = agent6.register()
|
val network6 = agent6.register()
|
||||||
if (SdkLevel.isAtLeastU()) {
|
if (SHOULD_CREATE_NETWORKS_IMMEDIATELY) {
|
||||||
agent6.expectCallback<OnNetworkCreated>()
|
agent6.expectCallback<OnNetworkCreated>()
|
||||||
} else {
|
} else {
|
||||||
// No callbacks are sent, so check LinkProperties to wait for the network to be created.
|
// 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
|
val timeoutMs = agent6.DEFAULT_TIMEOUT_MS.toInt() + 1_000
|
||||||
agent6.unregisterAfterReplacement(timeoutMs)
|
agent6.unregisterAfterReplacement(timeoutMs)
|
||||||
agent6.expectCallback<OnNetworkUnwanted>()
|
agent6.expectCallback<OnNetworkUnwanted>()
|
||||||
if (!SdkLevel.isAtLeastT() || SdkLevel.isAtLeastU()) {
|
if (!SdkLevel.isAtLeastT() || SHOULD_CREATE_NETWORKS_IMMEDIATELY) {
|
||||||
// Before T, onNetworkDestroyed is called even if the network was never created.
|
// 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<OnNetworkDestroyed>()
|
agent6.expectCallback<OnNetworkDestroyed>()
|
||||||
}
|
}
|
||||||
// Poll for LinkProperties becoming null, because when onNetworkUnwanted is called, the
|
// Poll for LinkProperties becoming null, because when onNetworkUnwanted is called, the
|
||||||
@@ -1477,10 +1484,9 @@ class NetworkAgentTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testNativeNetworkCreation_PhysicalNetwork() {
|
fun testNativeNetworkCreation_PhysicalNetwork() {
|
||||||
// On T and below, the native network is only created when the agent connects.
|
doTestNativeNetworkCreation(
|
||||||
// Starting in U, the native network is created as soon as the agent is registered.
|
expectCreatedImmediately = SHOULD_CREATE_NETWORKS_IMMEDIATELY,
|
||||||
doTestNativeNetworkCreation(expectCreatedImmediately = SdkLevel.isAtLeastU(),
|
intArrayOf(TRANSPORT_CELLULAR))
|
||||||
intArrayOf(TRANSPORT_CELLULAR))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user