Search in sources :

Example 1 with HaxmWizard

use of com.android.tools.idea.sdk.wizard.HaxmWizard in project android by JetBrains.

the class AccelerationErrorSolution method getAction.

private Runnable getAction() {
    switch(myError.getSolution()) {
        case DOWNLOAD_EMULATOR:
        case UPDATE_EMULATOR:
            return new Runnable() {

                @Override
                public void run() {
                    try {
                        showQuickFix(ImmutableList.of(SdkConstants.FD_TOOLS, SdkConstants.FD_PLATFORM_TOOLS));
                    } finally {
                        reportBack();
                    }
                }
            };
        case UPDATE_PLATFORM_TOOLS:
            return new Runnable() {

                @Override
                public void run() {
                    try {
                        showQuickFix(ImmutableList.of(SdkConstants.FD_PLATFORM_TOOLS));
                    } finally {
                        reportBack();
                    }
                }
            };
        case UPDATE_SYSTEM_IMAGES:
            return new Runnable() {

                @Override
                public void run() {
                    try {
                        AvdManagerConnection avdManager = AvdManagerConnection.getDefaultAvdManagerConnection();
                        showQuickFix(avdManager.getSystemImageUpdates());
                    } finally {
                        reportBack();
                    }
                }
            };
        case INSTALL_KVM:
            return new Runnable() {

                @Override
                public void run() {
                    try {
                        GeneralCommandLine install = createKvmInstallCommand();
                        if (install == null) {
                            BrowserUtil.browse(KVM_INSTRUCTIONS, myProject);
                        } else {
                            String text = String.format("Linux systems vary a great deal; the installation steps we will attempt may not work in your particular scenario.\n\n" + "The steps are:\n\n" + "  %1$s\n\n" + "If you prefer, you can skip this step and perform the KVM installation steps on your own.\n\n" + "There might be more details at: %2$s\n", install.getCommandLineString(), KVM_INSTRUCTIONS);
                            int response = Messages.showDialog(text, myError.getSolution().getDescription(), new String[] { "Skip", "Proceed" }, 1, Messages.getQuestionIcon());
                            if (response == 1) {
                                try {
                                    execute(install);
                                    myChangesMade = true;
                                } catch (ExecutionException ex) {
                                    LOG.error(ex);
                                    BrowserUtil.browse(KVM_INSTRUCTIONS, myProject);
                                    Messages.showWarningDialog(myProject, "Please install KVM on your own", "Installation Failed");
                                }
                            } else {
                                BrowserUtil.browse(KVM_INSTRUCTIONS, myProject);
                            }
                        }
                    } finally {
                        reportBack();
                    }
                }
            };
        case INSTALL_HAXM:
        case REINSTALL_HAXM:
            return new Runnable() {

                @Override
                public void run() {
                    try {
                        HaxmWizard wizard = new HaxmWizard(false);
                        wizard.init();
                        myChangesMade = wizard.showAndGet();
                    } finally {
                        reportBack();
                    }
                }
            };
        case TURNOFF_HYPER_V:
            return new Runnable() {

                @Override
                public void run() {
                    try {
                        GeneralCommandLine turnHyperVOff = new ElevatedCommandLine();
                        turnHyperVOff.setExePath("bcdedit");
                        turnHyperVOff.addParameters("/set", "hypervisorlaunchtype", "off");
                        turnHyperVOff.setWorkDirectory(FileUtilRt.getTempDirectory());
                        try {
                            execute(turnHyperVOff);
                            promptAndReboot(SOLUTION_REBOOT_AFTER_TURNING_HYPER_V_OFF);
                        } catch (ExecutionException ex) {
                            LOG.error(ex);
                            Messages.showWarningDialog(myProject, SOLUTION_TURN_OFF_HYPER_V, "Operation Failed");
                        }
                    } finally {
                        reportBack();
                    }
                }
            };
        default:
            return new Runnable() {

                @Override
                public void run() {
                    try {
                        Messages.showWarningDialog(myProject, myError.getSolutionMessage(), myError.getSolution().getDescription());
                    } finally {
                        reportBack();
                    }
                }
            };
    }
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) HaxmWizard(com.android.tools.idea.sdk.wizard.HaxmWizard) ExecutionException(com.intellij.execution.ExecutionException)

Example 2 with HaxmWizard

use of com.android.tools.idea.sdk.wizard.HaxmWizard in project android by JetBrains.

the class HaxmInstallListener method statusChanged.

@Override
public void statusChanged(@NonNull PackageOperation op, @NonNull ProgressIndicator progress) throws PackageOperation.StatusChangeListenerException {
    if ((op instanceof Uninstaller && op.getInstallStatus() == PackageOperation.InstallStatus.RUNNING) || (op instanceof Installer && op.getInstallStatus() == PackageOperation.InstallStatus.COMPLETE)) {
        // There are two possible workflows:
        // 1) Installation workflow: Install SDK package -> invoke wizard to run installer
        // 2) Uninstallation workflow: Invoke wizard to run installer with uninstallation params -> Uninstall SDK package
        // In both cases we need to leave the state of the SDK package consistent with the installer invocation success
        // status.
        // So if calling the installer during uninstallation fails, we simply throw an exception here and do not proceed
        // with SDK package removal, as the SDK package operation is in PREPARING state
        // If calling the installer during installation fails, then it is the responsibility of the wizard to cleanup the SDK
        // package as well
        final AtomicBoolean result = new AtomicBoolean(false);
        ApplicationManager.getApplication().invokeAndWait(() -> {
            HaxmWizard wizard = new HaxmWizard(op instanceof Uninstaller);
            wizard.init();
            result.set(wizard.showAndGet());
        }, ModalityState.any());
        if (!result.get()) {
            throw new PackageOperation.StatusChangeListenerException("HAXM setup failed!");
        }
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Installer(com.android.repository.api.Installer) Uninstaller(com.android.repository.api.Uninstaller) HaxmWizard(com.android.tools.idea.sdk.wizard.HaxmWizard)

Aggregations

HaxmWizard (com.android.tools.idea.sdk.wizard.HaxmWizard)2 Installer (com.android.repository.api.Installer)1 Uninstaller (com.android.repository.api.Uninstaller)1 ExecutionException (com.intellij.execution.ExecutionException)1 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1