Merge "Enable early native network creation for local network" into main am: daa1f52b02

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/3526892

Change-Id: Iffce67f2b702d7145f0490da001f9060678ff83e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot 2025-03-09 21:22:21 -07:00 • committed by Automerger Merge Worker
commit 08256f7c14
2 changed files with 19 additions and 19 deletions

View file

@ -5405,12 +5405,12 @@ public class ConnectivityService extends IConnectivityManager.Stub {
}
@VisibleForTesting
protected static boolean shouldCreateNetworksImmediately() {
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 : enable this in a Mainline update or in V, and re-enable the test for this
// in NetworkAgentTest.
return false;
return caps.hasCapability(NET_CAPABILITY_LOCAL_NETWORK);
}
private static boolean shouldCreateNativeNetwork(@NonNull NetworkAgentInfo nai,
@ -5419,12 +5419,12 @@ public class ConnectivityService extends IConnectivityManager.Stub {
if (state == NetworkInfo.State.CONNECTED) return true;
if (state != NetworkInfo.State.CONNECTING) {
// TODO: throw if no WTFs are observed in the field.
if (shouldCreateNetworksImmediately()) {
if (shouldCreateNetworksImmediately(nai.getCapsNoCopy())) {
Log.wtf(TAG, "Uncreated network in invalid state: " + state);
}
return false;
}
return nai.isVPN() || shouldCreateNetworksImmediately();
return nai.isVPN() || shouldCreateNetworksImmediately(nai.getCapsNoCopy());
}
private static boolean shouldDestroyNativeNetwork(@NonNull NetworkAgentInfo nai) {
@ -12048,7 +12048,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
// interfaces and routing rules have been added, DNS servers programmed, etc.
// For VPNs, this must be done before the capabilities are updated, because as soon as
// that happens, UIDs are routed to the network.
if (shouldCreateNetworksImmediately()) {
if (shouldCreateNetworksImmediately(networkAgent.getCapsNoCopy())) {
applyInitialLinkProperties(networkAgent);
}
@ -12073,7 +12073,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
networkAgent.getAndSetNetworkCapabilities(networkAgent.networkCapabilities);
handlePerNetworkPrivateDnsConfig(networkAgent, mDnsManager.getPrivateDnsConfig());
if (!shouldCreateNetworksImmediately()) {
if (!shouldCreateNetworksImmediately(networkAgent.getCapsNoCopy())) {
applyInitialLinkProperties(networkAgent);
} else {
// The network was created when the agent registered, and the LinkProperties are

View file

@ -4040,7 +4040,7 @@ public class ConnectivityServiceTest {
mWiFiAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI, callbacks);
if (mService.shouldCreateNetworksImmediately()) {
if (mService.shouldCreateNetworksImmediately(mWiFiAgent.getNetworkCapabilities())) {
assertEquals("onNetworkCreated", eventOrder.poll(TIMEOUT_MS, TimeUnit.MILLISECONDS));
} else {
assertNull(eventOrder.poll());
@ -4053,7 +4053,7 @@ public class ConnectivityServiceTest {
// connected.
// TODO: fix this bug, file the request before connecting, and remove the waitForIdle.
mWiFiAgent.connectWithoutInternet();
if (!mService.shouldCreateNetworksImmediately()) {
if (!mService.shouldCreateNetworksImmediately(mWiFiAgent.getNetworkCapabilities())) {
assertEquals("onNetworkCreated", eventOrder.poll(TIMEOUT_MS, TimeUnit.MILLISECONDS));
} else {
waitForIdle();
@ -7941,8 +7941,8 @@ public class ConnectivityServiceTest {
// Simple connection with initial LP should have updated ifaces.
mCellAgent.connect(false);
waitForIdle();
List<Network> allNetworks = mService.shouldCreateNetworksImmediately()
? cellAndWifi() : onlyCell();
List<Network> allNetworks = mService.shouldCreateNetworksImmediately(
mCellAgent.getNetworkCapabilities()) ? cellAndWifi() : onlyCell();
expectNotifyNetworkStatus(allNetworks, onlyCell(), MOBILE_IFNAME);
reset(mStatsManager);
@ -8254,7 +8254,7 @@ public class ConnectivityServiceTest {
mCellAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR);
final int netId = mCellAgent.getNetwork().netId;
waitForIdle();
if (mService.shouldCreateNetworksImmediately()) {
if (mService.shouldCreateNetworksImmediately(mCellAgent.getNetworkCapabilities())) {
verify(mMockDnsResolver, times(1)).createNetworkCache(netId);
} else {
verify(mMockDnsResolver, never()).setResolverConfiguration(any());
@ -8274,7 +8274,7 @@ public class ConnectivityServiceTest {
mCellAgent.sendLinkProperties(cellLp);
mCellAgent.connect(false);
waitForIdle();
if (!mService.shouldCreateNetworksImmediately()) {
if (!mService.shouldCreateNetworksImmediately(mCellAgent.getNetworkCapabilities())) {
// CS tells dnsresolver about the empty DNS config for this network.
verify(mMockDnsResolver, times(1)).createNetworkCache(netId);
}
@ -8397,7 +8397,7 @@ public class ConnectivityServiceTest {
mCellAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR);
final int netId = mCellAgent.getNetwork().netId;
waitForIdle();
if (mService.shouldCreateNetworksImmediately()) {
if (mService.shouldCreateNetworksImmediately(mCellAgent.getNetworkCapabilities())) {
verify(mMockDnsResolver, times(1)).createNetworkCache(netId);
} else {
verify(mMockDnsResolver, never()).setResolverConfiguration(any());
@ -8420,7 +8420,7 @@ public class ConnectivityServiceTest {
mCellAgent.sendLinkProperties(cellLp);
mCellAgent.connect(false);
waitForIdle();
if (!mService.shouldCreateNetworksImmediately()) {
if (!mService.shouldCreateNetworksImmediately(mCellAgent.getNetworkCapabilities())) {
verify(mMockDnsResolver, times(1)).createNetworkCache(netId);
}
verify(mMockDnsResolver, atLeastOnce()).setResolverConfiguration(
@ -16065,13 +16065,13 @@ public class ConnectivityServiceTest {
final TestNetworkAgentWrapper workAgent =
makeEnterpriseNetworkAgent(profileNetworkPreference.getPreferenceEnterpriseId());
if (mService.shouldCreateNetworksImmediately()) {
if (mService.shouldCreateNetworksImmediately(workAgent.getNetworkCapabilities())) {
expectNativeNetworkCreated(workAgent.getNetwork().netId, INetd.PERMISSION_SYSTEM,
null /* iface */, inOrder);
}
if (connectWorkProfileAgentAhead) {
workAgent.connect(false);
if (!mService.shouldCreateNetworksImmediately()) {
if (!mService.shouldCreateNetworksImmediately(workAgent.getNetworkCapabilities())) {
expectNativeNetworkCreated(workAgent.getNetwork().netId, INetd.PERMISSION_SYSTEM,
null /* iface */, inOrder);
}
@ -16114,7 +16114,7 @@ public class ConnectivityServiceTest {
if (!connectWorkProfileAgentAhead) {
workAgent.connect(false);
if (!mService.shouldCreateNetworksImmediately()) {
if (!mService.shouldCreateNetworksImmediately(workAgent.getNetworkCapabilities())) {
inOrder.verify(mMockNetd).networkCreate(
nativeNetworkConfigPhysical(workAgent.getNetwork().netId,
INetd.PERMISSION_SYSTEM));
@ -18825,7 +18825,7 @@ public class ConnectivityServiceTest {
}
private void verifyMtuSetOnWifiInterfaceOnlyUpToT(int mtu) throws Exception {
if (!mService.shouldCreateNetworksImmediately()) {
if (!mService.shouldCreateNetworksImmediately(mWiFiAgent.getNetworkCapabilities())) {
verify(mMockNetd, times(1)).interfaceSetMtu(WIFI_IFNAME, mtu);
} else {
verify(mMockNetd, never()).interfaceSetMtu(eq(WIFI_IFNAME), anyInt());
@ -18833,7 +18833,7 @@ public class ConnectivityServiceTest {
}
private void verifyMtuSetOnWifiInterfaceOnlyStartingFromU(int mtu) throws Exception {
if (mService.shouldCreateNetworksImmediately()) {
if (mService.shouldCreateNetworksImmediately(mWiFiAgent.getNetworkCapabilities())) {
verify(mMockNetd, times(1)).interfaceSetMtu(WIFI_IFNAME, mtu);
} else {
verify(mMockNetd, never()).interfaceSetMtu(eq(WIFI_IFNAME), anyInt());