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;
}
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;
}
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;
}
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()]);
}
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();
}
Aggregations