Search in sources :

Example 36 with IDevice

use of com.android.ddmlib.IDevice in project android by JetBrains.

the class LaunchTaskRunner method run.

@Override
public void run(@NotNull ProgressIndicator indicator) {
    indicator.setText(getTitle());
    indicator.setIndeterminate(false);
    LaunchStatus launchStatus = new ProcessHandlerLaunchStatus(myProcessHandler);
    ConsolePrinter consolePrinter = new ProcessHandlerConsolePrinter(myProcessHandler);
    List<ListenableFuture<IDevice>> listenableDeviceFutures = myDeviceFutures.get();
    AndroidVersion androidVersion = myDeviceFutures.getDevices().size() == 1 ? myDeviceFutures.getDevices().get(0).getVersion() : null;
    DebugConnectorTask debugSessionTask = myLaunchTasksProvider.getConnectDebuggerTask(launchStatus, androidVersion);
    if (debugSessionTask != null && listenableDeviceFutures.size() != 1) {
        launchStatus.terminateLaunch("Cannot launch a debug session on more than 1 device.");
    }
    if (debugSessionTask != null) {
        // we need to copy over console output from the first console to the debug console once it is established
        AndroidProcessText.attach(myProcessHandler);
    }
    DateFormat dateFormat = new SimpleDateFormat("MM/dd HH:mm:ss");
    consolePrinter.stdout("\n" + dateFormat.format(new Date()) + ": Launching " + myConfigName);
    for (ListenableFuture<IDevice> deviceFuture : listenableDeviceFutures) {
        indicator.setText("Waiting for target device to come online");
        IDevice device = waitForDevice(deviceFuture, indicator, launchStatus);
        if (device == null) {
            return;
        }
        List<LaunchTask> launchTasks = null;
        try {
            launchTasks = myLaunchTasksProvider.getTasks(device, launchStatus, consolePrinter);
        } catch (com.intellij.execution.ExecutionException e) {
            launchStatus.terminateLaunch(e.getMessage());
            return;
        } catch (IllegalStateException e) {
            launchStatus.terminateLaunch(e.getMessage());
            Logger.getInstance(LaunchTaskRunner.class).error(e);
            return;
        }
        int totalDuration = listenableDeviceFutures.size() * getTotalDuration(launchTasks, debugSessionTask);
        int elapsed = 0;
        for (LaunchTask task : launchTasks) {
            // perform each task
            indicator.setText(task.getDescription());
            if (!task.perform(device, launchStatus, consolePrinter)) {
                myError = "Error " + task.getDescription();
                launchStatus.terminateLaunch("Error while " + task.getDescription());
                return;
            }
            // update progress
            elapsed += task.getDuration();
            indicator.setFraction((double) elapsed / totalDuration);
            // check for cancellation via progress bar
            if (indicator.isCanceled()) {
                launchStatus.terminateLaunch("User cancelled launch");
                return;
            }
            // check for cancellation via stop button
            if (launchStatus.isLaunchTerminated()) {
                return;
            }
        }
        if (debugSessionTask != null) {
            debugSessionTask.perform(myLaunchInfo, device, (ProcessHandlerLaunchStatus) launchStatus, (ProcessHandlerConsolePrinter) consolePrinter);
        } else {
            // we only need to inform the process handler if certain scenarios
            if (// we are not doing a hot swap (in which case we are creating a new process)
            myLaunchTasksProvider.createsNewProcess() && myProcessHandler instanceof AndroidProcessHandler) {
                // we aren't debugging (in which case its a DebugProcessHandler)
                ((AndroidProcessHandler) myProcessHandler).addTargetDevice(device);
            }
        }
    }
}
Also used : LaunchStatus(com.android.tools.idea.run.util.LaunchStatus) ProcessHandlerLaunchStatus(com.android.tools.idea.run.util.ProcessHandlerLaunchStatus) IDevice(com.android.ddmlib.IDevice) AndroidVersion(com.android.sdklib.AndroidVersion) Date(java.util.Date) ProcessHandlerLaunchStatus(com.android.tools.idea.run.util.ProcessHandlerLaunchStatus) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) LaunchTask(com.android.tools.idea.run.tasks.LaunchTask) DebugConnectorTask(com.android.tools.idea.run.tasks.DebugConnectorTask) SimpleDateFormat(java.text.SimpleDateFormat)

Example 37 with IDevice

use of com.android.ddmlib.IDevice in project android by JetBrains.

the class AvdComboBox method doUpdateAvds.

