use of com.android.ddmlib.IDevice 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.IDevice in project buck by facebook.
the class AdbHelperTest method testDeviceFilterEmulator.
/**
* Verify that when emulator-only mode is enabled only emulators appear in result.
*/
@Test
public void testDeviceFilterEmulator() throws CmdLineException {
AdbHelper myAdbHelper = createAdbHelper(new AdbOptions(), new TargetDeviceOptions(true, false, Optional.empty()));
IDevice[] devices = new IDevice[] { createEmulator("1", IDevice.DeviceState.ONLINE), createRealDevice("2", IDevice.DeviceState.ONLINE) };
List<IDevice> filteredDevices = myAdbHelper.filterDevices(devices);
assertNotNull(filteredDevices);
assertEquals(1, filteredDevices.size());
assertSame(devices[0], filteredDevices.get(0));
}
use of com.android.ddmlib.IDevice in project buck by facebook.
the class AdbHelperTest method whenSerialNumberSetInEnvironmentThenCorrectDeviceFound.
/**
* Verify that filtering by environment variable works.
*/
@Test
public void whenSerialNumberSetInEnvironmentThenCorrectDeviceFound() throws CmdLineException {
IDevice[] devices = new IDevice[] { createRealDevice("1", IDevice.DeviceState.ONLINE), createEmulator("2", IDevice.DeviceState.ONLINE), createRealDevice("3", IDevice.DeviceState.ONLINE), createEmulator("4", IDevice.DeviceState.ONLINE) };
for (int i = 0; i < devices.length; i++) {
AdbHelper myAdbHelper = createAdbHelper(TestExecutionContext.newBuilder().setEnvironment(ImmutableMap.of(AdbHelper.SERIAL_NUMBER_ENV, devices[i].getSerialNumber())).build(), new AdbOptions(), new TargetDeviceOptions());
List<IDevice> filteredDevices = myAdbHelper.filterDevices(devices);
assertNotNull(filteredDevices);
assertEquals(1, filteredDevices.size());
assertSame(devices[i], filteredDevices.get(0));
}
}
use of com.android.ddmlib.IDevice in project buck by facebook.
the class AdbHelperTest method testDeviceFilterBySerial.
/**
* Verify that filtering by serial number works.
*/
@Test
public void testDeviceFilterBySerial() throws CmdLineException {
IDevice[] devices = new IDevice[] { createRealDevice("1", IDevice.DeviceState.ONLINE), createEmulator("2", IDevice.DeviceState.ONLINE), createRealDevice("3", IDevice.DeviceState.ONLINE), createEmulator("4", IDevice.DeviceState.ONLINE) };
for (int i = 0; i < devices.length; i++) {
AdbHelper myAdbHelper = createAdbHelper(new AdbOptions(), new TargetDeviceOptions(false, false, Optional.of(devices[i].getSerialNumber())));
List<IDevice> filteredDevices = myAdbHelper.filterDevices(devices);
assertNotNull(filteredDevices);
assertEquals(1, filteredDevices.size());
assertSame(devices[i], filteredDevices.get(0));
}
}
use of com.android.ddmlib.IDevice in project buck by facebook.
the class AdbHelperTest method testGenymotionIsntARealDevice.
@Test
public void testGenymotionIsntARealDevice() throws Throwable {
AdbHelper adbHelper = createAdbHelper(new AdbOptions(), new TargetDeviceOptions(false, true, Optional.empty()));
IDevice[] devices = new IDevice[] { TestDevice.createRealDevice("foobar"), TestDevice.createRealDevice("192.168.57.101:5555") };
List<IDevice> filtered = adbHelper.filterDevices(devices);
assertNotNull(filtered);
assertEquals(1, filtered.size());
assertEquals("foobar", filtered.get(0).getSerialNumber());
}
Aggregations