Search in sources :

Example 1 with GpuMode

use of com.android.sdklib.internal.avd.GpuMode in project android by JetBrains.

the class ConfigureAvdOptionsStep method gpuOtherMode.

@VisibleForTesting
static GpuMode gpuOtherMode(int apiLevel, boolean isIntel, boolean isGoogle, boolean isMac) {
    boolean supportGuest = (apiLevel >= 23) && isIntel && isGoogle;
    GpuMode otherMode = GpuMode.OFF;
    if (supportGuest) {
        otherMode = GpuMode.SWIFT;
    } else if (!isMac) {
        otherMode = GpuMode.MESA;
    }
    return otherMode;
}
Also used : GpuMode(com.android.sdklib.internal.avd.GpuMode) VisibleForTesting(com.android.annotations.VisibleForTesting)

Example 2 with GpuMode

use of com.android.sdklib.internal.avd.GpuMode in project android by JetBrains.

the class ConfigureAvdOptionsStep method populateHostGraphicsDropDown.

private void populateHostGraphicsDropDown() {
    myHostGraphics.removeAllItems();
    GpuMode otherMode = gpuOtherMode(getSelectedApiLevel(), isIntel(), isGoogleApiSelected(), SystemInfo.isMac);
    myHostGraphics.addItem(GpuMode.AUTO);
    myHostGraphics.addItem(GpuMode.HOST);
    myHostGraphics.addItem(otherMode);
}
Also used : GpuMode(com.android.sdklib.internal.avd.GpuMode)

Example 3 with GpuMode

use of com.android.sdklib.internal.avd.GpuMode in project android by JetBrains.

the class AvdOptionsModel method handleFinished.