private void doUpdateAvds() {
    final Module module = getModule();
    if (module == null || module.isDisposed()) {
        return;
    }
    final AndroidFacet facet = AndroidFacet.getInstance(module);
    final IdDisplay[] newAvds;
    if (facet != null) {
        final Set<String> filteringSet = new HashSet<String>();
        if (myShowNotLaunchedOnly) {
            final AndroidDebugBridge debugBridge = AndroidSdkUtils.getDebugBridge(facet.getModule().getProject());
            if (debugBridge != null) {
                for (IDevice device : debugBridge.getDevices()) {
                    final String avdName = device.getAvdName();
                    if (avdName != null && avdName.length() > 0) {
                        filteringSet.add(avdName);
                    }
                }
            }
        }
        final List<IdDisplay> newAvdList = new ArrayList<IdDisplay>();
        if (myAddEmptyElement) {
            newAvdList.add(IdDisplay.create("", ""));
        }
        for (AvdInfo avd : facet.getAllAvds()) {
            String displayName = avd.getProperties().get(AvdManager.AVD_INI_DISPLAY_NAME);
            final String avdName = displayName == null || displayName.isEmpty() ? avd.getName() : displayName;
            if (!filteringSet.contains(avdName)) {
                newAvdList.add(IdDisplay.create(avd.getName(), avdName));
            }
        }
        newAvds = ArrayUtil.toObjectArray(newAvdList, IdDisplay.class);
    } else {
        newAvds = new IdDisplay[0];
    }
    if (!Arrays.equals(myOldAvds, newAvds)) {
        myOldAvds = newAvds;
        final Object selected = getComboBox().getSelectedItem();
        getComboBox().setModel(new DefaultComboBoxModel(newAvds));
        getComboBox().setSelectedItem(selected);
    }
}
Also used : ArrayList(java.util.ArrayList) IDevice(com.android.ddmlib.IDevice) AvdInfo(com.android.sdklib.internal.avd.AvdInfo) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) IdDisplay(com.android.sdklib.repository.IdDisplay) Module(com.intellij.openapi.module.Module) HashSet(com.intellij.util.containers.HashSet) AndroidDebugBridge(com.android.ddmlib.AndroidDebugBridge)

Example 38 with IDevice

use of com.android.ddmlib.IDevice in project android by JetBrains.

the class DeviceChooser method refreshTable.

private void refreshTable(IDevice[] devices) {
    final IDevice[] selectedDevices = getSelectedDevices(false);
    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;
}
Also used : IDevice(com.android.ddmlib.IDevice) TIntArrayList(gnu.trove.TIntArrayList)

Example 39 with IDevice

use of com.android.ddmlib.IDevice in project android by JetBrains.

the class AndroidProcessChooserDialog method getSelectedDevice.

@Nullable
private IDevice getSelectedDevice() {
    final TreePath selectionPath = myProcessTree.getSelectionPath();
    if (selectionPath == null || selectionPath.getPathCount() < 2) {
        return null;
    }
    DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) selectionPath.getPathComponent(1);
    final Object obj = selectedNode.getUserObject();
    return obj instanceof IDevice ? (IDevice) obj : null;
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) IDevice(com.android.ddmlib.IDevice) Nullable(org.jetbrains.annotations.Nullable)

Example 40 with IDevice

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

the class AdbHelper method filterDevices.

/**
   * Returns list of devices that pass the filter. If there is an invalid combination or no
   * devices are left after filtering this function prints an error and returns null.
   */
@Nullable
@VisibleForTesting
@SuppressForbidden
List<IDevice> filterDevices(IDevice[] allDevices) {
    if (allDevices.length == 0) {
        console.printBuildFailure("No devices are found.");
        return null;
    }
    List<IDevice> devices = Lists.newArrayList();
    Optional<Boolean> emulatorsOnly = Optional.empty();
    if (deviceOptions.isEmulatorsOnlyModeEnabled() && options.isMultiInstallModeEnabled()) {
        emulatorsOnly = Optional.empty();
    } else if (deviceOptions.isEmulatorsOnlyModeEnabled()) {
        emulatorsOnly = Optional.of(true);
    } else if (deviceOptions.isRealDevicesOnlyModeEnabled()) {
        emulatorsOnly = Optional.of(false);
    }
    int onlineDevices = 0;
    for (IDevice device : allDevices) {
        boolean passed = false;
        if (device.isOnline()) {
            onlineDevices++;
            boolean serialMatches = true;
            if (deviceOptions.getSerialNumber().isPresent()) {
                serialMatches = device.getSerialNumber().equals(deviceOptions.getSerialNumber().get());
            } else if (context.getEnvironment().containsKey(SERIAL_NUMBER_ENV)) {
                serialMatches = device.getSerialNumber().equals(context.getEnvironment().get(SERIAL_NUMBER_ENV));
            }
            boolean deviceTypeMatches;
            if (emulatorsOnly.isPresent()) {
                // Only devices of specific type are accepted:
                // either real devices only or emulators only.
                deviceTypeMatches = (emulatorsOnly.get() == isEmulator(device));
            } else {
                // All online devices match.
                deviceTypeMatches = true;
            }
            passed = serialMatches && deviceTypeMatches;
        }
        if (passed) {
            devices.add(device);
        }
    }
    // Filtered out all devices.
    if (onlineDevices == 0) {
        console.printBuildFailure("No devices are found.");
        return null;
    }
    if (devices.isEmpty()) {
        console.printBuildFailure(String.format("Found %d connected device(s), but none of them matches specified filter.", onlineDevices));
        return null;
    }
    return devices;
}
Also used : IDevice(com.android.ddmlib.IDevice) VisibleForTesting(com.google.common.annotations.VisibleForTesting) SuppressForbidden(com.facebook.buck.annotations.SuppressForbidden) Nullable(javax.annotation.Nullable)

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