Search in sources :

Example 1 with AndroidDebugBridge

use of com.android.ddmlib.AndroidDebugBridge in project buck by facebook.

the class AdbHelper method createAdb.

/**
   * 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(ExecutionContext context) throws InterruptedException {
    DdmPreferences.setTimeOut(60000);
    try {
        AndroidDebugBridge.init(/* clientSupport */
        false);
    } catch (IllegalStateException ex) {
    // ADB was already initialized, we're fine, so just ignore.
    }
    AndroidDebugBridge adb = AndroidDebugBridge.createBridge(context.getPathToAdbExecutable(), false);
    if (adb == null) {
        console.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;
}
Also used : AndroidDebugBridge(com.android.ddmlib.AndroidDebugBridge) Nullable(javax.annotation.Nullable)

Example 2 with AndroidDebugBridge

use of com.android.ddmlib.AndroidDebugBridge in project buck by facebook.

the class AdbHelper method getDevices.

@SuppressForbidden
public List<IDevice> getDevices(boolean quiet) throws InterruptedException {
    // Initialize adb connection.
    AndroidDebugBridge adb = createAdb(context);
    if (adb == null) {
        console.printBuildFailure("Failed to create adb connection.");
        return Lists.newArrayList();
    }
    // Build list of matching devices.
    List<IDevice> devices = filterDevices(adb.getDevices());
    if (devices != null && devices.size() > 1) {
        // Found multiple devices but multi-install mode is not enabled.
        if (!options.isMultiInstallModeEnabled()) {
            console.printBuildFailure(String.format("%d device(s) matches specified device filter (1 expected).\n" + "Either disconnect other devices or enable multi-install mode (%s).", devices.size(), AdbOptions.MULTI_INSTALL_MODE_SHORT_ARG));
            return Lists.newArrayList();
        }
        if (!quiet) {
            // Report if multiple devices are matching the filter.
            console.getStdOut().printf("Found " + devices.size() + " matching devices.\n");
        }
    }
    if (devices == null && restartAdbOnFailure) {
        console.printErrorText("No devices found with adb, restarting adb-server.");
        adb.restart();
        devices = filterDevices(adb.getDevices());
    }
    if (devices == null) {
        return Lists.newArrayList();
    }
    return devices;
}
Also used : IDevice(com.android.ddmlib.IDevice) AndroidDebugBridge(com.android.ddmlib.AndroidDebugBridge) SuppressForbidden(com.facebook.buck.annotations.SuppressForbidden)

Example 3 with AndroidDebugBridge

use of com.android.ddmlib.AndroidDebugBridge in project buck by facebook.

the class InstrumentationTestRunner method createAdb.

/**
   * 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;
}
Also used : AndroidDebugBridge(com.android.ddmlib.AndroidDebugBridge)

Example 4 with AndroidDebugBridge

use of com.android.ddmlib.AndroidDebugBridge in project adb-idea by pbreault.

the class MyDeviceChooser method getSelectedDevices.

@NotNull
public IDevice[] getSelectedDevices() {
    int[] rows = mySelectedRows != null ? mySelectedRows : myDeviceTable.getSelectedRows();
    List<IDevice> result = new ArrayList<IDevice>();
    for (int row : rows) {
        if (row >= 0) {
            Object serial = myDeviceTable.getValueAt(row, SERIAL_COLUMN_INDEX);
            final AndroidDebugBridge bridge = AndroidSdkUtils.getDebugBridge(myFacet.getModule().getProject());
            if (bridge == null) {
                return EMPTY_DEVICE_ARRAY;
            }
            IDevice[] devices = getFilteredDevices(bridge);
            for (IDevice device : devices) {
                if (device.getSerialNumber().equals(serial.toString())) {
                    result.add(device);
                    break;
                }
            }
        }
    }
    return result.toArray(new IDevice[result.size()]);
}
Also used : TIntArrayList(gnu.trove.TIntArrayList) IDevice(com.android.ddmlib.IDevice) AndroidDebugBridge(com.android.ddmlib.AndroidDebugBridge) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with AndroidDebugBridge

use of com.android.ddmlib.AndroidDebugBridge in project otertool by wuntee.

the class Test method main.

/**
	 * @param args
	 * @throws InterruptedException 
	 */
public static void main(String[] args) throws InterruptedException {
    AndroidDebugBridge.init(true);
    AndroidDebugBridge adb = AndroidDebugBridge.createBridge("/Applications/android-sdk-macosx/platform-tools/adb", true);
    while (!adb.hasInitialDeviceList()) {
        System.out.println("Waiting...");
        Thread.sleep(1000);
    }
    for (IDevice dev : adb.getDevices()) {
        System.out.println(dev);
        for (Client client : dev.getClients()) {
            System.out.println(" -" + client);
        }
    }
    IDevice dev = adb.getDevices()[0];
    Client cli = dev.getClients()[0];
    AndroidDebugBridge.disconnectBridge();
}
Also used : IDevice(com.android.ddmlib.IDevice) Client(com.android.ddmlib.Client) AndroidDebugBridge(com.android.ddmlib.AndroidDebugBridge)

Aggregations

AndroidDebugBridge (com.android.ddmlib.AndroidDebugBridge)23 IDevice (com.android.ddmlib.IDevice)11 NotNull (org.jetbrains.annotations.NotNull)4 File (java.io.File)3 Client (com.android.ddmlib.Client)2 Project (com.intellij.openapi.project.Project)2 JBLoadingPanel (com.intellij.ui.components.JBLoadingPanel)2 TIntArrayList (gnu.trove.TIntArrayList)2 ArrayList (java.util.ArrayList)2 Nullable (org.jetbrains.annotations.Nullable)2 AvdInfo (com.android.sdklib.internal.avd.AvdInfo)1 IdDisplay (com.android.sdklib.repository.IdDisplay)1 DeviceContext (com.android.tools.idea.ddms.DeviceContext)1 DevicePanel (com.android.tools.idea.ddms.DevicePanel)1 OpenVmTraceHandler (com.android.tools.idea.ddms.OpenVmTraceHandler)1 AndroidLogcatView (com.android.tools.idea.logcat.AndroidLogcatView)1 SuppressForbidden (com.facebook.buck.annotations.SuppressForbidden)1 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)1 ConsoleView (com.intellij.execution.ui.ConsoleView)1 RunnerLayoutUi (com.intellij.execution.ui.RunnerLayoutUi)1