diff --git a/.idea/dictionaries/vidstige.xml b/.idea/dictionaries/vidstige.xml new file mode 100644 index 0000000..32e3332 --- /dev/null +++ b/.idea/dictionaries/vidstige.xml @@ -0,0 +1,7 @@ + + + + jadb + + + \ No newline at end of file diff --git a/src/se/vidstige/jadb/AndroidDevice.java b/src/se/vidstige/jadb/AndroidDevice.java index f726b36..4b555d1 100644 --- a/src/se/vidstige/jadb/AndroidDevice.java +++ b/src/se/vidstige/jadb/AndroidDevice.java @@ -3,26 +3,56 @@ package se.vidstige.jadb; import java.io.IOException; public class AndroidDevice { - private final String serial; + private String serial; private Transport transport; - + private boolean selected = false; + AndroidDevice(String serial, String type, Transport transport) { this.serial = serial; this.transport = transport; - } - + } + + static AndroidDevice createAny(Transport transport) { return new AndroidDevice(transport); } + + private AndroidDevice(Transport transport) + { + serial = null; + this.transport = transport; + } + + private void selectTransport() throws IOException, JadbException { + if (!selected) + { + if (serial == null) + { + transport.send("host:transport-any"); + transport.verifyResponse(); + } + else + { + transport.send("host:transport:" + serial); + transport.verifyResponse(); + + } + selected = true; + } + } + public String getSerial() { - return serial; + return serial; } public String getState() throws IOException, JadbException { + selectTransport(); transport.send(getPrefix() + "get-state"); transport.verifyResponse(); return transport.readString(); } public void executeShell(String command, String ... args) throws IOException, JadbException { + selectTransport(); + StringBuilder shellLine = new StringBuilder(command); for (String arg : args) { @@ -32,15 +62,15 @@ public class AndroidDevice { shellLine.append(arg); } send("shell:" + shellLine.toString()); - transport.verifyResponse(); } - public void push(String localPath, String remotePath) { - + public void push(String localPath, String remotePath) throws IOException, JadbException { + selectTransport(); } - - private void send(String command) throws IOException { - transport.send(getPrefix() + command); + + private void send(String command) throws IOException, JadbException { + transport.send(command); + transport.verifyResponse(); } private String getPrefix() { diff --git a/src/se/vidstige/jadb/JadbConnection.java b/src/se/vidstige/jadb/JadbConnection.java index a5de9f7..56d4333 100644 --- a/src/se/vidstige/jadb/JadbConnection.java +++ b/src/se/vidstige/jadb/JadbConnection.java @@ -2,7 +2,6 @@ package se.vidstige.jadb; import java.io.IOException; import java.net.Socket; -import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; @@ -15,12 +14,12 @@ public class JadbConnection { private final Transport main; - public JadbConnection() throws UnknownHostException, IOException + public JadbConnection() throws IOException { this("localhost", DEFAULTPORT); } - public JadbConnection(String host, int port) throws UnknownHostException, IOException + public JadbConnection(String host, int port) throws IOException { this.host = host; this.port = port; @@ -57,4 +56,8 @@ public class JadbConnection { } return devices; } + + public AndroidDevice getAnyDevice() { + return AndroidDevice.createAny(main); + } }