Search in sources :

Example 11 with IDevice

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

the class AdbHelperTest method testDeviceFilterNoMatchingDevices.

/**
   * Verify that if no devices match filters null is returned.
   */
@Test
public void testDeviceFilterNoMatchingDevices() 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) };
    AdbHelper myAdbHelper = createAdbHelper(new AdbOptions(), new TargetDeviceOptions(false, false, Optional.of("invalid-serial")));
    List<IDevice> filteredDevices = myAdbHelper.filterDevices(devices);
    assertNull(filteredDevices);
}
Also used : IDevice(com.android.ddmlib.IDevice) TargetDeviceOptions(com.facebook.buck.step.TargetDeviceOptions) AdbOptions(com.facebook.buck.step.AdbOptions) Test(org.junit.Test)

Example 12 with IDevice

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

the class AndroidDebugger method attachDebugger.

public static void attachDebugger(final String packageName, final Project project) throws InterruptedException {
    IDevice[] devices = AndroidDebugBridge.getBridge().getDevices();
    if (devices.length == 0) {
        return;
    }
    IDevice device = devices[0];
    Client client;
    int currentRetryNumber = 0;
    int currentRetryTime = RETRY_TIME;
    // It takes some time to get the updated client process list, so wait for it
    do {
        client = device.getClient(packageName);
        currentRetryTime *= 2;
        Thread.sleep(currentRetryTime);
        currentRetryNumber++;
    } while (client == null && currentRetryNumber < MAX_RETRIES);
    if (client == null) {
        throw new RuntimeException("Connecting to the adb debug server timed out." + "Can't find package with name " + packageName + ".");
    }
    String debugPort = String.valueOf(client.getDebuggerListenPort());
    final RunnerAndConfigurationSettings settings = createRunConfiguration(project, debugPort);
    ApplicationManager.getApplication().invokeLater(new Runnable() {

        @Override
        public void run() {
            // Needs read access which is available on the read thread.
            ProgramRunnerUtil.executeConfiguration(project, settings, DefaultDebugExecutor.getDebugExecutorInstance());
        }
    });
}
Also used : IDevice(com.android.ddmlib.IDevice) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) Client(com.android.ddmlib.Client)

Example 13 with IDevice

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

the class InstrumentationTestRunner method run.

public void run() throws Throwable {
    IDevice device = getDevice(this.deviceSerial);
    if (device == null) {
        System.err.printf("Unable to get device/emulator with serial %s", this.deviceSerial);
        System.exit(1);
    }
    if (this.instrumentationApkPath != null) {
        DdmPreferences.setTimeOut(60000);
        device.installPackage(this.instrumentationApkPath, true);
        if (this.apkUnderTestPath != null) {
            device.installPackage(this.apkUnderTestPath, true);
        }
    }
    try {
        final RemoteAndroidTestRunner runner = new RemoteAndroidTestRunner(this.packageName, this.testRunner, getDevice(deviceSerial));
        for (Map.Entry<String, String> entry : this.extraInstrumentationArguments.entrySet()) {
            runner.addInstrumentationArg(entry.getKey(), entry.getValue());
        }
        BuckXmlTestRunListener listener = new BuckXmlTestRunListener();
        ITestRunListener trimLineListener = new ITestRunListener() {

            /**
           * Before the actual run starts (and after the
           * InstrumentationResultsParser is created), we need to do
           * some reflection magic to make RemoteAndroidTestRunner not
           * trim indentation from lines.
           */
            @Override
            public void testRunStarted(String runName, int testCount) {
                setTrimLine(runner, false);
            }

            @Override
            public void testRunEnded(long elapsedTime, Map<String, String> runMetrics) {
            }

            @Override
            public void testRunFailed(String errorMessage) {
            }

            @Override
            public void testStarted(TestIdentifier test) {
            }

            @Override
            public void testFailed(TestIdentifier test, String trace) {
            }

            @Override
            public void testAssumptionFailure(TestIdentifier test, String trace) {
            }

            @Override
            public void testIgnored(TestIdentifier test) {
            }

            @Override
            public void testEnded(TestIdentifier test, Map<String, String> testMetrics) {
            }

            @Override
            public void testRunStopped(long elapsedTime) {
            }
        };
        listener.setReportDir(this.outputDirectory);
        runner.run(trimLineListener, listener);
    } finally {
        if (this.attemptUninstall) {
            // Best effort uninstall from the emulator/device.
            device.uninstallPackage(this.packageName);
        }
    }
}
Also used : ITestRunListener(com.android.ddmlib.testrunner.ITestRunListener) RemoteAndroidTestRunner(com.android.ddmlib.testrunner.RemoteAndroidTestRunner) IDevice(com.android.ddmlib.IDevice) TestIdentifier(com.android.ddmlib.testrunner.TestIdentifier) Map(java.util.Map) HashMap(java.util.HashMap)

Example 14 with IDevice

use of com.android.ddmlib.IDevice 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()]);
}
Also used : TIntArrayList(gnu.trove.TIntArrayList) IDevice(com.android.ddmlib.IDevice) AndroidDebugBridge(com.android.ddmlib.AndroidDebugBridge) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with IDevice

use of com.android.ddmlib.IDevice 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();
}
Also used : IDevice(com.android.ddmlib.IDevice) Client(com.android.ddmlib.Client) AndroidDebugBridge(com.android.ddmlib.AndroidDebugBridge)

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