com.android.ddmlib.DdmPreferences Java Examples

The following examples show how to use com.android.ddmlib.DdmPreferences. 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: HJAdb.java    From HJMirror with MIT License 6 votes vote down vote up
/**
 * Start and find Devices.
 */
public IDevice[] startAndFind() throws Exception {
    if (adb == null) {
        AndroidDebugBridge.init(false);
        DdmPreferences.setTimeOut(20000);
        adb = AndroidDebugBridge.createBridge(getAdbExec(), true);
        if (adb == null) {
            throw new Exception("Adb initilized failed!");
        }
    }
    if (adb.hasInitialDeviceList()) {
        IDevice[] devices = adb.getDevices();
        if (devices != null) {
            return devices;
        } else {
            return new IDevice[]{};
        }
    }
    return new IDevice[]{};
}
 
Example #2
Source File: AwoInstaller.java    From atlas with Apache License 2.0 5 votes vote down vote up
protected static AndroidDebugBridge initAndroidDebugBridge(AndroidBuilder androidBuilder) {
    synchronized (ADB_LOCK) {
        if (!adbInitialized) {
            DdmPreferences.setTimeOut(adbConnectionTimeout);
            AndroidDebugBridge.init(false);
            adbInitialized = true;
        }
        AndroidDebugBridge androidDebugBridge = AndroidDebugBridge.createBridge(
            androidBuilder.getSdkInfo().getAdb().getAbsolutePath(), false);
        waitUntilConnected(androidDebugBridge);
        return androidDebugBridge;
    }
}
 
Example #3
Source File: AdbHelper.java    From buck with Apache License 2.0 5 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 static AndroidDebugBridge createAdb(
    AndroidPlatformTarget androidPlatformTarget, ExecutionContext context, int adbTimeout)
    throws InterruptedException {
  DdmPreferences.setTimeOut(adbTimeout);

  try {
    AndroidDebugBridge.init(/* clientSupport */ false);
  } catch (IllegalStateException ex) {
    // ADB was already initialized, we're fine, so just ignore.
  }

  String adbExecutable = androidPlatformTarget.getAdbExecutable().toString();
  log.debug("Using %s to create AndroidDebugBridge", adbExecutable);
  AndroidDebugBridge adb = AndroidDebugBridge.createBridge(adbExecutable, false);
  if (adb == null) {
    context
        .getConsole()
        .printBuildFailure("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;
}