@Override
protected void handleFinished() {
    // By this point we should have both a Device and a SystemImage
    Device device = myDevice.getValue();
    SystemImageDescription systemImage = mySystemImage.getValue();
    Map<String, String> hardwareProperties = DeviceManager.getHardwareProperties(device);
    Map<String, Object> userEditedProperties = generateUserEditedPropertiesMap();
    // Remove the SD card setting that we're not using
    String sdCard = null;
    boolean useExisting = myUseExternalSdCard.get();
    if (!useExisting) {
        if (sdCardStorage().get().isPresent() && myOriginalSdCard != null && sdCardStorage().getValue().equals(myOriginalSdCard.get())) {
            // unchanged, use existing card
            useExisting = true;
        }
    }
    boolean hasSdCard = false;
    if (!useExisting) {
        userEditedProperties.remove(AvdWizardUtils.EXISTING_SD_LOCATION);
        Storage storage = null;
        myOriginalSdCard = new ObjectValueProperty<>(mySdCardStorage.getValue());
        if (mySdCardStorage.get().isPresent()) {
            storage = mySdCardStorage.getValue();
            sdCard = toIniString(storage, false);
        }
        hasSdCard = storage != null && storage.getSize() > 0;
    } else if (!Strings.isNullOrEmpty(existingSdLocation.get())) {
        sdCard = existingSdLocation.get();
        userEditedProperties.remove(AvdWizardUtils.SD_CARD_STORAGE_KEY);
        hasSdCard = true;
    }
    hardwareProperties.put(HardwareProperties.HW_SDCARD, toIniString(hasSdCard));
    // Remove any internal keys from the map
    userEditedProperties = Maps.filterEntries(userEditedProperties, input -> !input.getKey().startsWith(AvdWizardUtils.WIZARD_ONLY) && input.getValue() != null);
    // Call toIniString() on all remaining values
    hardwareProperties.putAll(Maps.transformEntries(userEditedProperties, (key, value) -> {
        if (value instanceof Storage) {
            if (key.equals(AvdWizardUtils.RAM_STORAGE_KEY) || key.equals(AvdWizardUtils.VM_HEAP_STORAGE_KEY)) {
                return toIniString((Storage) value, true);
            } else {
                return toIniString((Storage) value, false);
            }
        } else if (value instanceof Boolean) {
            return toIniString((Boolean) value);
        } else if (value instanceof File) {
            return toIniString((File) value);
        } else if (value instanceof Double) {
            return toIniString((Double) value);
        } else if (value instanceof GpuMode) {
            return ((GpuMode) value).getGpuSetting();
        } else {
            return value.toString();
        }
    }));
    File skinFile = (myAvdDeviceData.customSkinFile().get().isPresent()) ? myAvdDeviceData.customSkinFile().getValue() : AvdWizardUtils.resolveSkinPath(device.getDefaultHardware().getSkinFile(), systemImage, FileOpUtils.create());
    if (myBackupSkinFile.get().isPresent()) {
        hardwareProperties.put(AvdManager.AVD_INI_BACKUP_SKIN_PATH, myBackupSkinFile.getValue().getPath());
    }
    // Add defaults if they aren't already set differently
    if (!hardwareProperties.containsKey(AvdManager.AVD_INI_SKIN_DYNAMIC)) {
        hardwareProperties.put(AvdManager.AVD_INI_SKIN_DYNAMIC, toIniString(true));
    }
    if (!hardwareProperties.containsKey(HardwareProperties.HW_KEYBOARD)) {
        hardwareProperties.put(HardwareProperties.HW_KEYBOARD, toIniString(false));
    }
    boolean isCircular = myAvdDeviceData.isScreenRound().get();
    String tempAvdName = myAvdId.get();
    final String avdName = tempAvdName.isEmpty() ? calculateAvdName(myAvdInfo, hardwareProperties, device) : tempAvdName;
    // If we're editing an AVD and we downgrade a system image, wipe the user data with confirmation
    if (myAvdInfo != null) {
        ISystemImage image = myAvdInfo.getSystemImage();
        if (image != null) {
            int oldApiLevel = image.getAndroidVersion().getFeatureLevel();
            int newApiLevel = systemImage.getVersion().getFeatureLevel();
            final String oldApiName = image.getAndroidVersion().getApiString();
            final String newApiName = systemImage.getVersion().getApiString();
            if (oldApiLevel > newApiLevel || (oldApiLevel == newApiLevel && image.getAndroidVersion().isPreview() && !systemImage.getVersion().isPreview())) {
                final AtomicReference<Boolean> shouldContinue = new AtomicReference<>();
                ApplicationManager.getApplication().invokeAndWait(() -> {
                    String message = String.format(Locale.getDefault(), "You are about to downgrade %1$s from API level %2$s to API level %3$s.\n" + "This requires a wipe of the userdata partition of the AVD.\nDo you wish to " + "continue with the data wipe?", avdName, oldApiName, newApiName);
                    int result = Messages.showYesNoDialog((Project) null, message, "Confirm Data Wipe", AllIcons.General.QuestionDialog);
                    shouldContinue.set(result == Messages.YES);
                }, ModalityState.any());
                if (shouldContinue.get()) {
                    AvdManagerConnection.getDefaultAvdManagerConnection().wipeUserData(myAvdInfo);
                } else {
                    return;
                }
            }
        }
    }
    AvdManagerConnection connection = AvdManagerConnection.getDefaultAvdManagerConnection();
    myCreatedAvd = connection.createOrUpdateAvd(myAvdInfo, avdName, device, systemImage, mySelectedAvdOrientation.get(), isCircular, sdCard, skinFile, hardwareProperties, false);
    if (myCreatedAvd == null) {
        ApplicationManager.getApplication().invokeAndWait(() -> Messages.showErrorDialog((Project) null, "An error occurred while creating the AVD. See idea.log for details.", "Error Creating AVD"), ModalityState.any());
    }
}
Also used : com.android.tools.idea.ui.properties.core(com.android.tools.idea.ui.properties.core) AllIcons(com.intellij.icons.AllIcons) Strings.nullToEmpty(com.google.common.base.Strings.nullToEmpty) ModalityState(com.intellij.openapi.application.ModalityState) ScreenSize(com.android.resources.ScreenSize) AtomicReference(java.util.concurrent.atomic.AtomicReference) AvdInfo(com.android.sdklib.internal.avd.AvdInfo) Strings(com.google.common.base.Strings) ISystemImage(com.android.sdklib.ISystemImage) Locale(java.util.Locale) Density(com.android.resources.Density) Map(java.util.Map) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) FileUtil(com.intellij.openapi.util.io.FileUtil) Device(com.android.sdklib.devices.Device) Objects(com.google.common.base.Objects) HashMap(com.intellij.util.containers.hash.HashMap) HardwareProperties(com.android.sdklib.internal.avd.HardwareProperties) AvdManager(com.android.sdklib.internal.avd.AvdManager) DeviceManager(com.android.sdklib.devices.DeviceManager) WizardModel(com.android.tools.idea.wizard.model.WizardModel) Maps(com.google.common.collect.Maps) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) FileOpUtils(com.android.repository.io.FileOpUtils) GpuMode(com.android.sdklib.internal.avd.GpuMode) ScreenOrientation(com.android.resources.ScreenOrientation) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) Storage(com.android.sdklib.devices.Storage) GpuMode(com.android.sdklib.internal.avd.GpuMode) Device(com.android.sdklib.devices.Device) AtomicReference(java.util.concurrent.atomic.AtomicReference) Project(com.intellij.openapi.project.Project) Storage(com.android.sdklib.devices.Storage) ISystemImage(com.android.sdklib.ISystemImage) File(java.io.File)

