summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Hu <paulhu@google.com>2024-04-16 08:07:11 +0000
committerPaul Hu <paulhu@google.com>2024-04-18 05:57:04 +0000
commit82e396394bd2a67a0d905ceee2de31e69ecebd6f (patch)
tree43e0ed0b8b90996cc07d5a12833d8138e2737dc3
parent7e68d550f7c71835ce3c747653664be7f7d4f3fc (diff)
downloadConnectivity-82e396394bd2a67a0d905ceee2de31e69ecebd6f.tar.gz
Return current testable networks directly in instant mode
Some MultinetworkApiTest tests require a testable network and attempt to request cell or Wi-Fi connections. This involves calling ConnectivityManager#requestNetwork, which requires the CHANGE_NETWORK_STATE permission. Since instant apps cannot be granted this permission, return currently available testable networks directly in instant mode instead of attempting to request new ones. Fix: 335103621 Test: atest CtsNetTestCases:android.net.cts.MultinetworkApiTest \ --instant Change-Id: I51dbd33e0dab12856e1c0f387e45e6286feefe20
-rw-r--r--tests/cts/net/src/android/net/cts/MultinetworkApiTest.java8
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/cts/net/src/android/net/cts/MultinetworkApiTest.java b/tests/cts/net/src/android/net/cts/MultinetworkApiTest.java
index 73f65e019d..06a827b646 100644
--- a/tests/cts/net/src/android/net/cts/MultinetworkApiTest.java
+++ b/tests/cts/net/src/android/net/cts/MultinetworkApiTest.java
@@ -265,6 +265,14 @@ public class MultinetworkApiTest {
* Get all testable Networks with internet capability.
*/
private Set<Network> getTestableNetworks() throws InterruptedException {
+ // Calling requestNetwork() to request a cell or Wi-Fi network via CtsNetUtils or
+ // NetworkCallbackRule requires the CHANGE_NETWORK_STATE permission. This permission cannot
+ // be granted to instant apps. Therefore, return currently available testable networks
+ // directly in instant mode.
+ if (mContext.getApplicationInfo().isInstantApp()) {
+ return new ArraySet<>(mCtsNetUtils.getTestableNetworks());
+ }
+
// Obtain cell and Wi-Fi through CtsNetUtils (which uses NetworkCallbacks), as they may have
// just been reconnected by the test using NetworkCallbacks, so synchronous calls may not
// yet return them (synchronous calls and callbacks should not be mixed for a given