Automatically tries to launch adb server.

Fixes issue #3.
This commit is contained in:
Samuel Carlsson 2016-03-28 21:09:00 +02:00
parent 58db71039d
commit 6c1835cc11
2 changed files with 41 additions and 4 deletions

View File

@ -0,0 +1,34 @@
package se.vidstige.jadb;
import java.io.IOException;
/**
* Launches the ADB server
*/
public class AdbServerLauncher {
private Runtime runtime;
public AdbServerLauncher() {
this(Runtime.getRuntime());
}
public AdbServerLauncher(Runtime runtime) {
this.runtime = runtime;
}
private String findAdbExecutable() {
String android_home = System.getenv("ANDROID_HOME");
if (android_home == null || android_home.equals("")) {
return "adb";
}
return android_home + "/platform-tools/adb";
}
public void launch() throws IOException, InterruptedException {
Process p = runtime.exec(new String[]{findAdbExecutable(), "start-server"});
p.waitFor();
int exitValue = p.exitValue();
if (exitValue != 0) throw new IOException("adb exited with exit code: " + exitValue);
}
}

View File

@ -1,11 +1,9 @@
package se.vidstige.jadb.test;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import se.vidstige.jadb.JadbConnection;
import se.vidstige.jadb.JadbDevice;
import se.vidstige.jadb.JadbException;
import se.vidstige.jadb.RemoteFile;
import se.vidstige.jadb.*;
import java.io.File;
import java.io.FileOutputStream;
@ -16,6 +14,11 @@ public class RealDeviceTestCases {
private JadbConnection jadb;
@BeforeClass
public static void tryToStartAdbServer() throws IOException, InterruptedException {
new AdbServerLauncher().launch();
}
@Before
public void connect() throws IOException {
try {