8000 Automatically tries to launch adb server. by vidstige · Pull Request #6 · vidstige/jadb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Automatically tries to launch adb server. #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/se/vidstige/jadb/AdbServerLauncher.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
17 changes: 13 additions & 4 deletions test/se/vidstige/jadb/test/RealDeviceTestCases.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,6 +14,17 @@ public class RealDeviceTestCases {

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
public void connect() throws IOException {
try {
Expand Down
0