mirror of
https://github.com/revanced/jadb.git
synced 2024-11-19 10:39:23 +01:00
Adding execute shell command
This commit is contained in:
parent
068ef51f1b
commit
f3031c254b
@ -16,11 +16,26 @@ public class AndroidDevice {
|
|||||||
return serial;
|
return serial;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getStatus() throws IOException, JadbException {
|
public String getState() throws IOException, JadbException {
|
||||||
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 {
|
||||||
|
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() {
|
private String getPrefix() {
|
||||||
//return "host-serial:" + serial + ":";
|
//return "host-serial:" + serial + ":";
|
||||||
|
@ -6,14 +6,24 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import se.vidstige.jadb.AndroidDevice;
|
import se.vidstige.jadb.AndroidDevice;
|
||||||
import se.vidstige.jadb.JadbConnection;
|
import se.vidstige.jadb.JadbConnection;
|
||||||
|
import se.vidstige.jadb.JadbException;
|
||||||
|
|
||||||
public class AndroidDeviceTestCases {
|
public class AndroidDeviceTestCases {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() throws Exception {
|
public void testGetState() throws Exception {
|
||||||
JadbConnection jadb = new JadbConnection();
|
JadbConnection jadb = new JadbConnection();
|
||||||
List<AndroidDevice> devices = jadb.getDevices();
|
List<AndroidDevice> devices = jadb.getDevices();
|
||||||
AndroidDevice device = devices.get(0);
|
AndroidDevice device = devices.get(0);
|
||||||
device.getStatus();
|
device.getState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected=JadbException.class)
|
||||||
|
public void invalidShellCommand() throws Exception
|
||||||
|
{
|
||||||
|
JadbConnection jadb = new JadbConnection();
|
||||||
|
List<AndroidDevice> devices = jadb.getDevices();
|
||||||
|
AndroidDevice device = devices.get(0);
|
||||||
|
device.executeShell("cmd", "foo", "bar");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user