Search in sources :

Example 1 with ISystemImage

use of com.android.sdklib.ISystemImage in project otertool by wuntee.

the class AvdWorkshop method createAvd.

public static AvdInfo createAvd(CreateAvdBean bean) throws AndroidLocationException, IOException, GenericException {
    ISdkLog sdkLogger = AvdWorkshop.getAvdLogger();
    SdkManager sdkManager = SdkManager.createManager(OterStatics.getAndroidHome(), sdkLogger);
    AvdManager avdManager = new AvdManager(sdkManager, sdkLogger);
    File avdFolder = new File(AndroidLocation.getFolder() + "avd", bean.getName() + ".avd");
    //newAvdInfo = avdManager.createAvd(avdFolder, avdName, target, skin, this.mSdkCommandLine.getParamSdCard(), hardwareConfig, removePrevious, this.mSdkCommandLine.getFlagSnapshot(), this.mSdkLog);
    IAndroidTarget target = getAndroidTargetFromString(sdkManager, bean.getTarget());
    ISystemImage[] abiTypes = target.getSystemImages();
    if (abiTypes.length == 0) {
        throw new GenericException("There are no images associated with the target.");
    }
    //ABI = Android Base Image ?
    String abiType = abiTypes[0].getAbiType();
    // /Applications/android-sdk-macosx/system-images/android-15/armeabi-v7a//system.img
    // avdManager.           createAvd(avdFolder, avdName,     avdTarget, ABI, skin, sdCard, hadwareConfig, snapshot, force, false, logger)
    //AvdInfo ret = avdManager.createAvd(avdFolder, bean.getName(),           target,        null,        null,                     null,        false,        false, sdkLogger);
    //                       createAvd(File arg0, String arg1, IAndroidTarget arg2, String arg3, String arg4, Map<String, String> arg5, boolean arg6, boolean arg7, ISdkLog arg8)
    AvdInfo ret = avdManager.createAvd(avdFolder, bean.getName(), target, abiType, null, null, null, false, false, false, sdkLogger);
    if (ret == null) {
        logger.error("There was an error createing AVD, the manager returned a null info object.");
        throw new GenericException("Could not create AVD for an unknown reason.");
    }
    if (bean.isPersistant() == true) {
        makeAvdPersistant(ret);
    }
    return (ret);
}
Also used : AvdManager(com.android.sdklib.internal.avd.AvdManager) SdkManager(com.android.sdklib.SdkManager) AvdInfo(com.android.sdklib.internal.avd.AvdInfo) IAndroidTarget(com.android.sdklib.IAndroidTarget) ISystemImage(com.android.sdklib.ISystemImage) File(java.io.File) GenericException(com.wuntee.oter.exception.GenericException) ISdkLog(com.android.sdklib.ISdkLog)

Example 2 with ISystemImage

use of com.android.sdklib.ISystemImage in project android by JetBrains.

the class AvdManagerConnection method doesSystemImageSupportQemu2.

public static boolean doesSystemImageSupportQemu2(@Nullable SystemImageDescription description, @NotNull FileOp fileOp) {
    if (description == null) {
        return false;
    }
    ISystemImage systemImage = description.getSystemImage();
    if (systemImage == null) {
        return false;
    }
    File location = systemImage.getLocation();
    if (!fileOp.isDirectory(location)) {
        return false;
    }
    String[] files = fileOp.list(location, null);
    if (files != null) {
        for (String filename : files) {
            if (FileUtil.getNameWithoutExtension(filename).equals("kernel-ranchu")) {
                return true;
            }
        }
    }
    return false;
}
Also used : ISystemImage(com.android.sdklib.ISystemImage) File(java.io.File)

Example 3 with ISystemImage

use of com.android.sdklib.ISystemImage in project android by JetBrains.

the class AndroidFacet method addCompatibleAvds.

