Search in sources :

Example 6 with ISystemImage

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

the class AvdOptionsModel method updateValuesWithAvdInfo.

private void updateValuesWithAvdInfo(@NotNull AvdInfo avdInfo) {
    List<Device> devices = DeviceManagerConnection.getDefaultDeviceManagerConnection().getDevices();
    Device selectedDevice = null;
    String manufacturer = avdInfo.getDeviceManufacturer();
    String deviceId = avdInfo.getProperties().get(AvdManager.AVD_INI_DEVICE_NAME);
    for (Device device : devices) {
        if (manufacturer.equals(device.getManufacturer()) && deviceId.equals(device.getId())) {
            selectedDevice = device;
            break;
        }
    }
    myDevice.setNullableValue(selectedDevice);
    SystemImageDescription systemImageDescription = null;
    ISystemImage selectedImage = avdInfo.getSystemImage();
    if (selectedImage != null) {
        systemImageDescription = new SystemImageDescription(selectedImage);
        mySystemImage.setValue(systemImageDescription);
    }
    myAvdDeviceData = new AvdDeviceData(selectedDevice, systemImageDescription);
    Map<String, String> properties = avdInfo.getProperties();
    myUseQemu2.set(properties.containsKey(AvdWizardUtils.CPU_CORES_KEY));
    String cpuCoreCount = properties.get(AvdWizardUtils.CPU_CORES_KEY);
    myCpuCoreCount.setValue(cpuCoreCount == null ? 1 : Integer.parseInt(cpuCoreCount));
    Storage storage = getStorageFromIni(properties.get(AvdWizardUtils.RAM_STORAGE_KEY));
    if (storage != null) {
        myAvdDeviceData.ramStorage().set(storage);
    }
    storage = getStorageFromIni(properties.get(AvdWizardUtils.VM_HEAP_STORAGE_KEY));
    if (storage != null) {
        myVmHeapStorage.set(storage);
    }
    storage = getStorageFromIni(properties.get(AvdWizardUtils.INTERNAL_STORAGE_KEY));
    if (storage != null) {
        myInternalStorage.set(storage);
    }
    String sdCardLocation = null;
    if (properties.get(AvdWizardUtils.EXISTING_SD_LOCATION) != null) {
        sdCardLocation = properties.get(AvdWizardUtils.EXISTING_SD_LOCATION);
    } else if (properties.get(AvdWizardUtils.SD_CARD_STORAGE_KEY) != null) {
        sdCardLocation = FileUtil.join(avdInfo.getDataFolderPath(), "sdcard.img");
    }
    existingSdLocation = new StringValueProperty(nullToEmpty(sdCardLocation));
    String dataFolderPath = avdInfo.getDataFolderPath();
    File sdLocationFile = null;
    if (sdCardLocation != null) {
        sdLocationFile = new File(sdCardLocation);
    }
    if (sdLocationFile != null) {
        if (Objects.equal(sdLocationFile.getParent(), dataFolderPath)) {
            // the image is in the AVD folder, consider it to be internal
            File sdFile = new File(sdCardLocation);
            Storage sdCardSize = new Storage(sdFile.length());
            myUseExternalSdCard.set(false);
            myUseBuiltInSdCard.set(true);
            myOriginalSdCard = new ObjectValueProperty<>(sdCardSize);
            mySdCardStorage.setValue(sdCardSize);
        } else {
            // the image is external
            myUseExternalSdCard.set(true);
            myUseBuiltInSdCard.set(false);
            externalSdCardLocation().set(sdCardLocation);
        }
    }
    myUseHostGpu.set(fromIniString(properties.get(AvdWizardUtils.USE_HOST_GPU_KEY)));
    mySelectedAvdFrontCamera.set(AvdCamera.fromName(properties.get(AvdWizardUtils.FRONT_CAMERA_KEY)));
    mySelectedAvdBackCamera.set(AvdCamera.fromName(properties.get(AvdWizardUtils.BACK_CAMERA_KEY)));
    mySelectedNetworkLatency.set(AvdNetworkLatency.fromName(properties.get(AvdWizardUtils.NETWORK_LATENCY_KEY)));
    mySelectedNetworkSpeed.set(AvdNetworkSpeed.fromName(properties.get(AvdWizardUtils.NETWORK_SPEED_KEY)));
    myEnableHardwareKeyboard.set(fromIniString(properties.get(AvdWizardUtils.HAS_HARDWARE_KEYBOARD_KEY)));
    myAvdDisplayName.set(AvdManagerConnection.getAvdDisplayName(avdInfo));
    myHasDeviceFrame.set(fromIniString(properties.get(AvdWizardUtils.DEVICE_FRAME_KEY)));
    ScreenOrientation screenOrientation = null;
    String orientation = properties.get(HardwareProperties.HW_INITIAL_ORIENTATION);
    if (!Strings.isNullOrEmpty(orientation)) {
        screenOrientation = ScreenOrientation.getByShortDisplayName(orientation);
    }
    mySelectedAvdOrientation.set((screenOrientation == null) ? ScreenOrientation.PORTRAIT : screenOrientation);
    String skinPath = properties.get(AvdWizardUtils.CUSTOM_SKIN_FILE_KEY);
    if (skinPath != null) {
        File skinFile = (skinPath.equals(AvdWizardUtils.NO_SKIN.getPath())) ? AvdWizardUtils.NO_SKIN : new File(skinPath);
        if (skinFile.isDirectory()) {
            myAvdDeviceData.customSkinFile().setValue(skinFile);
        }
    }
    String backupSkinPath = properties.get(AvdWizardUtils.BACKUP_SKIN_FILE_KEY);
    if (backupSkinPath != null) {
        File skinFile = new File(backupSkinPath);
        if (skinFile.isDirectory() || FileUtil.filesEqual(skinFile, AvdWizardUtils.NO_SKIN)) {
            backupSkinFile().setValue(skinFile);
        }
    }
    String modeString = properties.get(AvdWizardUtils.HOST_GPU_MODE_KEY);
    myHostGpuMode.setValue(GpuMode.fromGpuSetting(modeString));
    myIsInEditMode.set(true);
}
Also used : ScreenOrientation(com.android.resources.ScreenOrientation) Storage(com.android.sdklib.devices.Storage) Device(com.android.sdklib.devices.Device) ISystemImage(com.android.sdklib.ISystemImage) File(java.io.File)

