From 846032e9455640b534a57ab0175c81d951b35fdf Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 27 Jul 2023 03:37:43 +0000 Subject: [PATCH 01/16] Fix ConnectivityManagerTest#testFactoryReset flaky Listen SoftAp callback to make sure soft ap is disabled before start hotspot. Bug: 277856014 Test: atest ConnectivityManagerTest#testFactoryReset (cherry picked from https://android-review.googlesource.com/q/commit:5fab2d6c17c4ecdd6673e882f53f29d2136a23b0) Merged-In: I95050be703b7c97da7a14541ac74718fdcbd7f13 Change-Id: I95050be703b7c97da7a14541ac74718fdcbd7f13 --- tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java index f0ad3f1e2d..4451a88efb 100644 --- a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java +++ b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java @@ -2591,6 +2591,7 @@ public class ConnectivityManagerTest { // prevent the race condition between airplane mode enabled and the followed // up wifi tethering enabled. tetherEventCallback.expectNoTetheringActive(); + tetherUtils.expectSoftApDisabled(); // start wifi tethering tetherUtils.startWifiTethering(tetherEventCallback); From 4d5e98e41c71cff78328b6c3a6d972935ab6631d Mon Sep 17 00:00:00 2001 From: Mark Date: Mon, 3 Jul 2023 09:23:55 +0000 Subject: [PATCH 02/16] Don't run EthernetTetheringTest if Ethernet is not supported Bug: 288844185 Test: atest CtsTetheringTest (cherry picked from https://android-review.googlesource.com/q/commit:dc581e6c8ff1a5b956ba41b2eb1fcdc7a11e1e65) Merged-In: Ie918a0657ab17900437918f7ae99f7aa2539052c Change-Id: Ie918a0657ab17900437918f7ae99f7aa2539052c --- .../base/android/net/EthernetTetheringTestBase.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Tethering/tests/integration/base/android/net/EthernetTetheringTestBase.java b/Tethering/tests/integration/base/android/net/EthernetTetheringTestBase.java index 007bf23a1c..dfb4aa5f72 100644 --- a/Tethering/tests/integration/base/android/net/EthernetTetheringTestBase.java +++ b/Tethering/tests/integration/base/android/net/EthernetTetheringTestBase.java @@ -184,13 +184,18 @@ public abstract class EthernetTetheringTestBase { mHandlerThread.start(); mHandler = new Handler(mHandlerThread.getLooper()); - mRunTests = runAsShell(NETWORK_SETTINGS, TETHER_PRIVILEGED, () -> - mTm.isTetheringSupported()); + mRunTests = isEthernetTetheringSupported(); assumeTrue(mRunTests); mTetheredInterfaceRequester = new TetheredInterfaceRequester(mHandler, mEm); } + private boolean isEthernetTetheringSupported() throws Exception { + if (mEm == null) return false; + + return runAsShell(NETWORK_SETTINGS, TETHER_PRIVILEGED, () -> mTm.isTetheringSupported()); + } + protected void maybeStopTapPacketReader(final TapPacketReader tapPacketReader) throws Exception { if (tapPacketReader != null) { From 861d32d0e01b0db8209167aa346f40424e64c7f6 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Wed, 6 Sep 2023 16:06:07 +0900 Subject: [PATCH 03/16] Fix lint errors in ProcNetTest. Test: test-only change (cherry picked from https://android-review.googlesource.com/q/commit:ab5e0c98f08a22fc99914e95e71825c179a92475) Merged-In: If3702cf9c3a36e3b7cb1853784f1a8ff98d7be07 Change-Id: If3702cf9c3a36e3b7cb1853784f1a8ff98d7be07 --- tests/cts/hostside/src/com/android/cts/net/ProcNetTest.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/cts/hostside/src/com/android/cts/net/ProcNetTest.java b/tests/cts/hostside/src/com/android/cts/net/ProcNetTest.java index 1a528b112b..b4964c1d62 100644 --- a/tests/cts/hostside/src/com/android/cts/net/ProcNetTest.java +++ b/tests/cts/hostside/src/com/android/cts/net/ProcNetTest.java @@ -22,11 +22,9 @@ import com.android.tradefed.testtype.DeviceTestCase; import com.android.tradefed.testtype.IBuildReceiver; import com.android.tradefed.testtype.IDeviceTest; -import java.lang.Integer; -import java.lang.String; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.ArrayList; /** * Host-side tests for values in /proc/net. From d0a655296ad0e167e9b598ab074adde91e78eb59 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Wed, 6 Sep 2023 17:01:19 +0900 Subject: [PATCH 04/16] Convert ProcNetTest to JUnit4. This allows using assumptions to skip tests. Test: atest CtsHostsideNetworkTests (cherry picked from https://android-review.googlesource.com/q/commit:9ae344b81ad53269f8b7c7d305fbf8f87c6d7ccc) Merged-In: Ic1fc41c1ca0c30b6b7350c413d710d959b9a5013 Change-Id: Ic1fc41c1ca0c30b6b7350c413d710d959b9a5013 --- .../src/com/android/cts/net/ProcNetTest.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/tests/cts/hostside/src/com/android/cts/net/ProcNetTest.java b/tests/cts/hostside/src/com/android/cts/net/ProcNetTest.java index b4964c1d62..e45ff82a17 100644 --- a/tests/cts/hostside/src/com/android/cts/net/ProcNetTest.java +++ b/tests/cts/hostside/src/com/android/cts/net/ProcNetTest.java @@ -16,11 +16,19 @@ package android.security.cts; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import com.android.tradefed.build.IBuildInfo; import com.android.tradefed.device.ITestDevice; -import com.android.tradefed.testtype.DeviceTestCase; +import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; import com.android.tradefed.testtype.IBuildReceiver; import com.android.tradefed.testtype.IDeviceTest; +import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; import java.util.ArrayList; import java.util.Arrays; @@ -31,7 +39,8 @@ import java.util.List; * * These tests analyze /proc/net to verify that certain networking properties are correct. */ -public class ProcNetTest extends DeviceTestCase implements IBuildReceiver, IDeviceTest { +@RunWith(DeviceJUnit4ClassRunner.class) +public class ProcNetTest extends BaseHostJUnit4Test implements IBuildReceiver, IDeviceTest { private static final String SPI_TIMEOUT_SYSCTL = "/proc/sys/net/core/xfrm_acq_expires"; private static final int MIN_ACQ_EXPIRES = 3600; // Global sysctls. Must be present and set to 1. @@ -70,13 +79,12 @@ public class ProcNetTest extends DeviceTestCase implements IBuildReceiver, IDevi */ @Override public void setDevice(ITestDevice device) { - super.setDevice(device); mDevice = device; } - @Override - protected void setUp() throws Exception { - super.setUp(); + /** Run before each test case. */ + @Before + public void setUp() throws Exception { mSysctlDirs = getSysctlDirs(); } @@ -111,6 +119,7 @@ public class ProcNetTest extends DeviceTestCase implements IBuildReceiver, IDevi /** * Checks that SPI default timeouts are overridden, and set to a reasonable length of time */ + @Test public void testMinAcqExpires() throws Exception { int value = readIntFromPath(SPI_TIMEOUT_SYSCTL); assertAtLeast(SPI_TIMEOUT_SYSCTL, value, MIN_ACQ_EXPIRES); @@ -120,6 +129,7 @@ public class ProcNetTest extends DeviceTestCase implements IBuildReceiver, IDevi * Checks that the sysctls for multinetwork kernel features are present and * enabled. */ + @Test public void testProcSysctls() throws Exception { for (String sysctl : GLOBAL_SYSCTLS) { int value = readIntFromPath(sysctl); @@ -136,6 +146,7 @@ public class ProcNetTest extends DeviceTestCase implements IBuildReceiver, IDevi /** * Verify that accept_ra_rt_info_{min,max}_plen exists and is set to the expected value */ + @Test public void testAcceptRaRtInfoMinMaxPlen() throws Exception { for (String interfaceDir : mSysctlDirs) { String path = IPV6_SYSCTL_DIR + "/" + interfaceDir + "/" + "accept_ra_rt_info_min_plen"; @@ -151,6 +162,7 @@ public class ProcNetTest extends DeviceTestCase implements IBuildReceiver, IDevi * Verify that router_solicitations exists and is set to the expected value * and verify that router_solicitation_max_interval exists and is in an acceptable interval. */ + @Test public void testRouterSolicitations() throws Exception { for (String interfaceDir : mSysctlDirs) { String path = IPV6_SYSCTL_DIR + "/" + interfaceDir + "/" + "router_solicitations"; @@ -170,6 +182,7 @@ public class ProcNetTest extends DeviceTestCase implements IBuildReceiver, IDevi * (This repeats the VTS test, and is here for good performance of the internet as a whole.) * TODO: revisit this once a better CC algorithm like BBR2 is available. */ + @Test public void testCongestionControl() throws Exception { String path = "/proc/sys/net/ipv4/tcp_congestion_control"; String value = mDevice.executeAdbCommand("shell", "cat", path).trim(); From 2444b11b335ae1518d64ffecd2878908298395a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Wed, 6 Sep 2023 06:49:20 +0000 Subject: [PATCH 05/16] cts: enforce cubic only on V+ Test: TreeHugger Bug: 291025434 Bug: 289802481 Bug: 294510745 (cherry picked from https://android-review.googlesource.com/q/commit:9fe823e34fb9c35b618b550dd1b81d98f5125140) Merged-In: I3c9646468834305e48c531040640e05f80b1c5e7 Change-Id: I3c9646468834305e48c531040640e05f80b1c5e7 --- tests/cts/hostside/src/com/android/cts/net/ProcNetTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/cts/hostside/src/com/android/cts/net/ProcNetTest.java b/tests/cts/hostside/src/com/android/cts/net/ProcNetTest.java index e45ff82a17..adaac6d892 100644 --- a/tests/cts/hostside/src/com/android/cts/net/ProcNetTest.java +++ b/tests/cts/hostside/src/com/android/cts/net/ProcNetTest.java @@ -18,7 +18,9 @@ package android.security.cts; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeTrue; +import com.android.modules.utils.build.testing.DeviceSdkLevel; import com.android.tradefed.build.IBuildInfo; import com.android.tradefed.device.ITestDevice; import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; @@ -184,6 +186,9 @@ public class ProcNetTest extends BaseHostJUnit4Test implements IBuildReceiver, I */ @Test public void testCongestionControl() throws Exception { + final DeviceSdkLevel dsl = new DeviceSdkLevel(mDevice); + assumeTrue(dsl.isDeviceAtLeastV()); + String path = "/proc/sys/net/ipv4/tcp_congestion_control"; String value = mDevice.executeAdbCommand("shell", "cat", path).trim(); assertEquals(value, "cubic"); From b018cb45dbaf454889e66a7fa860941d7d05421e Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 27 Jun 2023 08:54:23 +0000 Subject: [PATCH 06/16] Revert "Always disconnect agents immediately." This reverts commit 4bc9fa6b8cefca88f1065e95df06532979c202ee. Reason for revert: b/288450518 Some iterations over mNetworkAgentInfos result in networks being disconnected, which removes them from mNetworkAgentInfos during iteration. This crashes with NPE or OOB exceptions. Bug: 286649301 Bug: 288149251 Bug: 288450518 (cherry picked from https://android-review.googlesource.com/q/commit:3160bc0825490353d79c6586e21a7fc5893c678d) Merged-In: I6e0b5b614d9e88267db77cb807ae4bf09f88c0f6 Change-Id: I6e0b5b614d9e88267db77cb807ae4bf09f88c0f6 --- .../com/android/server/ConnectivityService.java | 16 ++++++---------- .../net/src/android/net/cts/NetworkAgentTest.kt | 13 ++++++------- .../android/server/ConnectivityServiceTest.java | 10 ++++------ 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java index 5e14be5852..28d1d73881 100755 --- a/service/src/com/android/server/ConnectivityService.java +++ b/service/src/com/android/server/ConnectivityService.java @@ -319,6 +319,7 @@ import java.io.IOException; import java.io.InterruptedIOException; import java.io.PrintWriter; import java.io.Writer; +import java.lang.IllegalArgumentException; import java.net.Inet4Address; import java.net.InetAddress; import java.net.InetSocketAddress; @@ -4011,7 +4012,7 @@ public class ConnectivityService extends IConnectivityManager.Stub // the destroyed flag is only just above the "current satisfier wins" // tie-breaker. But technically anything that affects scoring should rematch. rematchAllNetworksAndRequests(); - mHandler.postDelayed(() -> disconnectAndDestroyNetwork(nai), timeoutMs); + mHandler.postDelayed(() -> nai.disconnect(), timeoutMs); break; } } @@ -4610,9 +4611,6 @@ public class ConnectivityService extends IConnectivityManager.Stub if (DBG) { log(nai.toShortString() + " disconnected, was satisfying " + nai.numNetworkRequests()); } - - nai.disconnect(); - // Clear all notifications of this network. mNotifier.clearNotification(nai.network.getNetId()); // A network agent has disconnected. @@ -5897,7 +5895,7 @@ public class ConnectivityService extends IConnectivityManager.Stub final NetworkAgentInfo nai = getNetworkAgentInfoForNetwork((Network) msg.obj); if (nai == null) break; nai.onPreventAutomaticReconnect(); - disconnectAndDestroyNetwork(nai); + nai.disconnect(); break; case EVENT_SET_VPN_NETWORK_PREFERENCE: handleSetVpnNetworkPreference((VpnNetworkPreferenceInfo) msg.obj); @@ -9044,7 +9042,7 @@ public class ConnectivityService extends IConnectivityManager.Stub break; } } - disconnectAndDestroyNetwork(nai); + nai.disconnect(); } private void handleLingerComplete(NetworkAgentInfo oldNetwork) { @@ -9586,10 +9584,7 @@ public class ConnectivityService extends IConnectivityManager.Stub updateLegacyTypeTrackerAndVpnLockdownForRematch(changes, nais); // Tear down all unneeded networks. - // Iterate in reverse order because teardownUnneededNetwork removes the nai from - // mNetworkAgentInfos. - for (int i = mNetworkAgentInfos.size() - 1; i >= 0; i--) { - final NetworkAgentInfo nai = mNetworkAgentInfos.valueAt(i); + for (NetworkAgentInfo nai : mNetworkAgentInfos) { if (unneeded(nai, UnneededFor.TEARDOWN)) { if (nai.getInactivityExpiry() > 0) { // This network has active linger timers and no requests, but is not @@ -9972,6 +9967,7 @@ public class ConnectivityService extends IConnectivityManager.Stub // This has to happen after matching the requests, because callbacks are just requests. notifyNetworkCallbacks(networkAgent, ConnectivityManager.CALLBACK_PRECHECK); } else if (state == NetworkInfo.State.DISCONNECTED) { + networkAgent.disconnect(); if (networkAgent.isVPN()) { updateVpnUids(networkAgent, networkAgent.networkCapabilities, null); } diff --git a/tests/cts/net/src/android/net/cts/NetworkAgentTest.kt b/tests/cts/net/src/android/net/cts/NetworkAgentTest.kt index 9f8a05db61..cf5fc50f04 100644 --- a/tests/cts/net/src/android/net/cts/NetworkAgentTest.kt +++ b/tests/cts/net/src/android/net/cts/NetworkAgentTest.kt @@ -1247,15 +1247,15 @@ class NetworkAgentTest { // Connect a third network. Because network1 is awaiting replacement, network3 is preferred // as soon as it validates (until then, it is outscored by network1). - // The fact that the first event seen by matchAllCallback is the connection of network3 + // The fact that the first events seen by matchAllCallback is the connection of network3 // implicitly ensures that no callbacks are sent since network1 was lost. val (agent3, network3) = connectNetwork() + matchAllCallback.expectAvailableThenValidatedCallbacks(network3) + testCallback.expectAvailableDoubleValidatedCallbacks(network3) + // As soon as the replacement arrives, network1 is disconnected. // Check that this happens before the replacement timeout (5 seconds) fires. - matchAllCallback.expectAvailableCallbacks(network3, validated = false) matchAllCallback.expect(network1, 2_000 /* timeoutMs */) - matchAllCallback.expectCaps(network3) { it.hasCapability(NET_CAPABILITY_VALIDATED) } - testCallback.expectAvailableDoubleValidatedCallbacks(network3) agent1.expectCallback() // Test lingering: @@ -1301,7 +1301,7 @@ class NetworkAgentTest { val callback = TestableNetworkCallback() requestNetwork(makeTestNetworkRequest(specifier = specifier6), callback) val agent6 = createNetworkAgent(specifier = specifier6) - agent6.register() + val network6 = agent6.register() if (SdkLevel.isAtLeastU()) { agent6.expectCallback() } else { @@ -1368,9 +1368,8 @@ class NetworkAgentTest { val (newWifiAgent, newWifiNetwork) = connectNetwork(TRANSPORT_WIFI) testCallback.expectAvailableCallbacks(newWifiNetwork, validated = true) - matchAllCallback.expectAvailableCallbacks(newWifiNetwork, validated = false) + matchAllCallback.expectAvailableThenValidatedCallbacks(newWifiNetwork) matchAllCallback.expect(wifiNetwork) - matchAllCallback.expectCaps(newWifiNetwork) { it.hasCapability(NET_CAPABILITY_VALIDATED) } wifiAgent.expectCallback() } diff --git a/tests/unit/java/com/android/server/ConnectivityServiceTest.java b/tests/unit/java/com/android/server/ConnectivityServiceTest.java index bb55aee35e..57c3acc9a2 100755 --- a/tests/unit/java/com/android/server/ConnectivityServiceTest.java +++ b/tests/unit/java/com/android/server/ConnectivityServiceTest.java @@ -2946,24 +2946,22 @@ public class ConnectivityServiceTest { if (expectLingering) { generalCb.expectLosing(net1); } + generalCb.expectCaps(net2, c -> c.hasCapability(NET_CAPABILITY_VALIDATED)); + defaultCb.expectAvailableDoubleValidatedCallbacks(net2); // Make sure cell 1 is unwanted immediately if the radio can't time share, but only // after some delay if it can. if (expectLingering) { - generalCb.expectCaps(net2, c -> c.hasCapability(NET_CAPABILITY_VALIDATED)); - defaultCb.expectAvailableDoubleValidatedCallbacks(net2); net1.assertNotDisconnected(TEST_CALLBACK_TIMEOUT_MS); // always incurs the timeout generalCb.assertNoCallback(); // assertNotDisconnected waited for TEST_CALLBACK_TIMEOUT_MS, so waiting for the // linger period gives TEST_CALLBACK_TIMEOUT_MS time for the event to process. net1.expectDisconnected(UNREASONABLY_LONG_ALARM_WAIT_MS); - generalCb.expect(LOST, net1); } else { net1.expectDisconnected(TEST_CALLBACK_TIMEOUT_MS); - generalCb.expect(LOST, net1); - generalCb.expectCaps(net2, c -> c.hasCapability(NET_CAPABILITY_VALIDATED)); - defaultCb.expectAvailableDoubleValidatedCallbacks(net2); } + net1.disconnect(); + generalCb.expect(LOST, net1); // Remove primary from net 2 net2.setScore(new NetworkScore.Builder().build()); From 3c15061eaa5756680914c0af1a85c9ade59b6e5a Mon Sep 17 00:00:00 2001 From: Chalard Jean Date: Tue, 27 Jun 2023 19:16:00 +0900 Subject: [PATCH 07/16] 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 (cherry picked from https://android-review.googlesource.com/q/commit:a16607f421ecfbf37ef8fb2fa96d4d285df9e77b) Merged-In: I96d755445f6e1f88bb71a7d32742e87dae185250 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 28d1d73881..e6bc5015b4 100755 --- a/service/src/com/android/server/ConnectivityService.java +++ b/service/src/com/android/server/ConnectivityService.java @@ -4549,9 +4549,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 From 47c26754600f4a6e085c21afd675a2217bed948b Mon Sep 17 00:00:00 2001 From: Ivo Kay Date: Thu, 12 Oct 2023 14:39:39 +0000 Subject: [PATCH 08/16] Allow to query NetworkStats for TYPE_PROXY (Test is a partial cherry-pick to allow behavior from different module versions) Test: atest FrameworksNetTests CtsNetTestCases Bug: 307217169 Merged-In: I006e3191a8c6100af3d2906d5d37f4e38a3db519 Change-Id: Ia7204ab44c0cf75b26408a5993b8cd49be5778f7 --- framework-t/src/android/net/NetworkStatsCollection.java | 2 ++ framework-t/src/android/net/NetworkTemplate.java | 2 +- .../common/java/android/net/netstats/NetworkTemplateTest.kt | 5 ----- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/framework-t/src/android/net/NetworkStatsCollection.java b/framework-t/src/android/net/NetworkStatsCollection.java index e23faa4ba8..20c5f30504 100644 --- a/framework-t/src/android/net/NetworkStatsCollection.java +++ b/framework-t/src/android/net/NetworkStatsCollection.java @@ -31,6 +31,7 @@ import static android.net.NetworkStats.UID_ALL; import static android.net.NetworkTemplate.MATCH_BLUETOOTH; import static android.net.NetworkTemplate.MATCH_ETHERNET; import static android.net.NetworkTemplate.MATCH_MOBILE; +import static android.net.NetworkTemplate.MATCH_PROXY; import static android.net.NetworkTemplate.MATCH_WIFI; import static android.net.TrafficStats.UID_REMOVED; import static android.text.format.DateUtils.WEEK_IN_MILLIS; @@ -784,6 +785,7 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W dumpCheckin(pw, start, end, new NetworkTemplate.Builder(MATCH_WIFI).build(), "wifi"); dumpCheckin(pw, start, end, new NetworkTemplate.Builder(MATCH_ETHERNET).build(), "eth"); dumpCheckin(pw, start, end, new NetworkTemplate.Builder(MATCH_BLUETOOTH).build(), "bt"); + dumpCheckin(pw, start, end, new NetworkTemplate.Builder(MATCH_PROXY).build(), "proxy"); } /** diff --git a/framework-t/src/android/net/NetworkTemplate.java b/framework-t/src/android/net/NetworkTemplate.java index 33bd884931..77b166cc3a 100644 --- a/framework-t/src/android/net/NetworkTemplate.java +++ b/framework-t/src/android/net/NetworkTemplate.java @@ -1170,7 +1170,7 @@ public final class NetworkTemplate implements Parcelable { * @param matchRule the target match rule to be checked. */ private static void assertRequestableMatchRule(final int matchRule) { - if (!isKnownMatchRule(matchRule) || matchRule == MATCH_PROXY) { + if (!isKnownMatchRule(matchRule)) { throw new IllegalArgumentException("Invalid match rule: " + getMatchRuleName(matchRule)); } diff --git a/tests/common/java/android/net/netstats/NetworkTemplateTest.kt b/tests/common/java/android/net/netstats/NetworkTemplateTest.kt index fd7bd74b4e..9469243a81 100644 --- a/tests/common/java/android/net/netstats/NetworkTemplateTest.kt +++ b/tests/common/java/android/net/netstats/NetworkTemplateTest.kt @@ -62,11 +62,6 @@ class NetworkTemplateTest { } } - // Verify hidden match rules cannot construct templates. - assertFailsWith { - NetworkTemplate.Builder(MATCH_PROXY).build() - } - // Verify template which matches metered cellular and carrier networks with // the given IMSI. See buildTemplateMobileAll and buildTemplateCarrierMetered. listOf(MATCH_MOBILE, MATCH_CARRIER).forEach { matchRule -> From 4cb9cfa3a1c50d99b448754bd6a16321b3c43401 Mon Sep 17 00:00:00 2001 From: Kefan Tu Date: Mon, 31 Jul 2023 05:19:33 +0000 Subject: [PATCH 09/16] Disable data saver mode in AbstractRestrictBackgroundNetworkTestCase setup This test assumes the data saver mode is initially disabled, but WearOS enables the mode on boot. This change fixes the precondition in the setUp method. Test: run cts -m CtsHostsideNetworkTests Bug: 315081804 Fixes: 315081804 Change-Id: Ibcceaf0f44821100c861ef7b3c61d0888ae30481 (cherry picked from commit 2cdeffc7e97a915a847cfc40d89e091aeadf20b3) --- .../AbstractRestrictBackgroundNetworkTestCase.java | 7 +++++++ .../android/cts/net/hostside/NetworkPolicyTestUtils.java | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java b/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java index 106a49c655..9acfc19346 100644 --- a/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java +++ b/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java @@ -31,6 +31,7 @@ import static com.android.cts.net.hostside.NetworkPolicyTestUtils.isAppStandbySu import static com.android.cts.net.hostside.NetworkPolicyTestUtils.isBatterySaverSupported; import static com.android.cts.net.hostside.NetworkPolicyTestUtils.isDozeModeSupported; import static com.android.cts.net.hostside.NetworkPolicyTestUtils.restrictBackgroundValueToString; +import static com.android.cts.net.hostside.NetworkPolicyTestUtils.setRestrictBackgroundInternal; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -187,6 +188,12 @@ public abstract class AbstractRestrictBackgroundNetworkTestCase { mServiceClient.bind(); mPowerManager = mContext.getSystemService(PowerManager.class); executeShellCommand("cmd netpolicy start-watching " + mUid); + // Some of the test cases assume that Data saver mode is initially disabled, which might not + // always be the case. Therefore, explicitly disable it before running the tests. + // Invoke setRestrictBackgroundInternal() directly instead of going through + // setRestrictBackground(), as some devices do not fully support the Data saver mode but + // still have certain parts of it enabled by default. + setRestrictBackgroundInternal(false); setAppIdle(false); mLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); diff --git a/tests/cts/hostside/app/src/com/android/cts/net/hostside/NetworkPolicyTestUtils.java b/tests/cts/hostside/app/src/com/android/cts/net/hostside/NetworkPolicyTestUtils.java index 12b186f2aa..5331601e04 100644 --- a/tests/cts/hostside/app/src/com/android/cts/net/hostside/NetworkPolicyTestUtils.java +++ b/tests/cts/hostside/app/src/com/android/cts/net/hostside/NetworkPolicyTestUtils.java @@ -344,7 +344,7 @@ public class NetworkPolicyTestUtils { setRestrictBackgroundInternal(enabled); } - private static void setRestrictBackgroundInternal(boolean enabled) { + static void setRestrictBackgroundInternal(boolean enabled) { executeShellCommand("cmd netpolicy set restrict-background " + enabled); final String output = executeShellCommand("cmd netpolicy get restrict-background"); final String expectedSuffix = enabled ? "enabled" : "disabled"; From 25a5eb9c2b14e56d2cc6fd3f9aa030b2745a9e03 Mon Sep 17 00:00:00 2001 From: Xinyi Zhou Date: Thu, 22 Feb 2024 01:28:43 +0000 Subject: [PATCH 10/16] Remove unused priviliged signature permission Change-Id: I11aba292e15301dd2d68bb7dfd20d6ae715f1f79 Fix:319155991 Fix:319046559 --- nearby/tests/cts/fastpair/AndroidManifest.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/nearby/tests/cts/fastpair/AndroidManifest.xml b/nearby/tests/cts/fastpair/AndroidManifest.xml index 9e1ec70427..472f4f0b67 100644 --- a/nearby/tests/cts/fastpair/AndroidManifest.xml +++ b/nearby/tests/cts/fastpair/AndroidManifest.xml @@ -21,7 +21,6 @@ - From 27344dbd2155eaf7f3462a1d83567d30591ef480 Mon Sep 17 00:00:00 2001 From: Motomu Utsumi Date: Wed, 21 Feb 2024 21:58:53 +0900 Subject: [PATCH 11/16] Make RedactedNetworkCapabilities compatible with upcoming change Upcoming change will make subIds public and not redacted but this change will make cts fail. So this CL updates test to be compatible with current code and code with planned changes. After the current cts support window is over, subIds can be public. Bug: 324357121 Test: TH, TH with aosp/2969321 (cherry picked from https://android-review.googlesource.com/q/commit:fd9d0e88555b5f5d3292e76c4f9c8a82a2fda179) Merged-In: I45d39f5bc3b1c4af26cc990ce29b45e9ad7d3c3c Change-Id: I45d39f5bc3b1c4af26cc990ce29b45e9ad7d3c3c --- .../cts/net/src/android/net/cts/ConnectivityManagerTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java index 4451a88efb..a4a8216c4a 100644 --- a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java +++ b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java @@ -799,7 +799,9 @@ public class ConnectivityManagerTest { assertNull(redactedNormal.getUids()); assertNull(redactedNormal.getSsid()); assertNull(redactedNormal.getUnderlyingNetworks()); - assertEquals(0, redactedNormal.getSubscriptionIds().size()); + // TODO: Make subIds public and update to verify the size is 2 + final int subIdsSize = redactedNormal.getSubscriptionIds().size(); + assertTrue(subIdsSize == 0 || subIdsSize == 2); assertEquals(WifiInfo.DEFAULT_MAC_ADDRESS, ((WifiInfo) redactedNormal.getTransportInfo()).getBSSID()); assertEquals(rssi, ((WifiInfo) redactedNormal.getTransportInfo()).getRssi()); From 927714a4446d8657490bc94493aa9ae7ca351200 Mon Sep 17 00:00:00 2001 From: "Wenbin.Chen" Date: Mon, 13 Nov 2023 10:56:01 +0000 Subject: [PATCH 12/16] Disable LowPowerStandby by adding configuration On low-performance devices, this test case will activate LOW_POWER_STANDBY mode during the test, which should not be initiated in this test case. The LOW_POWER_STANDBY mode blocks APK from accessing the network, resulting in test failures. BUG:301027368 Signed-off-by: Wenbin.Chen Change-Id: I1085addd22f4f3b709e1875049633832c5dac852 Test: CtsHostsideNetworkTests#com.android.cts.net.HostsideRestrictBackgroundNetworkTests (cherry picked from commit df1bf2a963d34e3458143c0e62163c14035b9e44) --- tests/cts/hostside/AndroidTest.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/cts/hostside/AndroidTest.xml b/tests/cts/hostside/AndroidTest.xml index 90b7875894..0ffe81eb53 100644 --- a/tests/cts/hostside/AndroidTest.xml +++ b/tests/cts/hostside/AndroidTest.xml @@ -36,6 +36,7 @@ From b10a90a4bdd3344e75a9180bd524ccb6f0ce0a5f Mon Sep 17 00:00:00 2001 From: "Phirsait (Sharp) Chareonchitseriwong" Date: Tue, 4 Jun 2024 05:59:46 +0000 Subject: [PATCH 13/16] Add ThreadNetworkTestCases.apk to run thread CTS Drop CTS from android-mcts-tethering.zip in aml-frc-release branch. Build: T1010062 (frc_350712000) The AndroidTest.xml makes sure only device that declares android.hardware.thread_network will run this test. Otherwise, the test will be skipped completely. Bug: 346980572 Test: Run on U devices with/without ThreadNetwork Change-Id: Ib41e70e2c6ae0491dde8e08009af533b25980be2 --- thread/tests/cts/Android.bp | 31 ++++++++++ thread/tests/cts/AndroidTest.xml | 58 ++++++++++++++++++ .../tests/cts/CtsThreadNetworkTestCases.apk | Bin 0 -> 4790765 bytes thread/tests/cts/METADATA | 17 +++++ 4 files changed, 106 insertions(+) create mode 100644 thread/tests/cts/Android.bp create mode 100644 thread/tests/cts/AndroidTest.xml create mode 100755 thread/tests/cts/CtsThreadNetworkTestCases.apk create mode 100644 thread/tests/cts/METADATA diff --git a/thread/tests/cts/Android.bp b/thread/tests/cts/Android.bp new file mode 100644 index 0000000000..9edbd8b140 --- /dev/null +++ b/thread/tests/cts/Android.bp @@ -0,0 +1,31 @@ +// +// Copyright (C) 2023 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +android_test_import { + name: "CtsThreadNetworkTestCases", + apk: "CtsThreadNetworkTestCases.apk", + + test_suites: [ + "cts", + "general-tests", + ], + + presigned: true, + dex_preopt: { + enabled: false, + }, +} + diff --git a/thread/tests/cts/AndroidTest.xml b/thread/tests/cts/AndroidTest.xml new file mode 100644 index 0000000000..6eda1e9cfd --- /dev/null +++ b/thread/tests/cts/AndroidTest.xml @@ -0,0 +1,58 @@ + + + + +