private boolean closeQuery() { final RunContentDescriptor descriptor = getRunContentDescriptorByContent(myContent); if (descriptor == null) { return true; } final ProcessHandler processHandler = descriptor.getProcessHandler(); if (processHandler == null || processHandler.isProcessTerminated() || processHandler.isProcessTerminating()) { return true; } final boolean destroyProcess; if (processHandler.isSilentlyDestroyOnClose() || Boolean.TRUE.equals( processHandler.getUserData(ProcessHandler.SILENTLY_DESTROY_ON_CLOSE))) { destroyProcess = true; } else { // todo[nik] this is a temporary solution for the following problem: some configurations // should not allow user to choose between 'terminating' and 'detaching' final boolean useDefault = Boolean.TRUE.equals( processHandler.getUserData(ALWAYS_USE_DEFAULT_STOPPING_BEHAVIOUR_KEY)); final TerminateRemoteProcessDialog terminateDialog = new TerminateRemoteProcessDialog( myProject, descriptor.getDisplayName(), processHandler.detachIsDefault(), useDefault); terminateDialog.show(); if (terminateDialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) return false; destroyProcess = terminateDialog.forceTermination(); } if (destroyProcess) { processHandler.destroyProcess(); } else { processHandler.detachProcess(); } waitForProcess(descriptor); return true; }
private static boolean askForClosingDebugSessions(@NotNull Project project) { final List<Pair<ProcessHandler, RunContentDescriptor>> pairs = new ArrayList<Pair<ProcessHandler, RunContentDescriptor>>(); for (Project p : ProjectManager.getInstance().getOpenProjects()) { final ProcessHandler[] processes = ExecutionManager.getInstance(p).getRunningProcesses(); for (ProcessHandler process : processes) { if (!process.isProcessTerminated()) { final AndroidSessionInfo info = process.getUserData(AndroidDebugRunner.ANDROID_SESSION_INFO); if (info != null) { pairs.add(Pair.create(process, info.getDescriptor())); } } } } if (pairs.size() == 0) { return true; } final StringBuilder s = new StringBuilder(); for (Pair<ProcessHandler, RunContentDescriptor> pair : pairs) { if (s.length() > 0) { s.append('\n'); } s.append(pair.getSecond().getDisplayName()); } final int r = Messages.showYesNoDialog( project, AndroidBundle.message("android.debug.sessions.will.be.closed", s), AndroidBundle.message("android.disable.adb.service.title"), Messages.getQuestionIcon()); return r == Messages.YES; }