Java Code Examples for com.android.ddmlib.AndroidDebugBridge#initIfNeeded()

The following examples show how to use com.android.ddmlib.AndroidDebugBridge#initIfNeeded() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DdmlibAdbServer.java    From bundletool with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes ADB server, optionally restarting it if it points at a different location.
 *
 * <p>Can be called multiple times.
 *
 * @param pathToAdb location of the ADB server to start.
 */
@Override
public synchronized void init(Path pathToAdb) {
  checkState(state != State.CLOSED, "Android Debug Bridge has been closed.");
  if (state.equals(State.INITIALIZED)) {
    checkState(
        pathToAdb.equals(this.pathToAdb),
        "Re-initializing DdmlibAdbServer with a different ADB path. Expected: '%s', got '%s'.",
        this.pathToAdb,
        pathToAdb);
    return;
  }
  AndroidDebugBridge.initIfNeeded(/* clientSupport= */ false);
  this.adb = AndroidDebugBridge.createBridge(pathToAdb.toString(), /* forceNewBridge= */ false);

  if (adb == null) {
    throw CommandExecutionException.builder()
        .withInternalMessage("Failed to start ADB server.")
        .build();
  }

  this.pathToAdb = pathToAdb;
  this.state = State.INITIALIZED;
}
 
Example 2
Source File: AndroidSdkProvider.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
protected void updateAdb() {
    AndroidSdk sdk = defaultSdk.get();
    if (sdk != null) {
        final FileObject path = sdk.findTool(ADB_TOOL);
        if (path != null) {
            ClientData.class.getClassLoader().clearAssertionStatus();      //qattern
            DebugPortManager.setProvider(DebugPortProvider.getDefault());
            AndroidDebugBridge.initIfNeeded(true);
            String adbLocation = FileUtil.toFile(path).getAbsolutePath();
            String lastLocation = adbPath.getAndSet(adbLocation);
            pcs.firePropertyChange(PROP_DEFAULT_ADB_PATH, lastLocation, adbLocation);
            AndroidDebugBridge bridge = AndroidDebugBridge.createBridge(adbLocation, false);
            AndroidDebugBridge lastAdb = adb.getAndSet(bridge);
            pcs.firePropertyChange(PROP_DEFAULT_ADB, lastAdb, bridge);
        }
    }
}
 
Example 3
Source File: InstrumentationTestRunner.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Creates connection to adb and waits for this connection to be initialized and receive initial
 * list of devices.
 */
@Nullable
@SuppressWarnings("PMD.EmptyCatchBlock")
private AndroidDebugBridge createAdb() throws InterruptedException {
  AndroidDebugBridge.initIfNeeded(/* clientSupport */ false);
  AndroidDebugBridge adb = AndroidDebugBridge.createBridge(this.adbExecutablePath, false);
  if (adb == null) {
    System.err.println("Failed to connect to adb. Make sure adb server is running.");
    return null;
  }

  long start = System.currentTimeMillis();
  while (!isAdbInitialized(adb)) {
    long timeLeft = start + ADB_CONNECT_TIMEOUT_MS - System.currentTimeMillis();
    if (timeLeft <= 0) {
      break;
    }
    Thread.sleep(ADB_CONNECT_TIME_STEP_MS);
  }
  return isAdbInitialized(adb) ? adb : null;
}