@NotNull
private AvdInfo[] addCompatibleAvds(@NotNull List<AvdInfo> to, @NotNull AvdInfo[] from) {
    AndroidVersion minSdk = AndroidModuleInfo.get(this).getRuntimeMinSdkVersion();
    AndroidPlatform platform = getConfiguration().getAndroidPlatform();
    if (platform == null) {
        LOG.error("Android Platform not set for module: " + getModule().getName());
        return new AvdInfo[0];
    }
    for (AvdInfo avd : from) {
        ISystemImage systemImage = avd.getSystemImage();
        if (systemImage == null || LaunchCompatibility.canRunOnAvd(minSdk, platform.getTarget(), systemImage).isCompatible() != ThreeState.NO) {
            to.add(avd);
        }
    }
    return to.toArray(new AvdInfo[to.size()]);
}
Also used : AvdInfo(com.android.sdklib.internal.avd.AvdInfo) ISystemImage(com.android.sdklib.ISystemImage) AndroidVersion(com.android.sdklib.AndroidVersion) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with ISystemImage

use of com.android.sdklib.ISystemImage in project otertool by wuntee.

the class AvdWorkshop method makeAvdPersistant.

public static void makeAvdPersistant(AvdInfo info) throws IOException {
    logger.debug("Makeing AVD: " + info.getName() + " persistant.");
    File avdPath = new File(info.getDataFolderPath());
    ISystemImage[] sysImages = null;
    // If target is a platform, copy parents system images first
    if (info.getTarget().isPlatform() == false) {
        for (ISystemImage iSysImg : info.getTarget().getParent().getSystemImages()) {
            File f = new File(iSysImg.getLocation().getAbsoluteFile() + System.getProperty("file.separator") + "system.img");
            FileUtils.copyFileToDirectory(f, avdPath);
        }
    }
    // Copy target system images to local directory
    sysImages = info.getTarget().getSystemImages();
    for (ISystemImage iSysImg : info.getTarget().getSystemImages()) {
        File f = new File(iSysImg.getLocation().getAbsoluteFile() + System.getProperty("file.separator") + "system.img");
        FileUtils.copyFileToDirectory(f, avdPath);
    }
    // If system.img exists, it should be system-qemu.img (http://code.google.com/p/android/issues/detail?id=23684)
    File sysImg = new File(avdPath + System.getProperty("file.separator") + "system.img");
    if (sysImg.exists()) {
        sysImg.renameTo(new File(avdPath + System.getProperty("file.separator") + "system-qemu.img"));
    }
}
Also used : ISystemImage(com.android.sdklib.ISystemImage) File(java.io.File)

Example 5 with ISystemImage

use of com.android.sdklib.ISystemImage 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)

Aggregations

ISystemImage (com.android.sdklib.ISystemImage)8 File (java.io.File)6 Device (com.android.sdklib.devices.Device)3 AvdInfo (com.android.sdklib.internal.avd.AvdInfo)3 ScreenOrientation (com.android.resources.ScreenOrientation)2 IAndroidTarget (com.android.sdklib.IAndroidTarget)2 Storage (com.android.sdklib.devices.Storage)2 AvdManager (com.android.sdklib.internal.avd.AvdManager)2 NotNull (org.jetbrains.annotations.NotNull)2 FileOpUtils (com.android.repository.io.FileOpUtils)1 Density (com.android.resources.Density)1 ScreenSize (com.android.resources.ScreenSize)1 AndroidVersion (com.android.sdklib.AndroidVersion)1 ISdkLog (com.android.sdklib.ISdkLog)1 SdkManager (com.android.sdklib.SdkManager)1 DeviceManager (com.android.sdklib.devices.DeviceManager)1 GpuMode (com.android.sdklib.internal.avd.GpuMode)1 HardwareProperties (com.android.sdklib.internal.avd.HardwareProperties)1 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)1 SystemImageManager (com.android.sdklib.repository.targets.SystemImageManager)1