Search in sources :

Example 36 with Client

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

the class AndroidConnectDebuggerAction method terminateRunSessions.

// Disconnect any active run sessions to the same client
private static void terminateRunSessions(@NotNull Project project, @NotNull Client selectedClient) {
    int pid = selectedClient.getClientData().getPid();
    // find if there are any active run sessions to the same client, and terminate them if so
    for (ProcessHandler handler : ExecutionManager.getInstance(project).getRunningProcesses()) {
        if (handler instanceof AndroidProcessHandler) {
            Client client = ((AndroidProcessHandler) handler).getClient(selectedClient.getDevice());
            if (client != null && client.getClientData().getPid() == pid) {
                ((AndroidProcessHandler) handler).setNoKill();
                handler.detachProcess();
                handler.notifyTextAvailable("Disconnecting run session: a new debug session will be established.\n", ProcessOutputTypes.STDOUT);
                break;
            }
        }
    }
}
Also used : AndroidProcessHandler(com.android.tools.idea.run.AndroidProcessHandler) AndroidProcessHandler(com.android.tools.idea.run.AndroidProcessHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler) Client(com.android.ddmlib.Client)

Example 37 with Client

use of com.android.ddmlib.Client 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 38 with Client

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

the class AndroidRunLayoutInspectorAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getProject();
    assert project != null;
    if (!AndroidSdkUtils.activateDdmsIfNecessary(project)) {
        return;
    }
    AndroidProcessChooserDialog dialog = new AndroidProcessChooserDialog(project, false);
    dialog.show();
    if (dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
        Client client = dialog.getClient();
        if (client != null) {
            new HierarchyViewAction.GetClientWindowsTask(project, client).queue();
        } else {
            Logger.getInstance(AndroidRunLayoutInspectorAction.class).warn("Not launching layout inspector - no client selected");
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) Client(com.android.ddmlib.Client) HierarchyViewAction(com.android.tools.idea.ddms.actions.HierarchyViewAction)

Example 39 with Client

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

the class InstantRunManager method refreshDebugger.

private void refreshDebugger(@NotNull String packageName) {
    // First we reapply the breakpoints on the new code, otherwise the breakpoints
    // remain set on the old classes and will never be hit again.
    ApplicationManager.getApplication().runReadAction(new Runnable() {

        @Override
        public void run() {
            DebuggerManagerEx debugger = DebuggerManagerEx.getInstanceEx(myProject);
            if (!debugger.getSessions().isEmpty()) {
                List<Breakpoint> breakpoints = debugger.getBreakpointManager().getBreakpoints();
                for (Breakpoint breakpoint : breakpoints) {
                    if (breakpoint.isEnabled()) {
                        breakpoint.setEnabled(false);
                        breakpoint.setEnabled(true);
                    }
                }
            }
        }
    });
    // Now we refresh the call-stacks and the variable panes.
    DebuggerManagerEx debugger = DebuggerManagerEx.getInstanceEx(myProject);
    for (final DebuggerSession session : debugger.getSessions()) {
        Client client = session.getProcess().getProcessHandler().getUserData(AndroidSessionInfo.ANDROID_DEBUG_CLIENT);
        if (client != null && client.isValid() && StringUtil.equals(packageName, client.getClientData().getClientDescription())) {
            session.getProcess().getManagerThread().invoke(new DebuggerCommandImpl() {

                @Override
                protected void action() throws Exception {
                    DebuggerContextImpl context = session.getContextManager().getContext();
                    SuspendContextImpl suspendContext = context.getSuspendContext();
                    if (suspendContext != null) {
                        XExecutionStack stack = suspendContext.getActiveExecutionStack();
                        if (stack != null) {
                            ((JavaExecutionStack) stack).initTopFrame();
                        }
                    }
                    ApplicationManager.getApplication().invokeLater(new Runnable() {

                        @Override
                        public void run() {
                            session.refresh(false);
                            XDebugSession xSession = session.getXDebugSession();
                            if (xSession != null) {
                                xSession.resume();
                            }
                        }
                    });
                }
            });
        }
    }
}
Also used : Breakpoint(com.intellij.debugger.ui.breakpoints.Breakpoint) XDebugSession(com.intellij.xdebugger.XDebugSession) DebuggerManagerEx(com.intellij.debugger.DebuggerManagerEx) XExecutionStack(com.intellij.xdebugger.frame.XExecutionStack) InstantRunPushFailedException(com.android.tools.fd.client.InstantRunPushFailedException) IOException(java.io.IOException) DebuggerSession(com.intellij.debugger.impl.DebuggerSession) DebuggerCommandImpl(com.intellij.debugger.engine.events.DebuggerCommandImpl) List(java.util.List) SuspendContextImpl(com.intellij.debugger.engine.SuspendContextImpl) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl) InstantRunClient(com.android.tools.fd.client.InstantRunClient) Client(com.android.ddmlib.Client)

Example 40 with Client

use of com.android.ddmlib.Client in project android_frameworks_base by DirtyUnicorns.

the class Main method findAndGetClassData.

public static Map<String, String> findAndGetClassData(IDevice device, String packageName) throws Exception {
    Client client = clientUtils.findClient(device, packageName, -1);
    if (client == null) {
        throw new RuntimeException("Could not find client...");
    }
    System.out.println("Found client: " + client);
    return getClassDataRetriever().getClassData(client);
}
Also used : Client(com.android.ddmlib.Client)

Aggregations

Client (com.android.ddmlib.Client)49 IDevice (com.android.ddmlib.IDevice)6 DumpData (com.android.preload.DumpData)5 Date (java.util.Date)5 AndroidDebugBridge (com.android.ddmlib.AndroidDebugBridge)3 ProcessHandler (com.intellij.execution.process.ProcessHandler)3 IOException (java.io.IOException)3 ClientData (com.android.ddmlib.ClientData)2 Project (com.intellij.openapi.project.Project)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 TreePath (javax.swing.tree.TreePath)2 Nullable (org.jetbrains.annotations.Nullable)2 IClientChangeListener (com.android.ddmlib.AndroidDebugBridge.IClientChangeListener)1 NullOutputReceiver (com.android.ddmlib.NullOutputReceiver)1 InstantRunClient (com.android.tools.fd.client.InstantRunClient)1 InstantRunPushFailedException (com.android.tools.fd.client.InstantRunPushFailedException)1 HierarchyViewAction (com.android.tools.idea.ddms.actions.HierarchyViewAction)1 GfxinfoHandler (com.android.tools.idea.monitor.gpu.gfxinfohandlers.GfxinfoHandler)1 AllocationTrackingSample (com.android.tools.idea.monitor.ui.memory.model.AllocationTrackingSample)1