Merge "CTS test for VpnService.isAlwaysOn & .isLockdownEnabled."
am: 30667cf8c0 Change-Id: I428c9fe6d03c18136ba38e5a52938eb0bf8e8a5c
This commit is contained in:
@@ -33,6 +33,10 @@ public class MyVpnService extends VpnService {
|
|||||||
private static String TAG = "MyVpnService";
|
private static String TAG = "MyVpnService";
|
||||||
private static int MTU = 1799;
|
private static int MTU = 1799;
|
||||||
|
|
||||||
|
public static final String ACTION_ESTABLISHED = "com.android.cts.net.hostside.ESTABNLISHED";
|
||||||
|
public static final String EXTRA_ALWAYS_ON = "is-always-on";
|
||||||
|
public static final String EXTRA_LOCKDOWN_ENABLED = "is-lockdown-enabled";
|
||||||
|
|
||||||
private ParcelFileDescriptor mFd = null;
|
private ParcelFileDescriptor mFd = null;
|
||||||
private PacketReflector mPacketReflector = null;
|
private PacketReflector mPacketReflector = null;
|
||||||
|
|
||||||
@@ -129,10 +133,19 @@ public class MyVpnService extends VpnService {
|
|||||||
mFd = builder.establish();
|
mFd = builder.establish();
|
||||||
Log.i(TAG, "Established, fd=" + (mFd == null ? "null" : mFd.getFd()));
|
Log.i(TAG, "Established, fd=" + (mFd == null ? "null" : mFd.getFd()));
|
||||||
|
|
||||||
|
broadcastEstablished();
|
||||||
|
|
||||||
mPacketReflector = new PacketReflector(mFd.getFileDescriptor(), MTU);
|
mPacketReflector = new PacketReflector(mFd.getFileDescriptor(), MTU);
|
||||||
mPacketReflector.start();
|
mPacketReflector.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void broadcastEstablished() {
|
||||||
|
final Intent bcIntent = new Intent(ACTION_ESTABLISHED);
|
||||||
|
bcIntent.putExtra(EXTRA_ALWAYS_ON, isAlwaysOn());
|
||||||
|
bcIntent.putExtra(EXTRA_LOCKDOWN_ENABLED, isLockdownEnabled());
|
||||||
|
sendBroadcast(bcIntent);
|
||||||
|
}
|
||||||
|
|
||||||
private void stop() {
|
private void stop() {
|
||||||
if (mPacketReflector != null) {
|
if (mPacketReflector != null) {
|
||||||
mPacketReflector.interrupt();
|
mPacketReflector.interrupt();
|
||||||
|
|||||||
@@ -36,8 +36,6 @@ import android.os.Process;
|
|||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
import android.support.test.uiautomator.UiDevice;
|
import android.support.test.uiautomator.UiDevice;
|
||||||
import android.support.test.uiautomator.UiObject;
|
import android.support.test.uiautomator.UiObject;
|
||||||
import android.support.test.uiautomator.UiObjectNotFoundException;
|
|
||||||
import android.support.test.uiautomator.UiScrollable;
|
|
||||||
import android.support.test.uiautomator.UiSelector;
|
import android.support.test.uiautomator.UiSelector;
|
||||||
import android.system.ErrnoException;
|
import android.system.ErrnoException;
|
||||||
import android.system.Os;
|
import android.system.Os;
|
||||||
@@ -49,18 +47,12 @@ import android.text.TextUtils;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.compatibility.common.util.BlockingBroadcastReceiver;
|
import com.android.compatibility.common.util.BlockingBroadcastReceiver;
|
||||||
import com.android.cts.net.hostside.IRemoteSocketFactory;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.net.DatagramPacket;
|
import java.net.DatagramPacket;
|
||||||
import java.net.DatagramSocket;
|
import java.net.DatagramSocket;
|
||||||
import java.net.Inet6Address;
|
import java.net.Inet6Address;
|
||||||
@@ -68,9 +60,9 @@ import java.net.InetAddress;
|
|||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for the VpnService API.
|
* Tests for the VpnService API.
|
||||||
@@ -230,6 +222,7 @@ public class VpnTest extends InstrumentationTestCase {
|
|||||||
.putExtra(mPackageName + ".allowedapplications", allowedApplications)
|
.putExtra(mPackageName + ".allowedapplications", allowedApplications)
|
||||||
.putExtra(mPackageName + ".disallowedapplications", disallowedApplications)
|
.putExtra(mPackageName + ".disallowedapplications", disallowedApplications)
|
||||||
.putExtra(mPackageName + ".httpProxy", proxyInfo);
|
.putExtra(mPackageName + ".httpProxy", proxyInfo);
|
||||||
|
|
||||||
mActivity.startService(intent);
|
mActivity.startService(intent);
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
if (mNetwork == null) {
|
if (mNetwork == null) {
|
||||||
@@ -573,15 +566,27 @@ public class VpnTest extends InstrumentationTestCase {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final BlockingBroadcastReceiver receiver = new BlockingBroadcastReceiver(
|
||||||
|
getInstrumentation().getTargetContext(), MyVpnService.ACTION_ESTABLISHED);
|
||||||
|
receiver.register();
|
||||||
|
|
||||||
FileDescriptor fd = openSocketFdInOtherApp(TEST_HOST, 80, TIMEOUT_MS);
|
FileDescriptor fd = openSocketFdInOtherApp(TEST_HOST, 80, TIMEOUT_MS);
|
||||||
|
|
||||||
startVpn(new String[] {"192.0.2.2/32", "2001:db8:1:2::ffe/128"},
|
startVpn(new String[] {"192.0.2.2/32", "2001:db8:1:2::ffe/128"},
|
||||||
new String[] {"0.0.0.0/0", "::/0"},
|
new String[] {"0.0.0.0/0", "::/0"},
|
||||||
"", "", null);
|
"", "", null);
|
||||||
|
|
||||||
|
final Intent intent = receiver.awaitForBroadcast(TimeUnit.MINUTES.toMillis(1));
|
||||||
|
assertNotNull("Failed to receive broadcast from VPN service", intent);
|
||||||
|
assertFalse("Wrong VpnService#isAlwaysOn",
|
||||||
|
intent.getBooleanExtra(MyVpnService.EXTRA_ALWAYS_ON, true));
|
||||||
|
assertFalse("Wrong VpnService#isLockdownEnabled",
|
||||||
|
intent.getBooleanExtra(MyVpnService.EXTRA_LOCKDOWN_ENABLED, true));
|
||||||
|
|
||||||
assertSocketClosed(fd, TEST_HOST);
|
assertSocketClosed(fd, TEST_HOST);
|
||||||
|
|
||||||
checkTrafficOnVpn();
|
checkTrafficOnVpn();
|
||||||
|
receiver.unregisterQuietly();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAppAllowed() throws Exception {
|
public void testAppAllowed() throws Exception {
|
||||||
@@ -774,6 +779,17 @@ public class VpnTest extends InstrumentationTestCase {
|
|||||||
assertEquals(expected, mCM.getProxyForNetwork(network));
|
assertEquals(expected, mCM.getProxyForNetwork(network));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public void testIsAlwaysOnIsLockdownNotAlwaysOn() throws Exception {
|
||||||
|
// if (!supportedHardware()) return;
|
||||||
|
//
|
||||||
|
// // This package is the VPN app, so we can call the APIs directly.
|
||||||
|
//
|
||||||
|
// startVpn(new String[] {"192.0.2.2/32", "2001:db8:1:2::ffe/128"},
|
||||||
|
// new String[] {"0.0.0.0/0", "::/0"},
|
||||||
|
// mPackageName /* allowedApps */, "",
|
||||||
|
// null /* proxyInfo */);
|
||||||
|
// }
|
||||||
|
|
||||||
class ProxyChangeBroadcastReceiver extends BlockingBroadcastReceiver {
|
class ProxyChangeBroadcastReceiver extends BlockingBroadcastReceiver {
|
||||||
private boolean received;
|
private boolean received;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user