Example 4 with GpuMode

use of com.android.sdklib.internal.avd.GpuMode in project android by JetBrains.

the class ConfigureAvdOptionsStep method updateGpuControlsAfterSystemImageChange.

private void updateGpuControlsAfterSystemImageChange() {
    GpuMode mode = getModel().hostGpuMode().getValueOr(GpuMode.AUTO);
    populateHostGraphicsDropDown();
    switch(mode) {
        case AUTO:
            myHostGraphics.setSelectedIndex(0);
            break;
        case HOST:
            myHostGraphics.setSelectedIndex(1);
            break;
        case MESA:
        case SWIFT:
        case OFF:
        default:
            myHostGraphics.setSelectedIndex(2);
            break;
    }
}
Also used : GpuMode(com.android.sdklib.internal.avd.GpuMode)

Example 5 with GpuMode

use of com.android.sdklib.internal.avd.GpuMode in project android by JetBrains.

the class ConfigureAvdOptionsStep method bindComponents.

private void bindComponents() {
    myBindings.bindTwoWay(new TextProperty(myAvdDisplayName), getModel().avdDisplayName());
    myBindings.bind(new TextProperty(myAvdId), new StringExpression(getModel().avdDisplayName()) {

        @NotNull
        @Override
        public String get() {
            String displayName = getModel().avdDisplayName().get();
            getModel().avdId().set(StringUtil.isNotEmpty(displayName) ? AvdWizardUtils.cleanAvdName(connection, displayName, !displayName.equals(myOriginalName)) : "");
            return getModel().avdId().get();
        }
    });
    myBindings.bindTwoWay(new TextProperty(mySystemImageName), getModel().systemImageName());
    myBindings.bindTwoWay(new TextProperty(mySystemImageDetails), getModel().systemImageDetails());
    myBindings.bindTwoWay(new SelectedProperty(myQemu2CheckBox), getModel().useQemu2());
    myBindings.bindTwoWay(new SelectedItemProperty<Integer>(myCoreCount), getModel().cpuCoreCount());
    myBindings.bindTwoWay(myRamStorage.storage(), getModel().getAvdDeviceData().ramStorage());
    myBindings.bindTwoWay(myVmHeapStorage.storage(), getModel().vmHeapStorage());
    myBindings.bindTwoWay(myInternalStorage.storage(), getModel().internalStorage());
    myBindings.bindTwoWay(myBuiltInSdCardStorage.storage(), new OptionalToValuePropertyAdapter<Storage>(getModel().sdCardStorage()));
    myBindings.bindTwoWay(new SelectedItemProperty<GpuMode>(myHostGraphics), getModel().hostGpuMode());
    myBindings.bindTwoWay(new SelectedProperty(myDeviceFrameCheckbox), getModel().hasDeviceFrame());
    myBindings.bindTwoWay(new SelectedItemProperty<File>(mySkinComboBox.getComboBox()), getModel().getAvdDeviceData().customSkinFile());
    myOrientationToggle.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            ScreenOrientation orientation = myOrientationToggle.getSelectedElement();
            if (orientation == null) {
                getModel().selectedAvdOrientation().set(ScreenOrientation.PORTRAIT);
            } else {
                getModel().selectedAvdOrientation().set(orientation);
            }
        }
    });
    FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(true, false, false, false, false, false) {

        @Override
        public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
            return super.isFileVisible(file, true);
        }
    };
    fileChooserDescriptor.setHideIgnored(false);
    myExternalSdCard.addBrowseFolderListener("Select SD Card", "Select an existing SD card image", myProject, fileChooserDescriptor);
    myBindings.bindTwoWay(new TextProperty(myExternalSdCard.getTextField()), getModel().externalSdCardLocation());
    myBindings.bindTwoWay(new OptionalToValuePropertyAdapter<AvdCamera>(new SelectedItemProperty<AvdCamera>(myFrontCameraCombo)), getModel().selectedFrontCamera());
    myBindings.bindTwoWay(new OptionalToValuePropertyAdapter<AvdCamera>(new SelectedItemProperty<AvdCamera>(myBackCameraCombo)), getModel().selectedBackCamera());
    myBindings.bindTwoWay(new OptionalToValuePropertyAdapter<AvdNetworkSpeed>(new SelectedItemProperty<AvdNetworkSpeed>(mySpeedCombo)), getModel().selectedNetworkSpeed());
    myBindings.bindTwoWay(new OptionalToValuePropertyAdapter<AvdNetworkLatency>(new SelectedItemProperty<AvdNetworkLatency>(myLatencyCombo)), getModel().selectedNetworkLatency());
    myBindings.bindTwoWay(new SelectedProperty(myEnableComputerKeyboard), getModel().enableHardwareKeyboard());
    myBindings.bindTwoWay(new SelectedProperty(myExternalRadioButton), getModel().useExternalSdCard());
    myBindings.bindTwoWay(new SelectedProperty(myBuiltInRadioButton), getModel().useBuiltInSdCard());
    myCheckSdForChanges = true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GpuMode(com.android.sdklib.internal.avd.GpuMode) ListSelectionEvent(javax.swing.event.ListSelectionEvent) NotNull(org.jetbrains.annotations.NotNull) TextProperty(com.android.tools.idea.ui.properties.swing.TextProperty) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) ListSelectionListener(javax.swing.event.ListSelectionListener) ScreenOrientation(com.android.resources.ScreenOrientation) SelectedItemProperty(com.android.tools.idea.ui.properties.swing.SelectedItemProperty) StringExpression(com.android.tools.idea.ui.properties.expressions.string.StringExpression) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) SelectedProperty(com.android.tools.idea.ui.properties.swing.SelectedProperty)