Example 7 with ISystemImage

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

the class SystemImageListModel method getLocalImages.

private List<SystemImageDescription> getLocalImages() {
    SystemImageManager systemImageManager = mySdkHandler.getSystemImageManager(LOGGER);
    List<SystemImageDescription> items = Lists.newArrayList();
    for (ISystemImage image : systemImageManager.getImages()) {
        SystemImageDescription desc = new SystemImageDescription(image);
        items.add(desc);
    }
    return items;
}
Also used : SystemImageManager(com.android.sdklib.repository.targets.SystemImageManager) ISystemImage(com.android.sdklib.ISystemImage)

Example 8 with ISystemImage

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

the class SkinChooser method getSkins.

private List<File> getSkins() {
    List<Device> devices = DeviceManagerConnection.getDefaultDeviceManagerConnection().getDevices();
    Set<File> result = Sets.newTreeSet();
    for (Device device : devices) {
        File skinFile = AvdWizardUtils.resolveSkinPath(device.getDefaultHardware().getSkinFile(), null, FileOpUtils.create());
        if (skinFile != null && skinFile.exists()) {
            result.add(skinFile);
        }
    }
    StudioLoggerProgressIndicator progress = new StudioLoggerProgressIndicator(SkinChooser.class);
    AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
    for (IAndroidTarget target : sdkHandler.getAndroidTargetManager(progress).getTargets(progress)) {
        Arrays.stream(target.getSkins()).map(this::resolve).forEach(result::add);
    }
    for (ISystemImage img : sdkHandler.getSystemImageManager(progress).getImages()) {
        Arrays.stream(img.getSkins()).map(this::resolve).forEach(result::add);
    }
    List<File> resultList = Lists.newArrayList();
    resultList.add(NO_SKIN);
    resultList.addAll(result);
    return resultList;
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) Device(com.android.sdklib.devices.Device) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) IAndroidTarget(com.android.sdklib.IAndroidTarget) 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