auto import from //branches/cupcake/...@130745
This commit is contained in:
@@ -268,56 +268,61 @@ 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;
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
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 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");
|
||||
byte[] request = formAdbRequest("shell:" + command); //$NON-NLS-1$
|
||||
if (write(adbChan, request) == false)
|
||||
throw new IOException("failed submitting shell command");
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
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.");
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
AdbResponse resp = readAdbResponse(adbChan, false /* readDiagString */);
|
||||
if (!resp.ioSuccess || !resp.okay) {
|
||||
throw new IOException("Device rejected command: " + resp.message);
|
||||
}
|
||||
|
||||
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.");
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
AdbResponse resp = readAdbResponse(adbChan, false /* readDiagString */);
|
||||
if (!resp.ioSuccess || !resp.okay) {
|
||||
throw new IOException("Device rejected command: " + resp.message);
|
||||
}
|
||||
|
||||
adbChan.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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><build></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.
|
||||
|
||||
Reference in New Issue
Block a user