Merge changes from topic "revert-1551943-vpn-impl-FKOLCXTDDT"
* changes: Revert "Unhide RouteInfo#getType and related fields" Revert "Unhide IpPrefix(InetAddress, int)" Revert "Add CTS tests for exclude VPN routes APIs"
This commit is contained in:
@@ -206,7 +206,6 @@ package android.net {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final class IpPrefix implements android.os.Parcelable {
|
public final class IpPrefix implements android.os.Parcelable {
|
||||||
ctor public IpPrefix(@NonNull java.net.InetAddress, @IntRange(from=0, to=128) int);
|
|
||||||
method public boolean contains(@NonNull java.net.InetAddress);
|
method public boolean contains(@NonNull java.net.InetAddress);
|
||||||
method public int describeContents();
|
method public int describeContents();
|
||||||
method @NonNull public java.net.InetAddress getAddress();
|
method @NonNull public java.net.InetAddress getAddress();
|
||||||
@@ -440,15 +439,11 @@ package android.net {
|
|||||||
method @NonNull public android.net.IpPrefix getDestination();
|
method @NonNull public android.net.IpPrefix getDestination();
|
||||||
method @Nullable public java.net.InetAddress getGateway();
|
method @Nullable public java.net.InetAddress getGateway();
|
||||||
method @Nullable public String getInterface();
|
method @Nullable public String getInterface();
|
||||||
method public int getType();
|
|
||||||
method public boolean hasGateway();
|
method public boolean hasGateway();
|
||||||
method public boolean isDefaultRoute();
|
method public boolean isDefaultRoute();
|
||||||
method public boolean matches(java.net.InetAddress);
|
method public boolean matches(java.net.InetAddress);
|
||||||
method public void writeToParcel(android.os.Parcel, int);
|
method public void writeToParcel(android.os.Parcel, int);
|
||||||
field @NonNull public static final android.os.Parcelable.Creator<android.net.RouteInfo> CREATOR;
|
field @NonNull public static final android.os.Parcelable.Creator<android.net.RouteInfo> CREATOR;
|
||||||
field public static final int RTN_THROW = 9; // 0x9
|
|
||||||
field public static final int RTN_UNICAST = 1; // 0x1
|
|
||||||
field public static final int RTN_UNREACHABLE = 7; // 0x7
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class SocketKeepalive implements java.lang.AutoCloseable {
|
public abstract class SocketKeepalive implements java.lang.AutoCloseable {
|
||||||
|
|||||||
@@ -131,6 +131,7 @@ package android.net {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final class IpPrefix implements android.os.Parcelable {
|
public final class IpPrefix implements android.os.Parcelable {
|
||||||
|
ctor public IpPrefix(@NonNull java.net.InetAddress, @IntRange(from=0, to=128) int);
|
||||||
ctor public IpPrefix(@NonNull String);
|
ctor public IpPrefix(@NonNull String);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -431,6 +432,10 @@ package android.net {
|
|||||||
ctor public RouteInfo(@Nullable android.net.IpPrefix, @Nullable java.net.InetAddress, @Nullable String, int);
|
ctor public RouteInfo(@Nullable android.net.IpPrefix, @Nullable java.net.InetAddress, @Nullable String, int);
|
||||||
ctor public RouteInfo(@Nullable android.net.IpPrefix, @Nullable java.net.InetAddress, @Nullable String, int, int);
|
ctor public RouteInfo(@Nullable android.net.IpPrefix, @Nullable java.net.InetAddress, @Nullable String, int, int);
|
||||||
method public int getMtu();
|
method public int getMtu();
|
||||||
|
method public int getType();
|
||||||
|
field public static final int RTN_THROW = 9; // 0x9
|
||||||
|
field public static final int RTN_UNICAST = 1; // 0x1
|
||||||
|
field public static final int RTN_UNREACHABLE = 7; // 0x7
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class SocketKeepalive implements java.lang.AutoCloseable {
|
public abstract class SocketKeepalive implements java.lang.AutoCloseable {
|
||||||
|
|||||||
@@ -87,7 +87,9 @@ public final class IpPrefix implements Parcelable {
|
|||||||
*
|
*
|
||||||
* @param address the IP address. Must be non-null.
|
* @param address the IP address. Must be non-null.
|
||||||
* @param prefixLength the prefix length. Must be >= 0 and <= (32 or 128) (IPv4 or IPv6).
|
* @param prefixLength the prefix length. Must be >= 0 and <= (32 or 128) (IPv4 or IPv6).
|
||||||
|
* @hide
|
||||||
*/
|
*/
|
||||||
|
@SystemApi
|
||||||
public IpPrefix(@NonNull InetAddress address, @IntRange(from = 0, to = 128) int prefixLength) {
|
public IpPrefix(@NonNull InetAddress address, @IntRange(from = 0, to = 128) int prefixLength) {
|
||||||
// We don't reuse the (byte[], int) constructor because it calls clone() on the byte array,
|
// We don't reuse the (byte[], int) constructor because it calls clone() on the byte array,
|
||||||
// which is unnecessary because getAddress() already returns a clone.
|
// which is unnecessary because getAddress() already returns a clone.
|
||||||
|
|||||||
@@ -86,26 +86,16 @@ public final class RouteInfo implements Parcelable {
|
|||||||
private final String mInterface;
|
private final String mInterface;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/** Unicast route. @hide */
|
||||||
* Unicast route.
|
@SystemApi
|
||||||
*
|
|
||||||
* Indicates that destination is reachable directly or via gateway.
|
|
||||||
**/
|
|
||||||
public static final int RTN_UNICAST = 1;
|
public static final int RTN_UNICAST = 1;
|
||||||
|
|
||||||
/**
|
/** Unreachable route. @hide */
|
||||||
* Unreachable route.
|
@SystemApi
|
||||||
*
|
|
||||||
* Indicates that destination is unreachable.
|
|
||||||
**/
|
|
||||||
public static final int RTN_UNREACHABLE = 7;
|
public static final int RTN_UNREACHABLE = 7;
|
||||||
|
|
||||||
/**
|
/** Throw route. @hide */
|
||||||
* Throw route.
|
@SystemApi
|
||||||
*
|
|
||||||
* Indicates that routing information about this destination is not in this table.
|
|
||||||
* Routing lookup should continue in another table.
|
|
||||||
**/
|
|
||||||
public static final int RTN_THROW = 9;
|
public static final int RTN_THROW = 9;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -401,7 +391,10 @@ public final class RouteInfo implements Parcelable {
|
|||||||
* Retrieves the type of this route.
|
* Retrieves the type of this route.
|
||||||
*
|
*
|
||||||
* @return The type of this route; one of the {@code RTN_xxx} constants defined in this class.
|
* @return The type of this route; one of the {@code RTN_xxx} constants defined in this class.
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
*/
|
*/
|
||||||
|
@SystemApi
|
||||||
@RouteType
|
@RouteType
|
||||||
public int getType() {
|
public int getType() {
|
||||||
return mType;
|
return mType;
|
||||||
|
|||||||
@@ -122,9 +122,6 @@ public class IpPrefixTest {
|
|||||||
|
|
||||||
p = new IpPrefix("[2001:db8::123]/64");
|
p = new IpPrefix("[2001:db8::123]/64");
|
||||||
assertEquals("2001:db8::/64", p.toString());
|
assertEquals("2001:db8::/64", p.toString());
|
||||||
|
|
||||||
p = new IpPrefix(InetAddresses.parseNumericAddress("::128"), 64);
|
|
||||||
assertEquals("::/64", p.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package android.net;
|
package android.net;
|
||||||
|
|
||||||
import static android.net.RouteInfo.RTN_THROW;
|
|
||||||
import static android.net.RouteInfo.RTN_UNICAST;
|
|
||||||
import static android.net.RouteInfo.RTN_UNREACHABLE;
|
import static android.net.RouteInfo.RTN_UNREACHABLE;
|
||||||
|
|
||||||
import static com.android.testutils.MiscAsserts.assertEqualBothWays;
|
import static com.android.testutils.MiscAsserts.assertEqualBothWays;
|
||||||
@@ -330,16 +328,6 @@ public class RouteInfoTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRouteTypes() {
|
|
||||||
RouteInfo r = new RouteInfo(new IpPrefix(Inet6Address.ANY, 0), RTN_UNREACHABLE);
|
|
||||||
assertEquals(RTN_UNREACHABLE, r.getType());
|
|
||||||
r = new RouteInfo(new IpPrefix(Inet6Address.ANY, 0), RTN_UNICAST);
|
|
||||||
assertEquals(RTN_UNICAST, r.getType());
|
|
||||||
r = new RouteInfo(new IpPrefix(Inet6Address.ANY, 0), RTN_THROW);
|
|
||||||
assertEquals(RTN_THROW, r.getType());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTruncation() {
|
public void testTruncation() {
|
||||||
LinkAddress l;
|
LinkAddress l;
|
||||||
|
|||||||
@@ -25,9 +25,6 @@ java_test_host {
|
|||||||
"cts-tradefed",
|
"cts-tradefed",
|
||||||
"tradefed",
|
"tradefed",
|
||||||
],
|
],
|
||||||
static_libs: [
|
|
||||||
"modules-utils-build-testing",
|
|
||||||
],
|
|
||||||
// Tag this module as a cts test artifact
|
// Tag this module as a cts test artifact
|
||||||
test_suites: [
|
test_suites: [
|
||||||
"cts",
|
"cts",
|
||||||
|
|||||||
@@ -18,8 +18,12 @@ package {
|
|||||||
default_applicable_licenses: ["Android-Apache-2.0"],
|
default_applicable_licenses: ["Android-Apache-2.0"],
|
||||||
}
|
}
|
||||||
|
|
||||||
java_defaults {
|
android_test_helper_app {
|
||||||
name: "CtsHostsideNetworkTestsAppDefaults",
|
name: "CtsHostsideNetworkTestsApp",
|
||||||
|
defaults: [
|
||||||
|
"cts_support_defaults",
|
||||||
|
"framework-connectivity-test-defaults",
|
||||||
|
],
|
||||||
platform_apis: true,
|
platform_apis: true,
|
||||||
static_libs: [
|
static_libs: [
|
||||||
"CtsHostsideNetworkTestsAidl",
|
"CtsHostsideNetworkTestsAidl",
|
||||||
@@ -44,28 +48,3 @@ java_defaults {
|
|||||||
"sts",
|
"sts",
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
android_test_helper_app {
|
|
||||||
name: "CtsHostsideNetworkTestsApp",
|
|
||||||
defaults: [
|
|
||||||
"cts_support_defaults",
|
|
||||||
"framework-connectivity-test-defaults",
|
|
||||||
"CtsHostsideNetworkTestsAppDefaults",
|
|
||||||
],
|
|
||||||
static_libs: [
|
|
||||||
"NetworkStackApiStableShims",
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
android_test_helper_app {
|
|
||||||
name: "CtsHostsideNetworkTestsAppNext",
|
|
||||||
defaults: [
|
|
||||||
"cts_support_defaults",
|
|
||||||
"framework-connectivity-test-defaults",
|
|
||||||
"CtsHostsideNetworkTestsAppDefaults",
|
|
||||||
"ConnectivityNextEnableDefaults",
|
|
||||||
],
|
|
||||||
static_libs: [
|
|
||||||
"NetworkStackApiCurrentShims",
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -17,27 +17,18 @@
|
|||||||
package com.android.cts.net.hostside;
|
package com.android.cts.net.hostside;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
|
||||||
import android.net.IpPrefix;
|
|
||||||
import android.net.Network;
|
import android.net.Network;
|
||||||
import android.net.NetworkUtils;
|
|
||||||
import android.net.ProxyInfo;
|
import android.net.ProxyInfo;
|
||||||
import android.net.VpnService;
|
import android.net.VpnService;
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
|
||||||
|
|
||||||
import com.android.modules.utils.build.SdkLevel;
|
|
||||||
import com.android.networkstack.apishim.VpnServiceBuilderShimImpl;
|
|
||||||
import com.android.networkstack.apishim.common.UnsupportedApiLevelException;
|
|
||||||
import com.android.networkstack.apishim.common.VpnServiceBuilderShim;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public class MyVpnService extends VpnService {
|
public class MyVpnService extends VpnService {
|
||||||
|
|
||||||
@@ -64,62 +55,39 @@ public class MyVpnService extends VpnService {
|
|||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String parseIpAndMaskListArgument(String packageName, Intent intent, String argName,
|
|
||||||
BiConsumer<InetAddress, Integer> consumer) {
|
|
||||||
final String addresses = intent.getStringExtra(packageName + "." + argName);
|
|
||||||
|
|
||||||
if (TextUtils.isEmpty(addresses)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
final String[] addressesArray = addresses.split(",");
|
|
||||||
for (String address : addressesArray) {
|
|
||||||
final Pair<InetAddress, Integer> ipAndMask = NetworkUtils.parseIpAndMask(address);
|
|
||||||
consumer.accept(ipAndMask.first, ipAndMask.second);
|
|
||||||
}
|
|
||||||
|
|
||||||
return addresses;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String parseIpPrefixListArgument(String packageName, Intent intent, String argName,
|
|
||||||
Consumer<IpPrefix> consumer) {
|
|
||||||
return parseIpAndMaskListArgument(packageName, intent, argName,
|
|
||||||
(inetAddress, prefixLength) -> consumer.accept(
|
|
||||||
new IpPrefix(inetAddress, prefixLength)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void start(String packageName, Intent intent) {
|
private void start(String packageName, Intent intent) {
|
||||||
Builder builder = new Builder();
|
Builder builder = new Builder();
|
||||||
VpnServiceBuilderShim vpnServiceBuilderShim = VpnServiceBuilderShimImpl.newInstance();
|
|
||||||
|
|
||||||
final String addresses = parseIpAndMaskListArgument(packageName, intent, "addresses",
|
String addresses = intent.getStringExtra(packageName + ".addresses");
|
||||||
builder::addAddress);
|
if (addresses != null) {
|
||||||
|
String[] addressArray = addresses.split(",");
|
||||||
String addedRoutes;
|
for (int i = 0; i < addressArray.length; i++) {
|
||||||
if (SdkLevel.isAtLeastT() && intent.getBooleanExtra(packageName + ".addRoutesByIpPrefix",
|
String[] prefixAndMask = addressArray[i].split("/");
|
||||||
false)) {
|
|
||||||
addedRoutes = parseIpPrefixListArgument(packageName, intent, "routes", (prefix) -> {
|
|
||||||
try {
|
try {
|
||||||
vpnServiceBuilderShim.addRoute(builder, prefix);
|
InetAddress address = InetAddress.getByName(prefixAndMask[0]);
|
||||||
} catch (UnsupportedApiLevelException e) {
|
int prefixLength = Integer.parseInt(prefixAndMask[1]);
|
||||||
throw new RuntimeException(e);
|
builder.addAddress(address, prefixLength);
|
||||||
|
} catch (UnknownHostException|NumberFormatException|
|
||||||
|
ArrayIndexOutOfBoundsException e) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
} else {
|
|
||||||
addedRoutes = parseIpAndMaskListArgument(packageName, intent, "routes",
|
|
||||||
builder::addRoute);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String excludedRoutes = null;
|
String routes = intent.getStringExtra(packageName + ".routes");
|
||||||
if (SdkLevel.isAtLeastT()) {
|
if (routes != null) {
|
||||||
excludedRoutes = parseIpPrefixListArgument(packageName, intent, "excludedRoutes",
|
String[] routeArray = routes.split(",");
|
||||||
(prefix) -> {
|
for (int i = 0; i < routeArray.length; i++) {
|
||||||
|
String[] prefixAndMask = routeArray[i].split("/");
|
||||||
try {
|
try {
|
||||||
vpnServiceBuilderShim.excludeRoute(builder, prefix);
|
InetAddress address = InetAddress.getByName(prefixAndMask[0]);
|
||||||
} catch (UnsupportedApiLevelException e) {
|
int prefixLength = Integer.parseInt(prefixAndMask[1]);
|
||||||
throw new RuntimeException(e);
|
builder.addRoute(address, prefixLength);
|
||||||
|
} catch (UnknownHostException|NumberFormatException|
|
||||||
|
ArrayIndexOutOfBoundsException e) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String allowed = intent.getStringExtra(packageName + ".allowedapplications");
|
String allowed = intent.getStringExtra(packageName + ".allowedapplications");
|
||||||
@@ -172,8 +140,7 @@ public class MyVpnService extends VpnService {
|
|||||||
|
|
||||||
Log.i(TAG, "Establishing VPN,"
|
Log.i(TAG, "Establishing VPN,"
|
||||||
+ " addresses=" + addresses
|
+ " addresses=" + addresses
|
||||||
+ " addedRoutes=" + addedRoutes
|
+ " routes=" + routes
|
||||||
+ " excludedRoutes=" + excludedRoutes
|
|
||||||
+ " allowedApplications=" + allowed
|
+ " allowedApplications=" + allowed
|
||||||
+ " disallowedApplications=" + disallowed);
|
+ " disallowedApplications=" + disallowed);
|
||||||
|
|
||||||
|
|||||||
@@ -270,30 +270,7 @@ public class VpnTest {
|
|||||||
private void startVpn(
|
private void startVpn(
|
||||||
String[] addresses, String[] routes, String allowedApplications,
|
String[] addresses, String[] routes, String allowedApplications,
|
||||||
String disallowedApplications, @Nullable ProxyInfo proxyInfo,
|
String disallowedApplications, @Nullable ProxyInfo proxyInfo,
|
||||||
@Nullable ArrayList<Network> underlyingNetworks, boolean isAlwaysMetered)
|
@Nullable ArrayList<Network> underlyingNetworks, boolean isAlwaysMetered) throws Exception {
|
||||||
throws Exception {
|
|
||||||
startVpn(addresses, routes, new String[0] /* excludedRoutes */, allowedApplications,
|
|
||||||
disallowedApplications, proxyInfo, underlyingNetworks, isAlwaysMetered);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startVpn(
|
|
||||||
String[] addresses, String[] routes, String[] excludedRoutes,
|
|
||||||
String allowedApplications, String disallowedApplications,
|
|
||||||
@Nullable ProxyInfo proxyInfo,
|
|
||||||
@Nullable ArrayList<Network> underlyingNetworks, boolean isAlwaysMetered)
|
|
||||||
throws Exception {
|
|
||||||
startVpn(addresses, routes, new String[0] /* excludedRoutes */, allowedApplications,
|
|
||||||
disallowedApplications, proxyInfo, underlyingNetworks, isAlwaysMetered,
|
|
||||||
false /* addRoutesByIpPrefix */);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startVpn(
|
|
||||||
String[] addresses, String[] routes, String[] excludedRoutes,
|
|
||||||
String allowedApplications, String disallowedApplications,
|
|
||||||
@Nullable ProxyInfo proxyInfo,
|
|
||||||
@Nullable ArrayList<Network> underlyingNetworks, boolean isAlwaysMetered,
|
|
||||||
boolean addRoutesByIpPrefix)
|
|
||||||
throws Exception {
|
|
||||||
prepareVpn();
|
prepareVpn();
|
||||||
|
|
||||||
// Register a callback so we will be notified when our VPN comes up.
|
// Register a callback so we will be notified when our VPN comes up.
|
||||||
@@ -318,14 +295,12 @@ public class VpnTest {
|
|||||||
.putExtra(mPackageName + ".cmd", "connect")
|
.putExtra(mPackageName + ".cmd", "connect")
|
||||||
.putExtra(mPackageName + ".addresses", TextUtils.join(",", addresses))
|
.putExtra(mPackageName + ".addresses", TextUtils.join(",", addresses))
|
||||||
.putExtra(mPackageName + ".routes", TextUtils.join(",", routes))
|
.putExtra(mPackageName + ".routes", TextUtils.join(",", routes))
|
||||||
.putExtra(mPackageName + ".excludedRoutes", TextUtils.join(",", excludedRoutes))
|
|
||||||
.putExtra(mPackageName + ".allowedapplications", allowedApplications)
|
.putExtra(mPackageName + ".allowedapplications", allowedApplications)
|
||||||
.putExtra(mPackageName + ".disallowedapplications", disallowedApplications)
|
.putExtra(mPackageName + ".disallowedapplications", disallowedApplications)
|
||||||
.putExtra(mPackageName + ".httpProxy", proxyInfo)
|
.putExtra(mPackageName + ".httpProxy", proxyInfo)
|
||||||
.putParcelableArrayListExtra(
|
.putParcelableArrayListExtra(
|
||||||
mPackageName + ".underlyingNetworks", underlyingNetworks)
|
mPackageName + ".underlyingNetworks", underlyingNetworks)
|
||||||
.putExtra(mPackageName + ".isAlwaysMetered", isAlwaysMetered)
|
.putExtra(mPackageName + ".isAlwaysMetered", isAlwaysMetered);
|
||||||
.putExtra(mPackageName + ".addRoutesByIpPrefix", addRoutesByIpPrefix);
|
|
||||||
|
|
||||||
mActivity.startService(intent);
|
mActivity.startService(intent);
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
@@ -547,12 +522,6 @@ public class VpnTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkUdpEcho(String to, String expectedFrom) throws IOException {
|
private void checkUdpEcho(String to, String expectedFrom) throws IOException {
|
||||||
checkUdpEcho(to, expectedFrom, expectedFrom != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkUdpEcho(String to, String expectedFrom,
|
|
||||||
boolean expectConnectionOwnerIsVisible)
|
|
||||||
throws IOException {
|
|
||||||
DatagramSocket s;
|
DatagramSocket s;
|
||||||
InetAddress address = InetAddress.getByName(to);
|
InetAddress address = InetAddress.getByName(to);
|
||||||
if (address instanceof Inet6Address) { // http://b/18094870
|
if (address instanceof Inet6Address) { // http://b/18094870
|
||||||
@@ -576,7 +545,7 @@ public class VpnTest {
|
|||||||
try {
|
try {
|
||||||
if (expectedFrom != null) {
|
if (expectedFrom != null) {
|
||||||
s.send(p);
|
s.send(p);
|
||||||
checkConnectionOwnerUidUdp(s, expectConnectionOwnerIsVisible);
|
checkConnectionOwnerUidUdp(s, true);
|
||||||
s.receive(p);
|
s.receive(p);
|
||||||
MoreAsserts.assertEquals(data, p.getData());
|
MoreAsserts.assertEquals(data, p.getData());
|
||||||
} else {
|
} else {
|
||||||
@@ -585,7 +554,7 @@ public class VpnTest {
|
|||||||
s.receive(p);
|
s.receive(p);
|
||||||
fail("Received unexpected reply");
|
fail("Received unexpected reply");
|
||||||
} catch (IOException expected) {
|
} catch (IOException expected) {
|
||||||
checkConnectionOwnerUidUdp(s, expectConnectionOwnerIsVisible);
|
checkConnectionOwnerUidUdp(s, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@@ -593,38 +562,19 @@ public class VpnTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkTrafficOnVpn(String destination) throws Exception {
|
|
||||||
final InetAddress address = InetAddress.getByName(destination);
|
|
||||||
|
|
||||||
if (address instanceof Inet6Address) {
|
|
||||||
checkUdpEcho(destination, "2001:db8:1:2::ffe");
|
|
||||||
checkTcpReflection(destination, "2001:db8:1:2::ffe");
|
|
||||||
checkPing(destination);
|
|
||||||
} else {
|
|
||||||
checkUdpEcho(destination, "192.0.2.2");
|
|
||||||
checkTcpReflection(destination, "192.0.2.2");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkNoTrafficOnVpn(String destination) throws IOException {
|
|
||||||
checkUdpEcho(destination, null);
|
|
||||||
checkTcpReflection(destination, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkTrafficOnVpn() throws Exception {
|
private void checkTrafficOnVpn() throws Exception {
|
||||||
checkTrafficOnVpn("192.0.2.251");
|
checkUdpEcho("192.0.2.251", "192.0.2.2");
|
||||||
checkTrafficOnVpn("2001:db8:dead:beef::f00");
|
checkUdpEcho("2001:db8:dead:beef::f00", "2001:db8:1:2::ffe");
|
||||||
|
checkPing("2001:db8:dead:beef::f00");
|
||||||
|
checkTcpReflection("192.0.2.252", "192.0.2.2");
|
||||||
|
checkTcpReflection("2001:db8:dead:beef::f00", "2001:db8:1:2::ffe");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkNoTrafficOnVpn() throws Exception {
|
private void checkNoTrafficOnVpn() throws Exception {
|
||||||
checkNoTrafficOnVpn("192.0.2.251");
|
checkUdpEcho("192.0.2.251", null);
|
||||||
checkNoTrafficOnVpn("2001:db8:dead:beef::f00");
|
checkUdpEcho("2001:db8:dead:beef::f00", null);
|
||||||
}
|
checkTcpReflection("192.0.2.252", null);
|
||||||
|
checkTcpReflection("2001:db8:dead:beef::f00", null);
|
||||||
private void checkTrafficBypassesVpn(String destination) throws Exception {
|
|
||||||
checkUdpEcho(destination, null, true /* expectVpnOwnedConnection */);
|
|
||||||
checkTcpReflection(destination, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private FileDescriptor openSocketFd(String host, int port, int timeoutMs) throws Exception {
|
private FileDescriptor openSocketFd(String host, int port, int timeoutMs) throws Exception {
|
||||||
@@ -922,74 +872,6 @@ public class VpnTest {
|
|||||||
assertFalse(nc.hasTransport(TRANSPORT_VPN));
|
assertFalse(nc.hasTransport(TRANSPORT_VPN));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testExcludedRoutes() throws Exception {
|
|
||||||
if (!supportedHardware()) return;
|
|
||||||
if (!SdkLevel.isAtLeastT()) return;
|
|
||||||
|
|
||||||
// Shell app must not be put in here or it would kill the ADB-over-network use case
|
|
||||||
String allowedApps = mRemoteSocketFactoryClient.getPackageName() + "," + mPackageName;
|
|
||||||
startVpn(new String[]{"192.0.2.2/32", "2001:db8:1:2::ffe/128"} /* addresses */,
|
|
||||||
new String[]{"0.0.0.0/0", "::/0"} /* routes */,
|
|
||||||
new String[]{"192.0.2.0/24", "2001:db8::/32"} /* excludedRoutes */,
|
|
||||||
allowedApps, "" /* disallowedApplications */, null /* proxyInfo */,
|
|
||||||
null /* underlyingNetworks */, false /* isAlwaysMetered */);
|
|
||||||
|
|
||||||
// Excluded routes should bypass VPN.
|
|
||||||
checkTrafficBypassesVpn("192.0.2.1");
|
|
||||||
checkTrafficBypassesVpn("2001:db8:dead:beef::f00");
|
|
||||||
// Other routes should go through VPN, since default routes are included.
|
|
||||||
checkTrafficOnVpn("198.51.100.1");
|
|
||||||
checkTrafficOnVpn("2002:db8::1");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIncludedRoutes() throws Exception {
|
|
||||||
if (!supportedHardware()) return;
|
|
||||||
|
|
||||||
// Shell app must not be put in here or it would kill the ADB-over-network use case
|
|
||||||
String allowedApps = mRemoteSocketFactoryClient.getPackageName() + "," + mPackageName;
|
|
||||||
startVpn(new String[]{"192.0.2.2/32", "2001:db8:1:2::ffe/128"} /* addresses */,
|
|
||||||
new String[]{"192.0.2.0/24", "2001:db8::/32"} /* routes */,
|
|
||||||
allowedApps, "" /* disallowedApplications */, null /* proxyInfo */,
|
|
||||||
null /* underlyingNetworks */, false /* isAlwaysMetered */);
|
|
||||||
|
|
||||||
// Included routes should go through VPN.
|
|
||||||
checkTrafficOnVpn("192.0.2.1");
|
|
||||||
checkTrafficOnVpn("2001:db8:dead:beef::f00");
|
|
||||||
// Other routes should bypass VPN, since default routes are not included.
|
|
||||||
checkTrafficBypassesVpn("198.51.100.1");
|
|
||||||
checkTrafficBypassesVpn("2002:db8::1");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testInterleavedRoutes() throws Exception {
|
|
||||||
if (!supportedHardware()) return;
|
|
||||||
if (!SdkLevel.isAtLeastT()) return;
|
|
||||||
|
|
||||||
// Shell app must not be put in here or it would kill the ADB-over-network use case
|
|
||||||
String allowedApps = mRemoteSocketFactoryClient.getPackageName() + "," + mPackageName;
|
|
||||||
startVpn(new String[]{"192.0.2.2/32", "2001:db8:1:2::ffe/128"} /* addresses */,
|
|
||||||
new String[]{"0.0.0.0/0", "192.0.2.0/32", "::/0", "2001:db8::/128"} /* routes */,
|
|
||||||
new String[]{"192.0.2.0/24", "2001:db8::/32"} /* excludedRoutes */,
|
|
||||||
allowedApps, "" /* disallowedApplications */, null /* proxyInfo */,
|
|
||||||
null /* underlyingNetworks */, false /* isAlwaysMetered */,
|
|
||||||
true /* addRoutesByIpPrefix */);
|
|
||||||
|
|
||||||
// Excluded routes should bypass VPN.
|
|
||||||
checkTrafficBypassesVpn("192.0.2.1");
|
|
||||||
checkTrafficBypassesVpn("2001:db8:dead:beef::f00");
|
|
||||||
|
|
||||||
// Included routes inside excluded routes should go through VPN, since the longest common
|
|
||||||
// prefix precedes.
|
|
||||||
checkTrafficOnVpn("192.0.2.0");
|
|
||||||
checkTrafficOnVpn("2001:db8::");
|
|
||||||
|
|
||||||
// Other routes should go through VPN, since default routes are included.
|
|
||||||
checkTrafficOnVpn("198.51.100.1");
|
|
||||||
checkTrafficOnVpn("2002:db8::1");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetConnectionOwnerUidSecurity() throws Exception {
|
public void testGetConnectionOwnerUidSecurity() throws Exception {
|
||||||
if (!supportedHardware()) return;
|
if (!supportedHardware()) return;
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import com.android.compatibility.common.tradefed.build.CompatibilityBuildHelper;
|
|||||||
import com.android.ddmlib.Log;
|
import com.android.ddmlib.Log;
|
||||||
import com.android.ddmlib.testrunner.RemoteAndroidTestRunner;
|
import com.android.ddmlib.testrunner.RemoteAndroidTestRunner;
|
||||||
import com.android.ddmlib.testrunner.TestResult.TestStatus;
|
import com.android.ddmlib.testrunner.TestResult.TestStatus;
|
||||||
import com.android.modules.utils.build.testing.DeviceSdkLevel;
|
|
||||||
import com.android.tradefed.build.IBuildInfo;
|
import com.android.tradefed.build.IBuildInfo;
|
||||||
import com.android.tradefed.device.DeviceNotAvailableException;
|
import com.android.tradefed.device.DeviceNotAvailableException;
|
||||||
import com.android.tradefed.result.CollectingTestListener;
|
import com.android.tradefed.result.CollectingTestListener;
|
||||||
@@ -43,7 +42,6 @@ abstract class HostsideNetworkTestCase extends DeviceTestCase implements IAbiRec
|
|||||||
protected static final String TAG = "HostsideNetworkTests";
|
protected static final String TAG = "HostsideNetworkTests";
|
||||||
protected static final String TEST_PKG = "com.android.cts.net.hostside";
|
protected static final String TEST_PKG = "com.android.cts.net.hostside";
|
||||||
protected static final String TEST_APK = "CtsHostsideNetworkTestsApp.apk";
|
protected static final String TEST_APK = "CtsHostsideNetworkTestsApp.apk";
|
||||||
protected static final String TEST_APK_NEXT = "CtsHostsideNetworkTestsAppNext.apk";
|
|
||||||
protected static final String TEST_APP2_PKG = "com.android.cts.net.hostside.app2";
|
protected static final String TEST_APP2_PKG = "com.android.cts.net.hostside.app2";
|
||||||
protected static final String TEST_APP2_APK = "CtsHostsideNetworkTestsApp2.apk";
|
protected static final String TEST_APP2_APK = "CtsHostsideNetworkTestsApp2.apk";
|
||||||
|
|
||||||
@@ -67,12 +65,8 @@ abstract class HostsideNetworkTestCase extends DeviceTestCase implements IAbiRec
|
|||||||
assertNotNull(mAbi);
|
assertNotNull(mAbi);
|
||||||
assertNotNull(mCtsBuild);
|
assertNotNull(mCtsBuild);
|
||||||
|
|
||||||
DeviceSdkLevel deviceSdkLevel = new DeviceSdkLevel(getDevice());
|
|
||||||
String testApk = deviceSdkLevel.isDeviceAtLeastT() ? TEST_APK_NEXT
|
|
||||||
: TEST_APK;
|
|
||||||
|
|
||||||
uninstallPackage(TEST_PKG, false);
|
uninstallPackage(TEST_PKG, false);
|
||||||
installPackage(testApk);
|
installPackage(TEST_APK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -100,16 +100,4 @@ public class HostsideVpnTests extends HostsideNetworkTestCase {
|
|||||||
runDeviceTests(TEST_PKG, TEST_PKG + ".VpnTest",
|
runDeviceTests(TEST_PKG, TEST_PKG + ".VpnTest",
|
||||||
"testDownloadWithDownloadManagerDisallowed");
|
"testDownloadWithDownloadManagerDisallowed");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testExcludedRoutes() throws Exception {
|
|
||||||
runDeviceTests(TEST_PKG, TEST_PKG + ".VpnTest", "testExcludedRoutes");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testIncludedRoutes() throws Exception {
|
|
||||||
runDeviceTests(TEST_PKG, TEST_PKG + ".VpnTest", "testIncludedRoutes");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testInterleavedRoutes() throws Exception {
|
|
||||||
runDeviceTests(TEST_PKG, TEST_PKG + ".VpnTest", "testInterleavedRoutes");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user