use of com.android.tools.idea.run.AndroidSessionInfo in project android by JetBrains.
the class HotswapAction method doPerform.
@Override
protected void doPerform(@NotNull AnActionEvent e, @NotNull Project project) {
RunnerAndConfigurationSettings settings = RunManager.getInstance(project).getSelectedConfiguration();
if (settings == null) {
InstantRunManager.LOG.warn("Hotswap Action could not locate current run config settings");
return;
}
AndroidSessionInfo session = getAndroidSessionInfo(project, settings);
if (session == null) {
InstantRunManager.LOG.warn("Hotswap Action could not locate an existing session for selected run config.");
return;
}
Executor executor = getExecutor(session.getExecutorId());
if (executor == null) {
InstantRunManager.LOG.warn("Hotswap Action could not identify executor");
return;
}
ExecutionEnvironmentBuilder builder = ExecutionEnvironmentBuilder.createOrNull(executor, settings);
if (builder == null) {
InstantRunManager.LOG.warn("Hotswap Action could not construct an env");
return;
}
ExecutionEnvironment env = builder.activeTarget().dataContext(e.getDataContext()).build();
InstantRunUtils.setInvokedViaHotswapAction(env, true);
InstantRunManager.LOG.info("Invoking hotswap launch");
ProgramRunnerUtil.executeConfiguration(env, false, true);
}
use of com.android.tools.idea.run.AndroidSessionInfo in project android by JetBrains.
the class AndroidEnableAdbServiceAction method askForClosingDebugSessions.
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(AndroidSessionInfo.KEY);
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;
}
use of com.android.tools.idea.run.AndroidSessionInfo in project android by JetBrains.
the class HotswapAction method getActiveProcessHandler.
@Nullable
private static ProcessHandler getActiveProcessHandler(@Nullable Project project, @Nullable RunnerAndConfigurationSettings settings) {
if (project == null || settings == null) {
return null;
}
AndroidSessionInfo session = getAndroidSessionInfo(project, settings);
if (session == null) {
return null;
}
ProcessHandler processHandler = session.getProcessHandler();
if (processHandler.isProcessTerminated() || processHandler.isProcessTerminating()) {
return null;
}
return processHandler;
}
use of com.android.tools.idea.run.AndroidSessionInfo in project android by JetBrains.
the class HotswapAction method doUpdate.
@Override
protected void doUpdate(@NotNull AnActionEvent e, @NotNull Project project) {
Presentation presentation = e.getPresentation();
presentation.setEnabled(false);
if (!InstantRunSettings.isInstantRunEnabled()) {
presentation.setText("Apply Changes: Instant Run has been disabled");
return;
}
RunnerAndConfigurationSettings settings = RunManager.getInstance(project).getSelectedConfiguration();
if (settings == null) {
presentation.setText("Apply Changes: No run configuration selected");
return;
}
AndroidSessionInfo session = getAndroidSessionInfo(project, settings);
if (session == null) {
presentation.setText(String.format("Apply Changes: No active '%1$s' launch", settings.getName()));
return;
}
ProcessHandler processHandler = getActiveProcessHandler(project, settings);
if (processHandler == null) {
presentation.setText(String.format("Apply Changes: No active '%1$s' launch", settings.getName()));
return;
}
RunConfiguration configuration = settings.getConfiguration();
if (!(configuration instanceof ModuleBasedConfiguration)) {
presentation.setText(String.format("Apply Changes: '%1$s' is not a module based configuration", settings.getName()));
return;
}
Module module = ((ModuleBasedConfiguration) configuration).getConfigurationModule().getModule();
if (module == null) {
presentation.setText(String.format("Apply Changes: No module specified in '%1$s'", settings.getName()));
return;
}
if (!(configuration instanceof AndroidRunConfigurationBase)) {
presentation.setText(String.format("Apply Changes: '%1$s' is not an Android launch configuration", settings.getName()));
return;
}
if (!((AndroidRunConfigurationBase) configuration).supportsInstantRun()) {
presentation.setText(String.format("Apply Changes: Configuration '%1$s' does not support instant run", settings.getName()));
return;
}
AndroidVersion androidVersion = InstantRunManager.getMinDeviceApiLevel(processHandler);
if (androidVersion == null) {
presentation.setText(String.format("Apply Changes: Cannot locate device from '%1$s'", settings.getName()));
return;
}
if (!InstantRunManager.isInstantRunCapableDeviceVersion(androidVersion)) {
presentation.setText(String.format("Apply Changes: Target device API level (%1$s) too low for Instant Run", androidVersion));
return;
}
InstantRunGradleSupport status = InstantRunGradleUtils.getIrSupportStatus(InstantRunGradleUtils.getAppModel(module), androidVersion);
if (status != SUPPORTED) {
String notification = status.getUserNotification();
if (notification == null) {
notification = status.toString();
}
presentation.setText("Apply Changes: " + notification);
return;
}
presentation.setText("Apply Changes" + getShortcutText());
presentation.setEnabled(true);
}
use of com.android.tools.idea.run.AndroidSessionInfo in project intellij by bazelbuild.
the class BlazeAndroidTestProgramRunner method doExecute.
@Override
protected RunContentDescriptor doExecute(final RunProfileState state, final ExecutionEnvironment env) throws ExecutionException {
RunContentDescriptor descriptor = super.doExecute(state, env);
if (descriptor != null) {
ProcessHandler processHandler = descriptor.getProcessHandler();
assert processHandler != null;
RunProfile runProfile = env.getRunProfile();
int uniqueId = (runProfile instanceof RunConfigurationBase) ? ((RunConfigurationBase) runProfile).getUniqueID() : -1;
AndroidSessionInfo sessionInfo = new AndroidSessionInfo(processHandler, descriptor, uniqueId, env.getExecutor().getId(), env.getExecutor().getActionName(), InstantRunUtils.isInstantRunEnabled(env));
processHandler.putUserData(AndroidSessionInfo.KEY, sessionInfo);
}
return descriptor;
}
Aggregations