diff --git a/src/se/vidstige/jadb/AndroidDevice.java b/src/se/vidstige/jadb/AndroidDevice.java index 7e017e6..71e573b 100644 --- a/src/se/vidstige/jadb/AndroidDevice.java +++ b/src/se/vidstige/jadb/AndroidDevice.java @@ -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 + ":"; diff --git a/test/se/vidstige/jadb/test/AndroidDeviceTestCases.java b/test/se/vidstige/jadb/test/AndroidDeviceTestCases.java index c3a7257..a2106f4 100644 --- a/test/se/vidstige/jadb/test/AndroidDeviceTestCases.java +++ b/test/se/vidstige/jadb/test/AndroidDeviceTestCases.java @@ -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 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 devices = jadb.getDevices(); + AndroidDevice device = devices.get(0); + device.executeShell("cmd", "foo", "bar"); } }