mirror of
https://github.com/revanced/jadb.git
synced 2025-05-03 16:14:25 +02:00
Merge pull request #6 from vidstige/launch-adb-automagically
Automatically tries to launch adb server.
This commit is contained in:
commit
17e43e650d
34
src/se/vidstige/jadb/AdbServerLauncher.java
Normal file
34
src/se/vidstige/jadb/AdbServerLauncher.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,9 @@
|
|||||||
package se.vidstige.jadb.test;
|
package se.vidstige.jadb.test;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import se.vidstige.jadb.JadbConnection;
|
import se.vidstige.jadb.*;
|
||||||
import se.vidstige.jadb.JadbDevice;
|
|
||||||
import se.vidstige.jadb.JadbException;
|
|
||||||
import se.vidstige.jadb.RemoteFile;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@ -16,6 +14,17 @@ public class RealDeviceTestCases {
|
|||||||
|
|
||||||
private JadbConnection jadb;
|
private JadbConnection jadb;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void tryToStartAdbServer() {
|
||||||
|
try {
|
||||||
|
new AdbServerLauncher().launch();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Could not start adb-server");
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
System.out.println("Could not start adb-server");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void connect() throws IOException {
|
public void connect() throws IOException {
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user