Search in sources :

Example 46 with IDevice

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

the class AdbHelperTest method testDeviceFilterCombos.

/**
   * Verify that different combinations of arguments work correctly.
   */
@Test
public void testDeviceFilterCombos() throws CmdLineException {
    TestDevice realDevice1 = createRealDevice("1", IDevice.DeviceState.ONLINE);
    TestDevice realDevice2 = createRealDevice("2", IDevice.DeviceState.ONLINE);
    TestDevice emulator1 = createEmulator("3", IDevice.DeviceState.ONLINE);
    TestDevice emulator2 = createEmulator("4", IDevice.DeviceState.ONLINE);
    IDevice[] devices = new IDevice[] { realDevice1, emulator1, realDevice2, emulator2 };
    AdbHelper myAdbHelper;
    // Filter by serial in "real device" mode with serial number for real device.
    myAdbHelper = createAdbHelper(new AdbOptions(), new TargetDeviceOptions(false, true, Optional.of(realDevice1.getSerialNumber())));
    List<IDevice> filteredDevices = myAdbHelper.filterDevices(devices);
    assertNotNull(filteredDevices);
    assertEquals(1, filteredDevices.size());
    assertSame(realDevice1, filteredDevices.get(0));
    // Filter by serial in "real device" mode with serial number for emulator.
    myAdbHelper = createAdbHelper(new AdbOptions(), new TargetDeviceOptions(false, true, Optional.of(emulator1.getSerialNumber())));
    filteredDevices = myAdbHelper.filterDevices(devices);
    assertNull(filteredDevices);
    // Filter by serial in "emulator" mode with serial number for real device.
    myAdbHelper = createAdbHelper(new AdbOptions(), new TargetDeviceOptions(true, false, Optional.of(realDevice1.getSerialNumber())));
    filteredDevices = myAdbHelper.filterDevices(devices);
    assertNull(filteredDevices);
    // Filter by serial in "real device" mode with serial number for emulator.
    myAdbHelper = createAdbHelper(new AdbOptions(), new TargetDeviceOptions(true, false, Optional.of(emulator1.getSerialNumber())));
    filteredDevices = myAdbHelper.filterDevices(devices);
    assertNotNull(filteredDevices);
    assertEquals(1, filteredDevices.size());
    assertSame(emulator1, filteredDevices.get(0));
    // Filter in both "real device" mode and "emulator mode".
    myAdbHelper = createAdbHelper(new AdbOptions(0, true), new TargetDeviceOptions(true, true, Optional.empty()));
    filteredDevices = myAdbHelper.filterDevices(devices);
    assertNotNull(filteredDevices);
    assertEquals(devices.length, filteredDevices.size());
    for (IDevice device : devices) {
        assertTrue(filteredDevices.contains(device));
    }
}
Also used : IDevice(com.android.ddmlib.IDevice) TargetDeviceOptions(com.facebook.buck.step.TargetDeviceOptions) AdbOptions(com.facebook.buck.step.AdbOptions) Test(org.junit.Test)

Example 47 with IDevice

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

the class AdbHelperTest method testDeviceFilterRealDevices.

/**
   * Verify that when real-device-only mode is enabled only real devices appear in result.
   */
@Test
public void testDeviceFilterRealDevices() throws CmdLineException {
    AdbHelper myAdbHelper = createAdbHelper(new AdbOptions(), new TargetDeviceOptions(false, true, Optional.empty()));
    IDevice[] devices = new IDevice[] { createRealDevice("1", IDevice.DeviceState.ONLINE), createEmulator("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 48 with IDevice

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

the class AdbHelperTest method testNonQuietShowsOutput.

@Test
public void testNonQuietShowsOutput() 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, false);
        }

        @Override
        public String toString() {
            return "install apk";
        }
    }, false);
    assertTrue(success);
    assertEquals(apk.getAbsolutePath(), apkPath.get());
    assertEquals("", console.getTextWrittenToStdOut());
    assertEquals("Successfully ran install apk on 1 device(s)\n", console.getTextWrittenToStdErr());
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) IDevice(com.android.ddmlib.IDevice) AtomicReference(java.util.concurrent.atomic.AtomicReference) AdbOptions(com.facebook.buck.step.AdbOptions) CmdLineException(org.kohsuke.args4j.CmdLineException) InstallException(com.android.ddmlib.InstallException) TargetDeviceOptions(com.facebook.buck.step.TargetDeviceOptions) TestConsole(com.facebook.buck.testutil.TestConsole) File(java.io.File) Test(org.junit.Test)