Aggregations

GpuMode (com.android.sdklib.internal.avd.GpuMode)5 ScreenOrientation (com.android.resources.ScreenOrientation)2 File (java.io.File)2 NotNull (org.jetbrains.annotations.NotNull)2 VisibleForTesting (com.android.annotations.VisibleForTesting)1 FileOpUtils (com.android.repository.io.FileOpUtils)1 Density (com.android.resources.Density)1 ScreenSize (com.android.resources.ScreenSize)1 ISystemImage (com.android.sdklib.ISystemImage)1 Device (com.android.sdklib.devices.Device)1 DeviceManager (com.android.sdklib.devices.DeviceManager)1 Storage (com.android.sdklib.devices.Storage)1 AvdInfo (com.android.sdklib.internal.avd.AvdInfo)1 AvdManager (com.android.sdklib.internal.avd.AvdManager)1 HardwareProperties (com.android.sdklib.internal.avd.HardwareProperties)1 com.android.tools.idea.ui.properties.core (com.android.tools.idea.ui.properties.core)1 StringExpression (com.android.tools.idea.ui.properties.expressions.string.StringExpression)1 SelectedItemProperty (com.android.tools.idea.ui.properties.swing.SelectedItemProperty)1 SelectedProperty (com.android.tools.idea.ui.properties.swing.SelectedProperty)1 TextProperty (com.android.tools.idea.ui.properties.swing.TextProperty)1