use of com.android.ddmlib.IDevice in project buck by facebook.
the class InstrumentationTestRunner method getDevice.
@Nullable
private IDevice getDevice(String serial) throws InterruptedException {
AndroidDebugBridge adb = createAdb();
if (adb == null) {
System.err.println("Unable to set up adb.");
System.exit(1);
}
IDevice[] allDevices = adb.getDevices();
for (IDevice device : allDevices) {
if (device.getSerialNumber().equals(serial)) {
return device;
}
}
return null;
}
use of com.android.ddmlib.IDevice in project buck by facebook.
the class AdbHelperTest method createAdbHelper.
private AdbHelper createAdbHelper(ExecutionContext executionContext, AdbOptions adbOptions, TargetDeviceOptions targetDeviceOptions) throws CmdLineException {
Console console = new TestConsole();
BuckEventBus eventBus = BuckEventBusFactory.newInstance();
return new AdbHelper(adbOptions, targetDeviceOptions, executionContext, console, eventBus, true) {
@Override
protected boolean isDeviceTempWritable(IDevice device, String name) {
return true;
}
};
}
use of com.android.ddmlib.IDevice in project buck by facebook.
the class AdbHelperTest method testDeviceFilterMultipleDevices.
/**
* Verify that multi-install is not enabled and multiple devices
* pass the filter null is returned. Also verify that if multiple
* devices are passing the filter and multi-install mode is enabled
* they all appear in resulting list.
*/
@Test
public void testDeviceFilterMultipleDevices() throws CmdLineException {
IDevice[] devices = new IDevice[] { createEmulator("1", IDevice.DeviceState.ONLINE), createEmulator("2", IDevice.DeviceState.ONLINE), createRealDevice("4", IDevice.DeviceState.ONLINE), createRealDevice("5", IDevice.DeviceState.ONLINE) };
List<IDevice> filteredDevicesNoMultiInstall = basicAdbHelper.filterDevices(devices);
assertNotNull(filteredDevicesNoMultiInstall);
assertEquals(devices.length, filteredDevicesNoMultiInstall.size());
AdbHelper myAdbHelper = createAdbHelper(new AdbOptions(0, true), new TargetDeviceOptions());
List<IDevice> filteredDevices = myAdbHelper.filterDevices(devices);
assertNotNull(filteredDevices);
assertEquals(devices.length, filteredDevices.size());
}
use of com.android.ddmlib.IDevice in project buck by facebook.
the class AdbHelperTest method testEmulatorAddsGenymotionDevices.
@Test
public void testEmulatorAddsGenymotionDevices() throws Throwable {
AdbHelper adbHelper = createAdbHelper(new AdbOptions(), new TargetDeviceOptions(true, false, Optional.empty()));
IDevice[] devices = new IDevice[] { TestDevice.createRealDevice("foobarblahblah"), TestDevice.createRealDevice("192.168.57.101:5555") };
List<IDevice> filtered = adbHelper.filterDevices(devices);
assertNotNull(filtered);
assertEquals(1, filtered.size());
assertEquals("192.168.57.101:5555", filtered.get(0).getSerialNumber());
}
use of com.android.ddmlib.IDevice in project buck by facebook.
the class AdbHelperTest method testQuietDeviceInstall.
@Test
public void testQuietDeviceInstall() throws InterruptedException {
final File apk = new File("/some/file.apk");
final AtomicReference<String> apkPath = new AtomicReference<>();
TestDevice device = new TestDevice() {
@Override
public void installPackage(String s, boolean b, String... strings) throws InstallException {
apkPath.set(s);
}
};
device.setSerialNumber("serial#1");
device.setName("testDevice");
final List<IDevice> deviceList = Lists.newArrayList((IDevice) device);
TestConsole console = new TestConsole();
BuckEventBus eventBus = BuckEventBusFactory.newInstance();
AdbHelper adbHelper = new AdbHelper(new AdbOptions(), new TargetDeviceOptions(), TestExecutionContext.newInstance(), console, eventBus, true) {
@Override
protected boolean isDeviceTempWritable(IDevice device, String name) {
return true;
}
@Override
public List<IDevice> getDevices(boolean quiet) {
return deviceList;
}
};
boolean success = adbHelper.adbCall(new AdbHelper.AdbCallable() {
@Override
public boolean call(IDevice device) throws Exception {
return basicAdbHelper.installApkOnDevice(device, apk, false, true);
}
@Override
public String toString() {
return "install apk";
}
}, true);
assertTrue(success);
assertEquals(apk.getAbsolutePath(), apkPath.get());
assertEquals("", console.getTextWrittenToStdOut());
assertEquals("", console.getTextWrittenToStdErr());
}
Aggregations