Search in sources :

Example 56 with IDevice

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

the class ShowChooserTargetProvider method showPrompt.

@Override
@Nullable
public DeployTarget showPrompt(@NotNull Executor executor, @NotNull ExecutionEnvironment env, @NotNull AndroidFacet facet, @NotNull DeviceCount deviceCount, boolean androidTests, @NotNull Map<String, DeployTargetState> deployTargetStates, int runConfigId, @NotNull LaunchCompatibilityChecker compatibilityChecker) {
    State showChooserState = (State) deployTargetStates.get(getId());
    Project project = facet.getModule().getProject();
    if (showChooserState.USE_LAST_SELECTED_DEVICE) {
        // If the last selection was a custom run profile state, then use that
        DeployTarget target = DevicePickerStateService.getInstance(project).getDeployTargetPickerResult(runConfigId);
        if (target != null && target.hasCustomRunProfileState(executor)) {
            return target;
        }
        // If the last selection was a device, we can't just use the saved deploy target, since the list of devices could be stale,
        // which would happen if the result was to launch an emulator. So we use the state of the devices instead
        Collection<IDevice> devices = ManualTargetChooser.getLastUsedDevices(project, runConfigId, deviceCount);
        if (!devices.isEmpty()) {
            return new RealizedDeployTarget(null, null, DeviceFutures.forDevices(devices));
        }
    }
    List<DeployTargetProvider> applicableTargets = getTargetsProvidingRunProfileState(executor, androidTests);
    // show the dialog and get the state
    DeployTargetPickerDialog dialog = new DeployTargetPickerDialog(runConfigId, facet, deviceCount, applicableTargets, deployTargetStates, compatibilityChecker);
    if (dialog.showAndGet()) {
        DeployTarget result = dialog.getSelectedDeployTarget();
        if (result == null) {
            return null;
        }
        if (showChooserState.USE_LAST_SELECTED_DEVICE) {
            DevicePickerStateService.getInstance(project).setDeployPickerResult(runConfigId, result.hasCustomRunProfileState(executor) ? result : null);
            // TODO: we only save the running devices, which means that the AVD selection is lost if the AVD wasn't running
            // TODO: the getRunningDevices() returns an empty list right now if there is an AVD to be selected, which at least makes the dialog
            // show up again, but eventually, we need to be able to handle a transition from AVD -> running device
            DevicePickerStateService.getInstance(project).setDevicesUsedInLaunch(runConfigId, getRunningDevices(dialog.getSelectedDevices()), ManualTargetChooser.getOnlineDevices(project));
        }
        return result;
    } else {
        return null;
    }
}
Also used : Project(com.intellij.openapi.project.Project) IDevice(com.android.ddmlib.IDevice) Nullable(org.jetbrains.annotations.Nullable)

Example 57 with IDevice

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

the class AndroidProcessChooserDialog method doUpdateTree.