Example 49 with IDevice

use of com.android.ddmlib.IDevice in project atlas by alibaba.

the class AwoInstaller method installPatchIfDeviceConnected.

/**
     * no device or too many device make install fail
     *
     * @param patch
     * @return
     */
private static boolean installPatchIfDeviceConnected(AndroidBuilder androidBuilder, File patch, String patchPkg, Logger logger) {
    final AndroidDebugBridge androidDebugBridge = initAndroidDebugBridge(androidBuilder);
    if (!androidDebugBridge.isConnected()) {
        throw new RuntimeException("Android Debug Bridge is not connected.");
    }
    waitForInitialDeviceList(androidDebugBridge, logger);
    List<IDevice> devices = Arrays.asList(androidDebugBridge.getDevices());
    String PATCH_INSTALL_DIRECTORY = String.format("%s%s%s", PATCH_INSTALL_DIRECTORY_PREFIX, patchPkg, PATCH_INSTALL_DIRECTORY_SUFFIX);
    if (devices.size() == 0) {
        throw new RuntimeException(String.format("%s%s%s%s%s", "no device connected,please check whether the connection is successful or copy ", patch, " in build/outputs/awbs/libxxx.so ", PATCH_INSTALL_DIRECTORY, " and restart you app"));
    }
    if (devices.size() > 1) {
        throw new RuntimeException("too much devices be connected,please disconnect the others and try again");
    }
    CommandExecutor executor = CommandExecutor.Factory.createDefaultCommmandExecutor();
    executor.setLogger(logger);
    executor.setCaptureStdOut(true);
    executor.setCaptureStdErr(true);
    List<String> cmd = Arrays.asList("push", patch.getAbsolutePath(), PATCH_INSTALL_DIRECTORY + patch.getName());
    try {
        executor.executeCommand(androidBuilder.getSdkInfo().getAdb().getAbsolutePath(), cmd, false);
        return true;
    } catch (ExecutionException e) {
        throw new RuntimeException("Error while trying to push patch to device ", e);
    } finally {
        String errout = executor.getStandardError();
        if ((errout != null) && (errout.trim().length() > 0)) {
            logger.error(errout);
        }
    }
}
Also used : CommandExecutor(com.taobao.android.builder.tools.command.CommandExecutor) IDevice(com.android.ddmlib.IDevice) ExecutionException(com.taobao.android.builder.tools.command.ExecutionException) AndroidDebugBridge(com.android.ddmlib.AndroidDebugBridge)

Example 50 with IDevice

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

the class MyDeviceChooser method refreshTable.

private void refreshTable() {
    IDevice[] devices = myDetectedDevicesRef.get();
    myDisplayedDevices = devices;
    final IDevice[] selectedDevices = getSelectedDevices();
    final TIntArrayList selectedRows = new TIntArrayList();
    for (int i = 0; i < devices.length; i++) {
        if (ArrayUtil.indexOf(selectedDevices, devices[i]) >= 0) {
            selectedRows.add(i);
        }
    }
    myProcessSelectionFlag = false;
    myDeviceTable.setModel(new MyDeviceTableModel(devices));
    if (selectedRows.size() == 0 && devices.length > 0) {
        myDeviceTable.getSelectionModel().setSelectionInterval(0, 0);
    }
    for (int selectedRow : selectedRows.toNativeArray()) {
        if (selectedRow < devices.length) {
            myDeviceTable.getSelectionModel().addSelectionInterval(selectedRow, selectedRow);
        }
    }
    fireSelectedDevicesChanged();
    myProcessSelectionFlag = true;
    updatePreviouslySelectedSerials();
}
Also used : IDevice(com.android.ddmlib.IDevice) TIntArrayList(gnu.trove.TIntArrayList)

Aggregations

IDevice (com.android.ddmlib.IDevice)75 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 AndroidVersion (com.android.sdklib.AndroidVersion)5 SuppressForbidden (com.facebook.buck.annotations.SuppressForbidden)5 TIntArrayList (gnu.trove.TIntArrayList)5 File (java.io.File)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