From f3963fa27948ab7179631586f3e3b9b6b86fa4ef Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Thu, 26 Nov 2020 18:05:13 +0900 Subject: [PATCH] Allow tests to create TRANSPORT_TEST|TRANSPORT_VPN networks. This CL allows an app that has the MANAGE_TEST_NETWORKS permission to create test VPN networks. The code enforces that such networks can never apply to any UIDs and thus will never carry any traffic. Bug: 173331190 Test: passes existing tests, moved tests pass Change-Id: I5befea0e3b4b6dce4ca0c6a04471a055186b644c --- core/java/android/net/NetworkCapabilities.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/java/android/net/NetworkCapabilities.java b/core/java/android/net/NetworkCapabilities.java index 40bb8bf11d..8dad11ffa7 100644 --- a/core/java/android/net/NetworkCapabilities.java +++ b/core/java/android/net/NetworkCapabilities.java @@ -712,6 +712,7 @@ public final class NetworkCapabilities implements Parcelable { if (ArrayUtils.contains(originalAdministratorUids, creatorUid)) { setAdministratorUids(new int[] {creatorUid}); } + // There is no need to clear the UIDs, they have already been cleared by clearAll() above. } /** @@ -805,7 +806,9 @@ public final class NetworkCapabilities implements Parcelable { */ private static final int TEST_NETWORKS_ALLOWED_TRANSPORTS = 1 << TRANSPORT_TEST // Test ethernet networks can be created with EthernetManager#setIncludeTestInterfaces - | 1 << TRANSPORT_ETHERNET; + | 1 << TRANSPORT_ETHERNET + // Test VPN networks can be created but their UID ranges must be empty. + | 1 << TRANSPORT_VPN; /** * Adds the given transport type to this {@code NetworkCapability} instance.