Search in sources :

Example 1 with AndroidRunConfigurationBase

use of com.android.tools.idea.run.AndroidRunConfigurationBase in project android by JetBrains.

the class AndroidUtils method getDefaultTargetSelectionMode.

@Nullable
public static TargetSelectionMode getDefaultTargetSelectionMode(@NotNull Module module, @NotNull ConfigurationType type, @NonNls ConfigurationType alternativeType) {
    final RunManager runManager = RunManager.getInstance(module.getProject());
    List<RunConfiguration> configurations = runManager.getConfigurationsList(type);
    TargetSelectionMode alternative = null;
    if (configurations.size() > 0) {
        for (RunConfiguration configuration : configurations) {
            if (configuration instanceof AndroidRunConfigurationBase) {
                final AndroidRunConfigurationBase runConfig = (AndroidRunConfigurationBase) configuration;
                final TargetSelectionMode targetMode = runConfig.getDeployTargetContext().getTargetSelectionMode();
                //noinspection IfStatementWithIdenticalBranches - branches are only identical for final iteration of outer loop
                if (runConfig.getConfigurationModule() == module) {
                    return targetMode;
                } else {
                    alternative = targetMode;
                }
            }
        }
    }
    if (alternative != null) {
        return alternative;
    }
    configurations = runManager.getConfigurationsList(alternativeType);
    if (configurations.size() > 0) {
        for (RunConfiguration configuration : configurations) {
            if (configuration instanceof AndroidRunConfigurationBase) {
                return ((AndroidRunConfigurationBase) configuration).getDeployTargetContext().getTargetSelectionMode();
            }
        }
    }
    return null;
}
Also used : RunConfiguration(com.intellij.execution.configurations.RunConfiguration) AndroidRunConfigurationBase(com.android.tools.idea.run.AndroidRunConfigurationBase) TargetSelectionMode(com.android.tools.idea.run.TargetSelectionMode) RunManager(com.intellij.execution.RunManager) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with AndroidRunConfigurationBase

use of com.android.tools.idea.run.AndroidRunConfigurationBase 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 3 with AndroidRunConfigurationBase

use of com.android.tools.idea.run.AndroidRunConfigurationBase in project intellij by bazelbuild.

the class ConnectBlazeTestDebuggerTask method launchDebugger.

/**
 * Nearly a clone of {@link ConnectJavaDebuggerTask#launchDebugger}. There are a few changes to
 * account for null variables that could occur in our implementation.
 */
