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;
}
}
}
}
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);
});
}
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");
}
}
}
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();
}
}
});
}
});
}
}
}
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);
}
Aggregations