Search in sources :

Example 1 with AndroidSessionInfo

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);
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) Executor(com.intellij.execution.Executor) AndroidSessionInfo(com.android.tools.idea.run.AndroidSessionInfo) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder)

Example 2 with AndroidSessionInfo

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;
}
Also used : Project(com.intellij.openapi.project.Project) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) AndroidSessionInfo(com.android.tools.idea.run.AndroidSessionInfo) ArrayList(java.util.ArrayList) ProcessHandler(com.intellij.execution.process.ProcessHandler) Pair(com.intellij.openapi.util.Pair)

Example 3 with AndroidSessionInfo

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;
}
Also used : AndroidSessionInfo(com.android.tools.idea.run.AndroidSessionInfo) ProcessHandler(com.intellij.execution.process.ProcessHandler) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with AndroidSessionInfo

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);
}
Also used : RunConfiguration(com.intellij.execution.configurations.RunConfiguration) AndroidRunConfigurationBase(com.android.tools.idea.run.AndroidRunConfigurationBase) AndroidSessionInfo(com.android.tools.idea.run.AndroidSessionInfo) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) ProcessHandler(com.intellij.execution.process.ProcessHandler) InstantRunGradleSupport(com.android.tools.idea.fd.gradle.InstantRunGradleSupport) Presentation(com.intellij.openapi.actionSystem.Presentation) ModuleBasedConfiguration(com.intellij.execution.configurations.ModuleBasedConfiguration) Module(com.intellij.openapi.module.Module) AndroidVersion(com.android.sdklib.AndroidVersion)

Example 5 with AndroidSessionInfo

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;
}
Also used : RunConfigurationBase(com.intellij.execution.configurations.RunConfigurationBase) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) AndroidSessionInfo(com.android.tools.idea.run.AndroidSessionInfo) ProcessHandler(com.intellij.execution.process.ProcessHandler) RunProfile(com.intellij.execution.configurations.RunProfile)

Aggregations

AndroidSessionInfo (com.android.tools.idea.run.AndroidSessionInfo)8 ProcessHandler (com.intellij.execution.process.ProcessHandler)6 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)4 RunProfile (com.intellij.execution.configurations.RunProfile)3 AndroidRunConfigurationBase (com.android.tools.idea.run.AndroidRunConfigurationBase)2 ExecutionException (com.intellij.execution.ExecutionException)2 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)2 RunConfigurationBase (com.intellij.execution.configurations.RunConfigurationBase)2 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)2 ExecutionEnvironmentBuilder (com.intellij.execution.runners.ExecutionEnvironmentBuilder)2 Project (com.intellij.openapi.project.Project)2 Nullable (org.jetbrains.annotations.Nullable)2 AndroidVersion (com.android.sdklib.AndroidVersion)1 InstantRunGradleSupport (com.android.tools.idea.fd.gradle.InstantRunGradleSupport)1 AndroidDebugState (com.android.tools.idea.run.AndroidDebugState)1 AndroidProcessText (com.android.tools.idea.run.AndroidProcessText)1 DeviceFutures (com.android.tools.idea.run.DeviceFutures)1 LaunchOptions (com.android.tools.idea.run.LaunchOptions)1 DeployTarget (com.android.tools.idea.run.editor.DeployTarget)1 DeployTargetState (com.android.tools.idea.run.editor.DeployTargetState)1