Adding execute shell command

This commit is contained in:
Samuel Carlsson 2013-07-26 09:24:03 +02:00
parent 068ef51f1b
commit f3031c254b
2 changed files with 29 additions and 4 deletions

View File

@ -16,11 +16,26 @@ public class AndroidDevice {
return serial;
}
public String getStatus() throws IOException, JadbException {
public String getState() throws IOException, JadbException {
transport.send(getPrefix() + "get-state");
transport.verifyResponse();
return transport.readString();
}
}
public void executeShell(String command, String ... args) throws IOException, JadbException {
StringBuilder shellLine = new StringBuilder(command);
for (String arg : args)
{
shellLine.append(" ");
shellLine.append(arg);
}
send("shell:" + shellLine.toString());
transport.verifyResponse();
}
private void send(String command) throws IOException {
transport.send(getPrefix() + command);
}
private String getPrefix() {
//return "host-serial:" + serial + ":";

View File

@ -6,14 +6,24 @@ import org.junit.Test;
import se.vidstige.jadb.AndroidDevice;
import se.vidstige.jadb.JadbConnection;
import se.vidstige.jadb.JadbException;
public class AndroidDeviceTestCases {
@Test
public void test() throws Exception {
public void testGetState() throws Exception {
JadbConnection jadb = new JadbConnection();
List<AndroidDevice> devices = jadb.getDevices();
AndroidDevice device = devices.get(0);
device.getStatus();
device.getState();
}
@Test(expected=JadbException.class)
public void invalidShellCommand() throws Exception
{
JadbConnection jadb = new JadbConnection();
List<AndroidDevice> devices = jadb.getDevices();
AndroidDevice device = devices.get(0);
device.executeShell("cmd", "foo", "bar");
}
}