use of com.android.ddmlib.AndroidDebugBridge in project android by JetBrains.
the class AndroidSdkUtils method activateDdmsIfNecessary.
public static boolean activateDdmsIfNecessary(@NotNull Project project) {
if (AndroidEnableAdbServiceAction.isAdbServiceEnabled()) {
AndroidDebugBridge bridge = getDebugBridge(project);
if (bridge != null && AdbService.isDdmsCorrupted(bridge)) {
LOG.info("DDMLIB is corrupted and will be restarted");
AdbService.getInstance().restartDdmlib(project);
}
} else {
OSProcessHandler ddmsProcessHandler = AndroidRunDdmsAction.getDdmsProcessHandler();
if (ddmsProcessHandler != null) {
String message = "Monitor will be closed to enable ADB integration. Continue?";
int result = Messages.showYesNoDialog(project, message, "ADB Integration", Messages.getQuestionIcon());
if (result != Messages.YES) {
return false;
}
Runnable destroyingRunnable = () -> {
if (!ddmsProcessHandler.isProcessTerminated()) {
OSProcessManager.getInstance().killProcessTree(ddmsProcessHandler.getProcess());
ddmsProcessHandler.waitFor();
}
};
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(destroyingRunnable, "Closing Monitor", true, project)) {
return false;
}
setAdbServiceEnabled(project, true);
return true;
}
int result = Messages.showYesNoDialog(project, AndroidBundle.message("android.ddms.disabled.error"), AndroidBundle.message("android.ddms.disabled.dialog.title"), Messages.getQuestionIcon());
if (result != Messages.YES) {
return false;
}
setAdbServiceEnabled(project, true);
}
return true;
}
use of com.android.ddmlib.AndroidDebugBridge in project android by JetBrains.
the class AndroidToolWindowFactory method createToolWindowContent.
@Override
public void createToolWindowContent(@NotNull final Project project, @NotNull final ToolWindow toolWindow) {
// In order to use the runner layout ui, the runner infrastructure needs to be initialized.
// Otherwise it is not possible to for example drag one of the tabs out of the tool window.
// The object that needs to be created is the content manager of the execution manager for this project.
ExecutionManager.getInstance(project).getContentManager();
RunnerLayoutUi layoutUi = RunnerLayoutUi.Factory.getInstance(project).create("Android", TOOL_WINDOW_ID, "Profiling Tools", project);
toolWindow.setIcon(AndroidIcons.AndroidToolWindow);
toolWindow.setAvailable(true, null);
toolWindow.setToHideOnEmptyContent(true);
toolWindow.setTitle(TOOL_WINDOW_ID);
DeviceContext deviceContext = new DeviceContext();
// TODO Remove global handlers. These handlers are global, but are set per project.
// if there are two projects opened, things go very wrong.
ClientData.setMethodProfilingHandler(new OpenVmTraceHandler(project));
Content logcatContent = createLogcatContent(layoutUi, project, deviceContext);
final AndroidLogcatView logcatView = logcatContent.getUserData(AndroidLogcatView.ANDROID_LOGCAT_VIEW_KEY);
assert logcatView != null;
logcatContent.setSearchComponent(logcatView.createSearchComponent());
layoutUi.addContent(logcatContent, 0, PlaceInGrid.center, false);
MonitorContentFactory.createMonitorContent(project, deviceContext, layoutUi);
layoutUi.getOptions().setLeftToolbar(getToolbarActions(project, deviceContext), ActionPlaces.UNKNOWN);
layoutUi.addListener(new ContentManagerAdapter() {
@Override
public void selectionChanged(ContentManagerEvent event) {
Content selectedContent = event.getContent();
BaseMonitorView view = selectedContent.getUserData(BaseMonitorView.MONITOR_VIEW_KEY);
if (view != null && event.getOperation() == ContentManagerEvent.ContentOperation.add) {
UsageTracker.getInstance().log(AndroidStudioEvent.newBuilder().setCategory(AndroidStudioEvent.EventCategory.PROFILING).setKind(AndroidStudioEvent.EventKind.MONITOR_RUNNING).setMonitorType(view.getMonitorType()));
}
}
}, project);
final JBLoadingPanel loadingPanel = new JBLoadingPanel(new BorderLayout(), project);
DevicePanel devicePanel = new DevicePanel(project, deviceContext);
JPanel panel = devicePanel.getComponent();
panel.setBorder(IdeBorderFactory.createBorder(SideBorder.BOTTOM));
loadingPanel.add(panel, BorderLayout.NORTH);
loadingPanel.add(layoutUi.getComponent(), BorderLayout.CENTER);
final ContentManager contentManager = toolWindow.getContentManager();
Content c = contentManager.getFactory().createContent(loadingPanel, "", true);
// Store references to the logcat & device panel views, so that these views can be retrieved directly from
// the DDMS tool window. (e.g. to clear logcat before a launch, select a particular device, etc)
c.putUserData(AndroidLogcatView.ANDROID_LOGCAT_VIEW_KEY, logcatView);
c.putUserData(DEVICES_PANEL_KEY, devicePanel);
contentManager.addContent(c);
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
logcatView.activate();
final ToolWindow window = ToolWindowManager.getInstance(project).getToolWindow(TOOL_WINDOW_ID);
if (window != null && window.isVisible()) {
ConsoleView console = logcatView.getLogConsole().getConsole();
if (console != null) {
checkFacetAndSdk(project, console);
}
}
}
}, project.getDisposed());
final File adb = AndroidSdkUtils.getAdb(project);
if (adb == null) {
return;
}
loadingPanel.setLoadingText("Initializing ADB");
loadingPanel.startLoading();
ListenableFuture<AndroidDebugBridge> future = AdbService.getInstance().getDebugBridge(adb);
Futures.addCallback(future, new FutureCallback<AndroidDebugBridge>() {
@Override
public void onSuccess(@Nullable AndroidDebugBridge bridge) {
Logger.getInstance(AndroidToolWindowFactory.class).info("Successfully obtained debug bridge");
loadingPanel.stopLoading();
}
@Override
public void onFailure(@NotNull Throwable t) {
loadingPanel.stopLoading();
// If we cannot connect to ADB in a reasonable amount of time (10 seconds timeout in AdbService), then something is seriously
// wrong. The only identified reason so far is that some machines have incompatible versions of adb that were already running.
// e.g. Genymotion, some HTC flashing software, Ubuntu's adb package may all conflict with the version of adb in the SDK.
Logger.getInstance(AndroidToolWindowFactory.class).info("Unable to obtain debug bridge", t);
String msg;
if (t.getMessage() != null) {
msg = t.getMessage();
} else {
msg = String.format("Unable to establish a connection to adb.\n\n" + "Check the Event Log for possible issues.\n" + "This can happen if you have an incompatible version of adb running already.\n" + "Try re-opening %1$s after killing any existing adb daemons.\n\n" + "If this happens repeatedly, please file a bug at http://b.android.com including the following:\n" + " 1. Output of the command: '%2$s devices'\n" + " 2. Your idea.log file (Help | Show Log in Explorer)\n", ApplicationNamesInfo.getInstance().getProductName(), adb.getAbsolutePath());
}
Messages.showErrorDialog(msg, "ADB Connection Error");
}
}, EdtExecutor.INSTANCE);
}
use of com.android.ddmlib.AndroidDebugBridge in project android by JetBrains.
the class AdbServiceTest method testBasics.
// tests that basic API for getting and terminating a debug bridge works
public void testBasics() throws ExecutionException {
if (SystemInfo.isWindows) {
// Do not run tests on Windows (see http://b.android.com/222904)
return;
}
ListenableFuture<AndroidDebugBridge> future = AdbService.getInstance().getDebugBridge(AndroidSdkUtils.getAdb(getProject()));
AndroidDebugBridge bridge = Uninterruptibles.getUninterruptibly(future);
assertTrue(bridge.isConnected());
AdbService.getInstance().terminateDdmlib();
}
use of com.android.ddmlib.AndroidDebugBridge in project android by JetBrains.
the class GetAdbAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
Notifications.Bus.notify(new Notification("Android", "ADB", "ADB requested.", NotificationType.INFORMATION));
Project project = getEventProject(e);
File adb = project == null ? null : AndroidSdkUtils.getAdb(project);
if (adb == null) {
return;
}
ListenableFuture<AndroidDebugBridge> bridge = AdbService.getInstance().getDebugBridge(adb);
Futures.addCallback(bridge, new FutureCallback<AndroidDebugBridge>() {
@Override
public void onSuccess(AndroidDebugBridge result) {
Notifications.Bus.notify(new Notification("Android", "ADB", "ADB obtained", NotificationType.INFORMATION));
}
@Override
public void onFailure(Throwable t) {
Notifications.Bus.notify(new Notification("Android", "ADB", "ADB error: " + t.toString(), NotificationType.INFORMATION));
}
});
}
use of com.android.ddmlib.AndroidDebugBridge in project android by JetBrains.
the class DeployTargetPickerDialog method createCenterPanel.
@Nullable
@Override
protected JComponent createCenterPanel() {
final JBLoadingPanel loadingPanel = new JBLoadingPanel(new BorderLayout(), getDisposable());
loadingPanel.add(myDeployTargetProvider == null ? myDevicesPanel : myContentPane);
loadingPanel.setLoadingText("Initializing ADB");
if (!myAdbFuture.isDone()) {
loadingPanel.startLoading();
Futures.addCallback(myAdbFuture, new FutureCallback<AndroidDebugBridge>() {
@Override
public void onSuccess(AndroidDebugBridge result) {
loadingPanel.stopLoading();
Logger.getInstance(DeployTargetPickerDialog.class).info("Successfully obtained debug bridge");
}
@Override
public void onFailure(Throwable t) {
loadingPanel.stopLoading();
Logger.getInstance(DeployTargetPickerDialog.class).info("Unable to obtain debug bridge", t);
// TODO: show an inline banner to restart adb?
}
}, EdtExecutor.INSTANCE);
}
return loadingPanel;
}
Aggregations