aboutsummaryrefslogtreecommitdiffstats
path: root/ddms/libs/ddmlib/src
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-02-10 15:43:58 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-02-10 15:43:58 -0800
commit6990abcbc03c25aeff94da27ed6893e7993d2709 (patch)
tree8d48abfa1c567386a1b0e035f52f767c6ed9f519 /ddms/libs/ddmlib/src
parent4da15c90a4f3e67182afce7b41d67f9ffbf511f0 (diff)
downloadsdk-6990abcbc03c25aeff94da27ed6893e7993d2709.zip
sdk-6990abcbc03c25aeff94da27ed6893e7993d2709.tar.gz
sdk-6990abcbc03c25aeff94da27ed6893e7993d2709.tar.bz2
auto import from //branches/cupcake/...@130745
Diffstat (limited to 'ddms/libs/ddmlib/src')
-rw-r--r--ddms/libs/ddmlib/src/com/android/ddmlib/AdbHelper.java346
-rw-r--r--ddms/libs/ddmlib/src/com/android/ddmlib/Device.java8
-rw-r--r--ddms/libs/ddmlib/src/com/android/ddmlib/DeviceMonitor.java8
-rw-r--r--ddms/libs/ddmlib/src/com/android/ddmlib/EmulatorConsole.java6
-rwxr-xr-xddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java8
5 files changed, 200 insertions, 176 deletions
diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/AdbHelper.java b/ddms/libs/ddmlib/src/com/android/ddmlib/AdbHelper.java
index 154bfa1..42022fe 100644
--- a/ddms/libs/ddmlib/src/com/android/ddmlib/AdbHelper.java
+++ b/ddms/libs/ddmlib/src/com/android/ddmlib/AdbHelper.java
@@ -268,55 +268,60 @@ final class AdbHelper {
};
byte[] reply;
- SocketChannel adbChan = SocketChannel.open(adbSockAddr);
- adbChan.configureBlocking(false);
-
- // if the device is not -1, then we first tell adb we're looking to talk
- // to a specific device
- setDevice(adbChan, device);
-
- if (write(adbChan, request) == false)
- throw new IOException("failed asking for frame buffer");
-
- AdbResponse resp = readAdbResponse(adbChan, false /* readDiagString */);
- if (!resp.ioSuccess || !resp.okay) {
- Log.w("ddms", "Got timeout or unhappy response from ADB fb req: "
- + resp.message);
- adbChan.close();
- return null;
- }
-
- reply = new byte[16];
- if (read(adbChan, reply) == false) {
- Log.w("ddms", "got partial reply from ADB fb:");
- Log.hexDump("ddms", LogLevel.WARN, reply, 0, reply.length);
- adbChan.close();
- return null;
- }
- ByteBuffer buf = ByteBuffer.wrap(reply);
- buf.order(ByteOrder.LITTLE_ENDIAN);
-
- imageParams.bpp = buf.getInt();
- imageParams.size = buf.getInt();
- imageParams.width = buf.getInt();
- imageParams.height = buf.getInt();
-
- Log.d("ddms", "image params: bpp=" + imageParams.bpp + ", size="
- + imageParams.size + ", width=" + imageParams.width
- + ", height=" + imageParams.height);
-
- if (write(adbChan, nudge) == false)
- throw new IOException("failed nudging");
-
- reply = new byte[imageParams.size];
- if (read(adbChan, reply) == false) {
- Log.w("ddms", "got truncated reply from ADB fb data");
- adbChan.close();
- return null;
+ SocketChannel adbChan = null;
+ try {
+ adbChan = SocketChannel.open(adbSockAddr);
+ adbChan.configureBlocking(false);
+
+ // if the device is not -1, then we first tell adb we're looking to talk
+ // to a specific device
+ setDevice(adbChan, device);
+
+ if (write(adbChan, request) == false)
+ throw new IOException("failed asking for frame buffer");
+
+ AdbResponse resp = readAdbResponse(adbChan, false /* readDiagString */);
+ if (!resp.ioSuccess || !resp.okay) {
+ Log.w("ddms", "Got timeout or unhappy response from ADB fb req: "
+ + resp.message);
+ adbChan.close();
+ return null;
+ }
+
+ reply = new byte[16];
+ if (read(adbChan, reply) == false) {
+ Log.w("ddms", "got partial reply from ADB fb:");
+ Log.hexDump("ddms", LogLevel.WARN, reply, 0, reply.length);
+ adbChan.close();
+ return null;
+ }
+ ByteBuffer buf = ByteBuffer.wrap(reply);
+ buf.order(ByteOrder.LITTLE_ENDIAN);
+
+ imageParams.bpp = buf.getInt();
+ imageParams.size = buf.getInt();
+ imageParams.width = buf.getInt();
+ imageParams.height = buf.getInt();
+
+ Log.d("ddms", "image params: bpp=" + imageParams.bpp + ", size="
+ + imageParams.size + ", width=" + imageParams.width
+ + ", height=" + imageParams.height);
+
+ if (write(adbChan, nudge) == false)
+ throw new IOException("failed nudging");
+
+ reply = new byte[imageParams.size];
+ if (read(adbChan, reply) == false) {
+ Log.w("ddms", "got truncated reply from ADB fb data");
+ adbChan.close();
+ return null;
+ }
+ imageParams.data = reply;
+ } finally {
+ if (adbChan != null) {
+ adbChan.close();
+ }
}
- imageParams.data = reply;
-
- adbChan.close();
return imageParams;
}
@@ -330,58 +335,61 @@ final class AdbHelper {
throws IOException {
Log.v("ddms", "execute: running " + command);
- SocketChannel adbChan = SocketChannel.open(adbSockAddr);
- adbChan.configureBlocking(false);
-
- // if the device is not -1, then we first tell adb we're looking to talk
- // to a specific device
- setDevice(adbChan, device);
-
- byte[] request = formAdbRequest("shell:" + command); //$NON-NLS-1$
- if (write(adbChan, request) == false)
- throw new IOException("failed submitting shell command");
+ SocketChannel adbChan = null;
+ try {
+ adbChan = SocketChannel.open(adbSockAddr);
+ adbChan.configureBlocking(false);
- AdbResponse resp = readAdbResponse(adbChan, false /* readDiagString */);
- if (!resp.ioSuccess || !resp.okay) {
- Log.e("ddms", "ADB rejected shell command (" + command + "): "
- + resp.message);
- throw new IOException("sad result from adb: " + resp.message);
- }
+ // if the device is not -1, then we first tell adb we're looking to
+ // talk
+ // to a specific device
+ setDevice(adbChan, device);
- byte[] data = new byte[16384];
- ByteBuffer buf = ByteBuffer.wrap(data);
- while (true) {
- int count;
+ byte[] request = formAdbRequest("shell:" + command); //$NON-NLS-1$
+ if (write(adbChan, request) == false)
+ throw new IOException("failed submitting shell command");
- if (rcvr != null && rcvr.isCancelled()) {
- Log.v("ddms", "execute: cancelled");
- break;
+ AdbResponse resp = readAdbResponse(adbChan, false /* readDiagString */);
+ if (!resp.ioSuccess || !resp.okay) {
+ Log.e("ddms", "ADB rejected shell command (" + command + "): " + resp.message);
+ throw new IOException("sad result from adb: " + resp.message);
}
- count = adbChan.read(buf);
- if (count < 0) {
- // we're at the end, we flush the output
- rcvr.flush();
- Log.v("ddms",
- "execute '" + command + "' on '" + device + "' : EOF hit. Read: " + count);
- break;
- } else if (count == 0) {
- try {
- Thread.sleep(WAIT_TIME * 5);
- } catch (InterruptedException ie) {
+ byte[] data = new byte[16384];
+ ByteBuffer buf = ByteBuffer.wrap(data);
+ while (true) {
+ int count;
+
+ if (rcvr != null && rcvr.isCancelled()) {
+ Log.v("ddms", "execute: cancelled");
+ break;
}
- } else {
- if (rcvr != null) {
- rcvr.addOutput(buf.array(), buf.arrayOffset(), buf
- .position());
+
+ count = adbChan.read(buf);
+ if (count < 0) {
+ // we're at the end, we flush the output
+ rcvr.flush();
+ Log.v("ddms", "execute '" + command + "' on '" + device + "' : EOF hit. Read: "
+ + count);
+ break;
+ } else if (count == 0) {
+ try {
+ Thread.sleep(WAIT_TIME * 5);
+ } catch (InterruptedException ie) {
+ }
+ } else {
+ if (rcvr != null) {
+ rcvr.addOutput(buf.array(), buf.arrayOffset(), buf.position());
+ }
+ buf.rewind();
}
- buf.rewind();
}
+ } finally {
+ if (adbChan != null) {
+ adbChan.close();
+ }
+ Log.v("ddms", "execute: returning");
}
-
- adbChan.close();
-
- Log.v("ddms", "execute: returning");
}
/**
@@ -407,49 +415,55 @@ final class AdbHelper {
*/
public static void runLogService(InetSocketAddress adbSockAddr, Device device, String logName,
LogReceiver rcvr) throws IOException {
- SocketChannel adbChan = SocketChannel.open(adbSockAddr);
- adbChan.configureBlocking(false);
-
- // if the device is not -1, then we first tell adb we're looking to talk
- // to a specific device
- setDevice(adbChan, device);
-
- byte[] request = formAdbRequest("log:" + logName);
- if (write(adbChan, request) == false) {
- throw new IOException("failed to submit the log command");
- }
-
- AdbResponse resp = readAdbResponse(adbChan, false /* readDiagString */);
- if (!resp.ioSuccess || !resp.okay) {
- throw new IOException("Device rejected log command: " + resp.message);
- }
-
- byte[] data = new byte[16384];
- ByteBuffer buf = ByteBuffer.wrap(data);
- while (true) {
- int count;
-
- if (rcvr != null && rcvr.isCancelled()) {
- break;
+ SocketChannel adbChan = null;
+
+ try {
+ adbChan = SocketChannel.open(adbSockAddr);
+ adbChan.configureBlocking(false);
+
+ // if the device is not -1, then we first tell adb we're looking to talk
+ // to a specific device
+ setDevice(adbChan, device);
+
+ byte[] request = formAdbRequest("log:" + logName);
+ if (write(adbChan, request) == false) {
+ throw new IOException("failed to submit the log command");
}
-
- count = adbChan.read(buf);
- if (count < 0) {
- break;
- } else if (count == 0) {
- try {
- Thread.sleep(WAIT_TIME * 5);
- } catch (InterruptedException ie) {
+
+ AdbResponse resp = readAdbResponse(adbChan, false /* readDiagString */);
+ if (!resp.ioSuccess || !resp.okay) {
+ throw new IOException("Device rejected log command: " + resp.message);
+ }
+
+ byte[] data = new byte[16384];
+ ByteBuffer buf = ByteBuffer.wrap(data);
+ while (true) {
+ int count;
+
+ if (rcvr != null && rcvr.isCancelled()) {
+ break;
}
- } else {
- if (rcvr != null) {
- rcvr.parseNewData(buf.array(), buf.arrayOffset(), buf.position());
+
+ count = adbChan.read(buf);
+ if (count < 0) {
+ break;
+ } else if (count == 0) {
+ try {
+ Thread.sleep(WAIT_TIME * 5);
+ } catch (InterruptedException ie) {
+ }
+ } else {
+ if (rcvr != null) {
+ rcvr.parseNewData(buf.array(), buf.arrayOffset(), buf.position());
+ }
+ buf.rewind();
}
- buf.rewind();
+ }
+ } finally {
+ if (adbChan != null) {
+ adbChan.close();
}
}
-
- adbChan.close();
}
/**
@@ -464,24 +478,29 @@ final class AdbHelper {
public static boolean createForward(InetSocketAddress adbSockAddr, Device device, int localPort,
int remotePort) throws IOException {
- SocketChannel adbChan = SocketChannel.open(adbSockAddr);
- adbChan.configureBlocking(false);
-
- byte[] request = formAdbRequest(String.format(
- "host-serial:%1$s:forward:tcp:%2$d;tcp:%3$d", //$NON-NLS-1$
- device.serialNumber, localPort, remotePort));
-
- if (write(adbChan, request) == false) {
- throw new IOException("failed to submit the forward command.");
- }
-
- AdbResponse resp = readAdbResponse(adbChan, false /* readDiagString */);
- if (!resp.ioSuccess || !resp.okay) {
- throw new IOException("Device rejected command: " + resp.message);
+ SocketChannel adbChan = null;
+ try {
+ adbChan = SocketChannel.open(adbSockAddr);
+ adbChan.configureBlocking(false);
+
+ byte[] request = formAdbRequest(String.format(
+ "host-serial:%1$s:forward:tcp:%2$d;tcp:%3$d", //$NON-NLS-1$
+ device.serialNumber, localPort, remotePort));
+
+ if (write(adbChan, request) == false) {
+ throw new IOException("failed to submit the forward command.");
+ }
+
+ AdbResponse resp = readAdbResponse(adbChan, false /* readDiagString */);
+ if (!resp.ioSuccess || !resp.okay) {
+ throw new IOException("Device rejected command: " + resp.message);
+ }
+ } finally {
+ if (adbChan != null) {
+ adbChan.close();
+ }
}
- adbChan.close();
-
return true;
}
@@ -497,24 +516,29 @@ final class AdbHelper {
public static boolean removeForward(InetSocketAddress adbSockAddr, Device device, int localPort,
int remotePort) throws IOException {
- SocketChannel adbChan = SocketChannel.open(adbSockAddr);
- adbChan.configureBlocking(false);
-
- byte[] request = formAdbRequest(String.format(
- "host-serial:%1$s:killforward:tcp:%2$d;tcp:%3$d", //$NON-NLS-1$
- device.serialNumber, localPort, remotePort));
-
- if (!write(adbChan, request)) {
- throw new IOException("failed to submit the remove forward command.");
- }
-
- AdbResponse resp = readAdbResponse(adbChan, false /* readDiagString */);
- if (!resp.ioSuccess || !resp.okay) {
- throw new IOException("Device rejected command: " + resp.message);
+ SocketChannel adbChan = null;
+ try {
+ adbChan = SocketChannel.open(adbSockAddr);
+ adbChan.configureBlocking(false);
+
+ byte[] request = formAdbRequest(String.format(
+ "host-serial:%1$s:killforward:tcp:%2$d;tcp:%3$d", //$NON-NLS-1$
+ device.serialNumber, localPort, remotePort));
+
+ if (!write(adbChan, request)) {
+ throw new IOException("failed to submit the remove forward command.");
+ }
+
+ AdbResponse resp = readAdbResponse(adbChan, false /* readDiagString */);
+ if (!resp.ioSuccess || !resp.okay) {
+ throw new IOException("Device rejected command: " + resp.message);
+ }
+ } finally {
+ if (adbChan != null) {
+ adbChan.close();
+ }
}
- adbChan.close();
-
return true;
}
diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/Device.java b/ddms/libs/ddmlib/src/com/android/ddmlib/Device.java
index 8291f59..34ef432 100644
--- a/ddms/libs/ddmlib/src/com/android/ddmlib/Device.java
+++ b/ddms/libs/ddmlib/src/com/android/ddmlib/Device.java
@@ -69,8 +69,8 @@ public final class Device implements IDevice {
/** Serial number of the device */
String serialNumber = null;
- /** Name of the vm */
- String mVmName = null;
+ /** Name of the AVD */
+ String mAvdName = null;
/** State of the device. */
DeviceState state = null;
@@ -94,8 +94,8 @@ public final class Device implements IDevice {
return serialNumber;
}
- public String getVmName() {
- return mVmName;
+ public String getAvdName() {
+ return mAvdName;
}
diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/DeviceMonitor.java b/ddms/libs/ddmlib/src/com/android/ddmlib/DeviceMonitor.java
index 8547ac1..f9d0fa0 100644
--- a/ddms/libs/ddmlib/src/com/android/ddmlib/DeviceMonitor.java
+++ b/ddms/libs/ddmlib/src/com/android/ddmlib/DeviceMonitor.java
@@ -420,11 +420,11 @@ final class DeviceMonitor {
device.executeShellCommand(GetPropReceiver.GETPROP_COMMAND,
new GetPropReceiver(device));
- // now get the emulator VM name (if applicable).
+ // now get the emulator Virtual Device name (if applicable).
if (device.isEmulator()) {
EmulatorConsole console = EmulatorConsole.getConsole(device);
if (console != null) {
- device.mVmName = console.getVmName();
+ device.mAvdName = console.getAvdName();
}
}
} catch (IOException e) {
@@ -470,7 +470,7 @@ final class DeviceMonitor {
} catch (IOException e1) {
// we can ignore that one. It may already have been closed.
}
- Log.e("DeviceMonitor",
+ Log.d("DeviceMonitor",
"Connection Failure when starting to monitor device '"
+ device + "' : " + e.getMessage());
}
@@ -558,7 +558,7 @@ final class DeviceMonitor {
processIncomingJdwpData(device, socket, length);
} catch (IOException ioe) {
- Log.e("DeviceMonitor",
+ Log.d("DeviceMonitor",
"Error reading jdwp list: " + ioe.getMessage());
socket.close();
diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/EmulatorConsole.java b/ddms/libs/ddmlib/src/com/android/ddmlib/EmulatorConsole.java
index e00073c..74c432d 100644
--- a/ddms/libs/ddmlib/src/com/android/ddmlib/EmulatorConsole.java
+++ b/ddms/libs/ddmlib/src/com/android/ddmlib/EmulatorConsole.java
@@ -54,7 +54,7 @@ public final class EmulatorConsole {
private final static String HOST = "127.0.0.1"; //$NON-NLS-1$
private final static String COMMAND_PING = "help\r\n"; //$NON-NLS-1$
- private final static String COMMAND_VM_NAME = "vm name\r\n"; //$NON-NLS-1$
+ private final static String COMMAND_AVD_NAME = "vm name\r\n"; //$NON-NLS-1$ // TODO change with emulator
private final static String COMMAND_KILL = "kill\r\n"; //$NON-NLS-1$
private final static String COMMAND_GSM_STATUS = "gsm status\r\n"; //$NON-NLS-1$
private final static String COMMAND_GSM_CALL = "gsm call %1$s\r\n"; //$NON-NLS-1$
@@ -309,8 +309,8 @@ public final class EmulatorConsole {
}
}
- public synchronized String getVmName() {
- if (sendCommand(COMMAND_VM_NAME)) {
+ public synchronized String getAvdName() {
+ if (sendCommand(COMMAND_AVD_NAME)) {
String[] result = readLines();
if (result != null && result.length == 2) { // this should be the name on first line,
// and ok on 2nd line
diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java b/ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java
index 61d1ca4..664b0c9 100755
--- a/ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java
+++ b/ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java
@@ -46,13 +46,13 @@ public interface IDevice {
public String getSerialNumber();
/**
- * Returns the name of the VM the emulator is running.
+ * Returns the name of the AVD the emulator is running.
* <p/>This is only valid if {@link #isEmulator()} returns true.
- * <p/>If the emulator is not running any VM (for instance it's running from an Android source
+ * <p/>If the emulator is not running any AVD (for instance it's running from an Android source
* tree build), this method will return "<code>&lt;build&gt;</code>".
- * @return the name of the VM or <code>null</code> if there isn't any.
+ * @return the name of the AVD or <code>null</code> if there isn't any.
*/
- public String getVmName();
+ public String getAvdName();
/**
* Returns the state of the device.