aboutsummaryrefslogtreecommitdiffstats
path: root/ddms/libs
diff options
context:
space:
mode:
authorSiva Velusamy <vsiva@google.com>2012-01-27 14:20:45 -0800
committerSiva Velusamy <vsiva@google.com>2012-01-31 09:14:11 -0800
commit7a7181fc7d6fbaf227fe8b97501eff7dac615e92 (patch)
tree976a28227c45a8f3bf07fadf0c84810e3efe4cf9 /ddms/libs
parentf476714135b592dbd865c4ec2690c51db72a6243 (diff)
downloadsdk-7a7181fc7d6fbaf227fe8b97501eff7dac615e92.zip
sdk-7a7181fc7d6fbaf227fe8b97501eff7dac615e92.tar.gz
sdk-7a7181fc7d6fbaf227fe8b97501eff7dac615e92.tar.bz2
ddms: Allow port forwarding to Unix Domain Sockets
adb allows forwarding to not just TCP ports, but also Unix Domain Sockets (UDS) addressed by an abstract name or file system path. This patch enables support for port forwarding to UDS in the IDevice interface. Change-Id: I23fa667b24a2b469acc04cef26304f19179dc483
Diffstat (limited to 'ddms/libs')
-rw-r--r--ddms/libs/ddmlib/src/com/android/ddmlib/AdbHelper.java40
-rw-r--r--ddms/libs/ddmlib/src/com/android/ddmlib/Device.java26
-rw-r--r--ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java50
3 files changed, 102 insertions, 14 deletions
diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/AdbHelper.java b/ddms/libs/ddmlib/src/com/android/ddmlib/AdbHelper.java
index 5b5a41f..c1c9300 100644
--- a/ddms/libs/ddmlib/src/com/android/ddmlib/AdbHelper.java
+++ b/ddms/libs/ddmlib/src/com/android/ddmlib/AdbHelper.java
@@ -511,14 +511,22 @@ final class AdbHelper {
* Creates a port forwarding between a local and a remote port.
* @param adbSockAddr the socket address to connect to adb
* @param device the device on which to do the port fowarding
- * @param localPort the local port to forward
- * @param remotePort the remote port.
+ * @param localPortSpec specification of the local port to forward, should be of format
+ * tcp:<port number>
+ * @param remotePortSpec specification of the remote port to forward to, one of:
+ * tcp:<port>
+ * localabstract:<unix domain socket name>
+ * localreserved:<unix domain socket name>
+ * localfilesystem:<unix domain socket name>
+ * dev:<character device name>
+ * jdwp:<process pid> (remote only)
* @throws TimeoutException in case of timeout on the connection.
* @throws AdbCommandRejectedException if adb rejects the command
* @throws IOException in case of I/O error on the connection.
*/
- public static void createForward(InetSocketAddress adbSockAddr, Device device, int localPort,
- int remotePort) throws TimeoutException, AdbCommandRejectedException, IOException {
+ public static void createForward(InetSocketAddress adbSockAddr, Device device,
+ String localPortSpec, String remotePortSpec)
+ throws TimeoutException, AdbCommandRejectedException, IOException {
SocketChannel adbChan = null;
try {
@@ -526,8 +534,8 @@ final class AdbHelper {
adbChan.configureBlocking(false);
byte[] request = formAdbRequest(String.format(
- "host-serial:%1$s:forward:tcp:%2$d;tcp:%3$d", //$NON-NLS-1$
- device.getSerialNumber(), localPort, remotePort));
+ "host-serial:%1$s:forward:%2$s;%3$s", //$NON-NLS-1$
+ device.getSerialNumber(), localPortSpec, remotePortSpec));
write(adbChan, request);
@@ -547,14 +555,22 @@ final class AdbHelper {
* Remove a port forwarding between a local and a remote port.
* @param adbSockAddr the socket address to connect to adb
* @param device the device on which to remove the port fowarding
- * @param localPort the local port of the forward
- * @param remotePort the remote port.
+ * @param localPortSpec specification of the local port that was forwarded, should be of format
+ * tcp:<port number>
+ * @param remotePortSpec specification of the remote port forwarded to, one of:
+ * tcp:<port>
+ * localabstract:<unix domain socket name>
+ * localreserved:<unix domain socket name>
+ * localfilesystem:<unix domain socket name>
+ * dev:<character device name>
+ * jdwp:<process pid> (remote only)
* @throws TimeoutException in case of timeout on the connection.
* @throws AdbCommandRejectedException if adb rejects the command
* @throws IOException in case of I/O error on the connection.
*/
- public static void removeForward(InetSocketAddress adbSockAddr, Device device, int localPort,
- int remotePort) throws TimeoutException, AdbCommandRejectedException, IOException {
+ public static void removeForward(InetSocketAddress adbSockAddr, Device device,
+ String localPortSpec, String remotePortSpec)
+ throws TimeoutException, AdbCommandRejectedException, IOException {
SocketChannel adbChan = null;
try {
@@ -562,8 +578,8 @@ final class AdbHelper {
adbChan.configureBlocking(false);
byte[] request = formAdbRequest(String.format(
- "host-serial:%1$s:killforward:tcp:%2$d;tcp:%3$d", //$NON-NLS-1$
- device.getSerialNumber(), localPort, remotePort));
+ "host-serial:%1$s:killforward:%2$s;%3$s", //$NON-NLS-1$
+ device.getSerialNumber(), localPortSpec, remotePortSpec));
write(adbChan, request);
diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/Device.java b/ddms/libs/ddmlib/src/com/android/ddmlib/Device.java
index f3931a1..45b6533 100644
--- a/ddms/libs/ddmlib/src/com/android/ddmlib/Device.java
+++ b/ddms/libs/ddmlib/src/com/android/ddmlib/Device.java
@@ -413,13 +413,35 @@ final class Device implements IDevice {
@Override
public void createForward(int localPort, int remotePort)
throws TimeoutException, AdbCommandRejectedException, IOException {
- AdbHelper.createForward(AndroidDebugBridge.getSocketAddress(), this, localPort, remotePort);
+ AdbHelper.createForward(AndroidDebugBridge.getSocketAddress(), this,
+ String.format("tcp:%d", localPort), //$NON-NLS-1$
+ String.format("tcp:%d", remotePort)); //$NON-NLS-1$
+ }
+
+ @Override
+ public void createForward(int localPort, String remoteSocketName,
+ DeviceUnixSocketNamespace namespace) throws TimeoutException,
+ AdbCommandRejectedException, IOException {
+ AdbHelper.createForward(AndroidDebugBridge.getSocketAddress(), this,
+ String.format("tcp:%d", localPort), //$NON-NLS-1$
+ String.format("%s:%s", namespace.getType(), remoteSocketName)); //$NON-NLS-1$
}
@Override
public void removeForward(int localPort, int remotePort)
throws TimeoutException, AdbCommandRejectedException, IOException {
- AdbHelper.removeForward(AndroidDebugBridge.getSocketAddress(), this, localPort, remotePort);
+ AdbHelper.removeForward(AndroidDebugBridge.getSocketAddress(), this,
+ String.format("tcp:%d", localPort), //$NON-NLS-1$
+ String.format("tcp:%d", remotePort)); //$NON-NLS-1$
+ }
+
+ @Override
+ public void removeForward(int localPort, String remoteSocketName,
+ DeviceUnixSocketNamespace namespace) throws TimeoutException,
+ AdbCommandRejectedException, IOException {
+ AdbHelper.removeForward(AndroidDebugBridge.getSocketAddress(), this,
+ String.format("tcp:%d", localPort), //$NON-NLS-1$
+ String.format("%s:%s", namespace.getType(), remoteSocketName)); //$NON-NLS-1$
}
/*
diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java b/ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java
index 9ba068b..41637e2 100644
--- a/ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java
+++ b/ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java
@@ -42,6 +42,7 @@ public interface IDevice {
public static final int CHANGE_BUILD_INFO = 0x0004;
/** @deprecated Use {@link #PROP_BUILD_API_LEVEL}. */
+ @Deprecated
public final static String PROP_BUILD_VERSION_NUMBER = PROP_BUILD_API_LEVEL;
public final static String MNT_EXTERNAL_STORAGE = "EXTERNAL_STORAGE"; //$NON-NLS-1$
@@ -80,6 +81,25 @@ public interface IDevice {
}
/**
+ * Namespace of a Unix Domain Socket created on the device.
+ */
+ public static enum DeviceUnixSocketNamespace {
+ ABSTRACT("localabstract"), //$NON-NLS-1$
+ FILESYSTEM("localfilesystem"), //$NON-NLS-1$
+ RESERVED("localreserved"); //$NON-NLS-1$
+
+ private String mType;
+
+ private DeviceUnixSocketNamespace(String type) {
+ mType = type;
+ }
+
+ String getType() {
+ return mType;
+ }
+ };
+
+ /**
* Returns the serial number of the device.
*/
public String getSerialNumber();
@@ -334,6 +354,21 @@ public interface IDevice {
throws TimeoutException, AdbCommandRejectedException, IOException;
/**
+ * Creates a port forwarding between a local TCP port and a remote Unix Domain Socket.
+ *
+ * @param localPort the local port to forward
+ * @param remoteSocketName name of the unix domain socket created on the device
+ * @param namespace namespace in which the unix domain socket was created
+ * @return <code>true</code> if success.
+ * @throws TimeoutException in case of timeout on the connection.
+ * @throws AdbCommandRejectedException if adb rejects the command
+ * @throws IOException in case of I/O error on the connection.
+ */
+ public void createForward(int localPort, String remoteSocketName,
+ DeviceUnixSocketNamespace namespace)
+ throws TimeoutException, AdbCommandRejectedException, IOException;
+
+ /**
* Removes a port forwarding between a local and a remote port.
*
* @param localPort the local port to forward
@@ -347,6 +382,21 @@ public interface IDevice {
throws TimeoutException, AdbCommandRejectedException, IOException;
/**
+ * Removes an existing port forwarding between a local and a remote port.
+ *
+ * @param localPort the local port to forward
+ * @param remoteSocketName the remote unix domain socket name.
+ * @param namespace namespace in which the unix domain socket was created
+ * @return <code>true</code> if success.
+ * @throws TimeoutException in case of timeout on the connection.
+ * @throws AdbCommandRejectedException if adb rejects the command
+ * @throws IOException in case of I/O error on the connection.
+ */
+ public void removeForward(int localPort, String remoteSocketName,
+ DeviceUnixSocketNamespace namespace)
+ throws TimeoutException, AdbCommandRejectedException, IOException;
+
+ /**
* Returns the name of the client by pid or <code>null</code> if pid is unknown
* @param pid the pid of the client.
*/