Search in sources :

Example 6 with IDevice

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;
}
Also used : IDevice(com.android.ddmlib.IDevice) AndroidDebugBridge(com.android.ddmlib.AndroidDebugBridge) SuppressForbidden(com.facebook.buck.annotations.SuppressForbidden)

Example 7 with IDevice

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));
}
Also used : TargetDeviceOptions(com.facebook.buck.step.TargetDeviceOptions) IDevice(com.android.ddmlib.IDevice) AdbOptions(com.facebook.buck.step.AdbOptions) Test(org.junit.Test)

Example 8 with IDevice

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));
    }
}
Also used : IDevice(com.android.ddmlib.IDevice) TargetDeviceOptions(com.facebook.buck.step.TargetDeviceOptions) AdbOptions(com.facebook.buck.step.AdbOptions) Test(org.junit.Test)

Example 9 with IDevice

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));
    }
}
Also used : IDevice(com.android.ddmlib.IDevice) TargetDeviceOptions(com.facebook.buck.step.TargetDeviceOptions) AdbOptions(com.facebook.buck.step.AdbOptions) Test(org.junit.Test)

Example 10 with IDevice

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());
}
Also used : TargetDeviceOptions(com.facebook.buck.step.TargetDeviceOptions) IDevice(com.android.ddmlib.IDevice) AdbOptions(com.facebook.buck.step.AdbOptions) Test(org.junit.Test)

Aggregations

IDevice (com.android.ddmlib.IDevice)76 Test (org.junit.Test)17 AndroidDebugBridge (com.android.ddmlib.AndroidDebugBridge)11 AdbOptions (com.facebook.buck.step.AdbOptions)11 TargetDeviceOptions (com.facebook.buck.step.TargetDeviceOptions)11 NotNull (org.jetbrains.annotations.NotNull)10 Client (com.android.ddmlib.Client)6 File (java.io.File)6 AndroidVersion (com.android.sdklib.AndroidVersion)5 SuppressForbidden (com.facebook.buck.annotations.SuppressForbidden)5 TIntArrayList (gnu.trove.TIntArrayList)5 Nullable (org.jetbrains.annotations.Nullable)5 InstallException (com.android.ddmlib.InstallException)4 AvdInfo (com.android.sdklib.internal.avd.AvdInfo)4 ExecutionException (java.util.concurrent.ExecutionException)4 AdbCommandRejectedException (com.android.ddmlib.AdbCommandRejectedException)3 ShellCommandUnresponsiveException (com.android.ddmlib.ShellCommandUnresponsiveException)3 TimeoutException (com.android.ddmlib.TimeoutException)3 BuckEventBus (com.facebook.buck.event.BuckEventBus)3 TestConsole (com.facebook.buck.testutil.TestConsole)3