@Override
public ProcessHandler launchDebugger(@NotNull LaunchInfo currentLaunchInfo, @NotNull Client client, @NotNull ProcessHandlerLaunchStatus launchStatus, @NotNull ProcessHandlerConsolePrinter printer) {
    String debugPort = Integer.toString(client.getDebuggerListenPort());
    int pid = client.getClientData().getPid();
    Logger.getInstance(ConnectJavaDebuggerTask.class).info(String.format(Locale.US, "Attempting to connect debugger to port %1$s [client %2$d]", debugPort, pid));
    // create a new process handler
    RemoteConnection connection = new RemoteConnection(true, "localhost", debugPort, false);
    RemoteDebugProcessHandler debugProcessHandler = new RemoteDebugProcessHandler(project);
    // switch the launch status and console printers to point to the new process handler
    // this is required, esp. for AndroidTestListener which holds a
    // reference to the launch status and printers, and those should
    // be updated to point to the new process handlers,
    // otherwise test results will not be forwarded appropriately
    ProcessHandler oldProcessHandler = launchStatus.getProcessHandler();
    launchStatus.setProcessHandler(debugProcessHandler);
    printer.setProcessHandler(debugProcessHandler);
    // Detach old process handler after the launch status
    // has been updated to point to the new process handler.
    oldProcessHandler.detachProcess();
    AndroidDebugState debugState = new AndroidDebugState(project, debugProcessHandler, connection, currentLaunchInfo.consoleProvider);
    RunContentDescriptor oldDescriptor;
    AndroidSessionInfo oldSession = oldProcessHandler.getUserData(AndroidSessionInfo.KEY);
    if (oldSession != null) {
        oldDescriptor = oldSession.getDescriptor();
    } else {
        // This is the first time we are attaching the debugger; get it from the environment instead.
        oldDescriptor = currentLaunchInfo.env.getContentToReuse();
    }
    RunContentDescriptor debugDescriptor;
    try {
        // @formatter:off
        ExecutionEnvironment debugEnv = new ExecutionEnvironmentBuilder(currentLaunchInfo.env).executor(currentLaunchInfo.executor).runner(currentLaunchInfo.runner).contentToReuse(oldDescriptor).build();
        debugDescriptor = DebuggerPanelsManager.getInstance(project).attachVirtualMachine(debugEnv, debugState, connection, false);
    // @formatter:on
    } catch (ExecutionException e) {
        printer.stderr("ExecutionException: " + e.getMessage() + '.');
        return null;
    }
    // Based on the above try block we shouldn't get here unless we have assigned to debugDescriptor
    assert debugDescriptor != null;
    // re-run the collected text from the old process handler to the new
    // TODO: is there a race between messages received once the debugger has been connected,
    // and these messages that are printed out?
    final AndroidProcessText oldText = AndroidProcessText.get(oldProcessHandler);
    if (oldText != null) {
        oldText.printTo(debugProcessHandler);
    }
    RunProfile runProfile = currentLaunchInfo.env.getRunProfile();
    int uniqueId = runProfile instanceof AndroidRunConfigurationBase ? ((AndroidRunConfigurationBase) runProfile).getUniqueID() : -1;
    AndroidSessionInfo value = new AndroidSessionInfo(debugProcessHandler, debugDescriptor, uniqueId, currentLaunchInfo.executor.getId(), currentLaunchInfo.executor.getActionName(), false);
    debugProcessHandler.putUserData(AndroidSessionInfo.KEY, value);
    debugProcessHandler.putUserData(AndroidSessionInfo.ANDROID_DEBUG_CLIENT, client);
    debugProcessHandler.putUserData(AndroidSessionInfo.ANDROID_DEVICE_API_LEVEL, client.getDevice().getVersion());
    return debugProcessHandler;
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) AndroidRunConfigurationBase(com.android.tools.idea.run.AndroidRunConfigurationBase) ConnectJavaDebuggerTask(com.android.tools.idea.run.tasks.ConnectJavaDebuggerTask) AndroidSessionInfo(com.android.tools.idea.run.AndroidSessionInfo) RunProfile(com.intellij.execution.configurations.RunProfile) RemoteDebugProcessHandler(com.intellij.debugger.engine.RemoteDebugProcessHandler) AndroidProcessText(com.android.tools.idea.run.AndroidProcessText) AndroidDebugState(com.android.tools.idea.run.AndroidDebugState) RemoteDebugProcessHandler(com.intellij.debugger.engine.RemoteDebugProcessHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler) RemoteConnection(com.intellij.execution.configurations.RemoteConnection) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder) ExecutionException(com.intellij.execution.ExecutionException)

Aggregations

AndroidRunConfigurationBase (com.android.tools.idea.run.AndroidRunConfigurationBase)3 AndroidSessionInfo (com.android.tools.idea.run.AndroidSessionInfo)2 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)2 ProcessHandler (com.intellij.execution.process.ProcessHandler)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 TargetSelectionMode (com.android.tools.idea.run.TargetSelectionMode)1 ConnectJavaDebuggerTask (com.android.tools.idea.run.tasks.ConnectJavaDebuggerTask)1 RemoteDebugProcessHandler (com.intellij.debugger.engine.RemoteDebugProcessHandler)1 ExecutionException (com.intellij.execution.ExecutionException)1 RunManager (com.intellij.execution.RunManager)1 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 ModuleBasedConfiguration (com.intellij.execution.configurations.ModuleBasedConfiguration)1 RemoteConnection (com.intellij.execution.configurations.RemoteConnection)1 RunProfile (com.intellij.execution.configurations.RunProfile)1 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)1 ExecutionEnvironmentBuilder (com.intellij.execution.runners.ExecutionEnvironmentBuilder)1 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)1