private void doUpdateTree(boolean showAllProcesses) {
    final AndroidDebugBridge debugBridge = AndroidSdkUtils.getDebugBridge(myProject);
    final DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    final DefaultTreeModel model = new DefaultTreeModel(root);
    if (debugBridge == null) {
        myProcessTree.setModel(model);
        return;
    }
    final Set<String> processNames = collectAllProcessNames(myProject);
    TreeNode selectedDeviceNode = null;
    TreeNode selectedClientNode = null;
    Object[] firstTreePath = null;
    final IDevice[] devices = debugBridge.getDevices();
    for (IDevice device : devices) {
        final DefaultMutableTreeNode deviceNode = new DefaultMutableTreeNode(device);
        root.add(deviceNode);
        final String deviceName = device.getName();
        if (deviceName.equals(myLastSelectedDevice)) {
            selectedDeviceNode = deviceNode;
        }
        List<Client> clients = Lists.newArrayList(device.getClients());
        Collections.sort(clients, (c1, c2) -> {
            String n1 = StringUtil.notNullize(c1.getClientData().getClientDescription());
            String n2 = StringUtil.notNullize(c2.getClientData().getClientDescription());
            return n1.compareTo(n2);
        });
        for (Client client : clients) {
            final String clientDescription = client.getClientData().getClientDescription();
            if (clientDescription != null && (showAllProcesses || isRelatedProcess(processNames, clientDescription))) {
                final DefaultMutableTreeNode clientNode = new DefaultMutableTreeNode(client);
                deviceNode.add(clientNode);
                if (clientDescription.equals(myLastSelectedProcess) && (selectedDeviceNode == null || deviceName.equals(myLastSelectedDevice))) {
                    selectedClientNode = clientNode;
                    selectedDeviceNode = deviceNode;
                }
                if (firstTreePath == null) {
                    firstTreePath = new Object[] { root, deviceNode, clientNode };
                }
            }
        }
    }
    final Object[] pathToSelect;
    if (selectedDeviceNode != null && selectedClientNode != null) {
        pathToSelect = new Object[] { root, selectedDeviceNode, selectedClientNode };
    } else if (selectedDeviceNode != null) {
        pathToSelect = new Object[] { root, selectedDeviceNode };
    } else {
        pathToSelect = firstTreePath;
    }
    UIUtil.invokeLaterIfNeeded(() -> {
        myProcessTree.setModel(model);
        if (pathToSelect != null) {
            myProcessTree.getSelectionModel().setSelectionPath(new TreePath(pathToSelect));
        } else {
            getOKAction().setEnabled(false);
        }
        TreeUtil.expandAll(myProcessTree);
    });
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) IDevice(com.android.ddmlib.IDevice) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreePath(javax.swing.tree.TreePath) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Client(com.android.ddmlib.Client) AndroidDebugBridge(com.android.ddmlib.AndroidDebugBridge)

Example 58 with IDevice

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

the class AndroidProcessChooserDialog method doOKAction.

@Override
protected void doOKAction() {
    final PropertiesComponent properties = PropertiesComponent.getInstance(myProject);
    final IDevice selectedDevice = getSelectedDevice();
    if (selectedDevice == null) {
        return;
    }
    mySelectedClient = getSelectedClient();
    if (mySelectedClient == null) {
        return;
    }
    myAndroidDebugger = (AndroidDebugger) myDebuggerTypeCombo.getSelectedItem();
    properties.setValue(DEBUGGABLE_DEVICE_PROPERTY, getPersistableName(selectedDevice));
    properties.setValue(DEBUGGABLE_PROCESS_PROPERTY, getPersistableName(mySelectedClient));
    properties.setValue(SHOW_ALL_PROCESSES_PROPERTY, Boolean.toString(myShowAllProcessesCheckBox.isSelected()));
    if (myAndroidDebugger != null) {
        properties.setValue(DEBUGGER_ID_PROPERTY, myAndroidDebugger.getId());
    }
    super.doOKAction();
}
Also used : IDevice(com.android.ddmlib.IDevice) PropertiesComponent(com.intellij.ide.util.PropertiesComponent)

Example 59 with IDevice

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

the class FlightRecorder method setLaunchTarget.

public void setLaunchTarget(@NotNull AndroidDevice device) {
    try {
        Path deviceLog = myBasePath.resolve(timeStampToFolder(myTimestamp)).resolve(getDeviceLogFileName(device));
        Files.write(deviceLog, new byte[0]);
    } catch (IOException e) {
        Logger.getInstance(FlightRecorder.class).info("Unable to record deployment device info", e);
    }
    // start monitoring logcat if device is online
    if (device.getLaunchedDevice().isDone()) {
        try {
            IDevice d = device.getLaunchedDevice().get();
            myLogcatRecorder.startMonitoring(d, myTimestamp);
        } catch (InterruptedException | ExecutionException e) {
            Logger.getInstance(FlightRecorder.class).info("Unable to start recording logcat", e);
        }
    }
}
Also used : IDevice(com.android.ddmlib.IDevice) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 60 with IDevice

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

the class LogcatRecorder method startMonitoring.

public void startMonitoring(@NotNull IDevice device, @NotNull LocalDateTime buildTimeStamp) {
    IDevice old = myDeviceRef.getAndSet(device);
    if (old != device) {
        if (old != null) {
            myLogcatService.removeListener(old, myLogListener);
        }
        myLogcatService.addListener(device, myLogListener);
        enableInstantRunLog(device);
    }
    addLog("------------Launch on " + device.getName() + " @ " + buildTimeStamp.toString());
}
Also used : IDevice(com.android.ddmlib.IDevice)

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