mirror of
https://github.com/revanced/jadb.git
synced 2025-04-30 06:34:39 +02:00
Made it possible to create a android device that connects to any device
This commit is contained in:
parent
5723a7ce27
commit
4b162f41ad
7
.idea/dictionaries/vidstige.xml
generated
Normal file
7
.idea/dictionaries/vidstige.xml
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<component name="ProjectDictionaryState">
|
||||
<dictionary name="vidstige">
|
||||
<words>
|
||||
<w>jadb</w>
|
||||
</words>
|
||||
</dictionary>
|
||||
</component>
|
@ -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;
|
||||
}
|
||||
|
||||
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,17 +62,17 @@ public class AndroidDevice {
|
||||
shellLine.append(arg);
|
||||
}
|
||||
send("shell:" + shellLine.toString());
|
||||
}
|
||||
|
||||
public void push(String localPath, String remotePath) throws IOException, JadbException {
|
||||
selectTransport();
|
||||
}
|
||||
|
||||
private void send(String command) throws IOException, JadbException {
|
||||
transport.send(command);
|
||||
transport.verifyResponse();
|
||||
}
|
||||
|
||||
public void push(String localPath, String remotePath) {
|
||||
|
||||
}
|
||||
|
||||
private void send(String command) throws IOException {
|
||||
transport.send(getPrefix() + command);
|
||||
}
|
||||
|
||||
private String getPrefix() {
|
||||
//return "host-serial:" + serial + ":";
|
||||
return "host-local:";
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user