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;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class AndroidDevice {
|
public class AndroidDevice {
|
||||||
private final String serial;
|
private String serial;
|
||||||
private Transport transport;
|
private Transport transport;
|
||||||
|
private boolean selected = false;
|
||||||
|
|
||||||
AndroidDevice(String serial, String type, Transport transport) {
|
AndroidDevice(String serial, String type, Transport transport) {
|
||||||
this.serial = serial;
|
this.serial = serial;
|
||||||
this.transport = transport;
|
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()
|
public String getSerial()
|
||||||
{
|
{
|
||||||
return serial;
|
return serial;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getState() throws IOException, JadbException {
|
public String getState() throws IOException, JadbException {
|
||||||
|
selectTransport();
|
||||||
transport.send(getPrefix() + "get-state");
|
transport.send(getPrefix() + "get-state");
|
||||||
transport.verifyResponse();
|
transport.verifyResponse();
|
||||||
return transport.readString();
|
return transport.readString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void executeShell(String command, String ... args) throws IOException, JadbException {
|
public void executeShell(String command, String ... args) throws IOException, JadbException {
|
||||||
|
selectTransport();
|
||||||
|
|
||||||
StringBuilder shellLine = new StringBuilder(command);
|
StringBuilder shellLine = new StringBuilder(command);
|
||||||
for (String arg : args)
|
for (String arg : args)
|
||||||
{
|
{
|
||||||
@ -32,15 +62,15 @@ public class AndroidDevice {
|
|||||||
shellLine.append(arg);
|
shellLine.append(arg);
|
||||||
}
|
}
|
||||||
send("shell:" + shellLine.toString());
|
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 {
|
private void send(String command) throws IOException, JadbException {
|
||||||
transport.send(getPrefix() + command);
|
transport.send(command);
|
||||||
|
transport.verifyResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPrefix() {
|
private String getPrefix() {
|
||||||
|
@ -2,7 +2,6 @@ package se.vidstige.jadb;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -15,12 +14,12 @@ public class JadbConnection {
|
|||||||
|
|
||||||
private final Transport main;
|
private final Transport main;
|
||||||
|
|
||||||
public JadbConnection() throws UnknownHostException, IOException
|
public JadbConnection() throws IOException
|
||||||
{
|
{
|
||||||
this("localhost", DEFAULTPORT);
|
this("localhost", DEFAULTPORT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JadbConnection(String host, int port) throws UnknownHostException, IOException
|
public JadbConnection(String host, int port) throws IOException
|
||||||
{
|
{
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
@ -57,4 +56,8 @@ public class JadbConnection {
|
|||||||
}
|
}
|
||||||
return devices;
|
return devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AndroidDevice getAnyDevice() {
|
||||||
|
return AndroidDevice.createAny(main);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user