mirror of
https://github.com/revanced/jadb.git
synced 2025-02-06 07:26:48 +01:00
Adding get devices method
This commit is contained in:
parent
87ee4c5d83
commit
2799f05250
@ -22,19 +22,38 @@ public class JadbConnection {
|
||||
send("host:version");
|
||||
verifyResponse();
|
||||
}
|
||||
|
||||
|
||||
public void getDevices() throws IOException, JadbException
|
||||
{
|
||||
send("host:devices");
|
||||
verifyResponse();
|
||||
String body = readString();
|
||||
System.out.println(body);
|
||||
}
|
||||
|
||||
private String readString() throws IOException {
|
||||
String encodedLength = readString(4);
|
||||
int length = Integer.parseInt(encodedLength, 16);
|
||||
return readString(length);
|
||||
}
|
||||
|
||||
public void close() throws IOException
|
||||
{
|
||||
_socket.close();
|
||||
}
|
||||
|
||||
private void verifyResponse() throws IOException, JadbException {
|
||||
String response = readString(4);
|
||||
if ("OKAY".equals(response) == false) throw new JadbException("command failed");
|
||||
}
|
||||
|
||||
private String readString(int length) throws IOException {
|
||||
DataInput reader = new DataInputStream(_socket.getInputStream());
|
||||
byte[] responseBuffer = new byte[4];
|
||||
byte[] responseBuffer = new byte[length];
|
||||
reader.readFully(responseBuffer);
|
||||
String response = new String(responseBuffer, Charset.forName("utf-8"));
|
||||
if ("OKAY".equals(response) == false) throw new JadbException("command failed");
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
private String getCommandLength(String command) {
|
||||
return String.format("%04x", Integer.valueOf(command.length()));
|
||||
|
@ -7,8 +7,15 @@ import se.vidstige.jadb.JadbConnection;
|
||||
public class JadbTestCases {
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
public void testGetHostVersion() throws Exception {
|
||||
JadbConnection jadb = new JadbConnection();
|
||||
jadb.getHostVersion();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDevices() throws Exception
|
||||
{
|
||||
JadbConnection jadb = new JadbConnection();
|
||||
jadb.getDevices();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user