use of com.android.sdklib.devices.Storage in project android by JetBrains.
the class AvdOptionsModel method calculateInitialVmHeap.
/**
* Set the initial VM heap size. This is based on the Android CDD minimums for each screen size and density.
*/
@NotNull
private static Storage calculateInitialVmHeap(@NotNull AvdDeviceData deviceData) {
ScreenSize size = AvdScreenData.getScreenSize(deviceData.diagonalScreenSize().get());
Density density = AvdScreenData.getScreenDensity(deviceData.isTv().get(), deviceData.screenDpi().get(), deviceData.screenResolutionHeight().get());
int vmHeapSize = 32;
if (deviceData.isWear().get()) {
switch(density) {
case LOW:
case ANYDPI:
case NODPI:
case MEDIUM:
case TV:
vmHeapSize = 32;
break;
case HIGH:
case DPI_280:
vmHeapSize = 36;
break;
case XHIGH:
case DPI_360:
vmHeapSize = 48;
break;
case DPI_400:
vmHeapSize = 56;
break;
case DPI_420:
vmHeapSize = 64;
break;
case XXHIGH:
vmHeapSize = 88;
break;
case DPI_560:
vmHeapSize = 112;
break;
case XXXHIGH:
vmHeapSize = 154;
break;
}
} else {
switch(size) {
case SMALL:
case NORMAL:
switch(density) {
case LOW:
case ANYDPI:
case NODPI:
case MEDIUM:
vmHeapSize = 32;
break;
case TV:
case HIGH:
case DPI_280:
vmHeapSize = 48;
break;
case XHIGH:
case DPI_360:
vmHeapSize = 80;
break;
case DPI_400:
vmHeapSize = 96;
break;
case DPI_420:
vmHeapSize = 112;
break;
case XXHIGH:
vmHeapSize = 128;
break;
case DPI_560:
vmHeapSize = 192;
break;
case XXXHIGH:
vmHeapSize = 256;
break;
}
break;
case LARGE:
switch(density) {
case LOW:
vmHeapSize = 32;
break;
case ANYDPI:
case NODPI:
case MEDIUM:
vmHeapSize = 48;
break;
case TV:
case HIGH:
vmHeapSize = 80;
break;
case DPI_280:
vmHeapSize = 96;
break;
case XHIGH:
vmHeapSize = 128;
break;
case DPI_360:
vmHeapSize = 160;
break;
case DPI_400:
vmHeapSize = 192;
break;
case DPI_420:
vmHeapSize = 228;
break;
case XXHIGH:
vmHeapSize = 256;
break;
case DPI_560:
vmHeapSize = 384;
break;
case XXXHIGH:
vmHeapSize = 512;
break;
}
break;
case XLARGE:
switch(density) {
case LOW:
vmHeapSize = 48;
break;
case ANYDPI:
case NODPI:
case MEDIUM:
vmHeapSize = 80;
break;
case TV:
case HIGH:
vmHeapSize = 96;
break;
case DPI_280:
vmHeapSize = 144;
break;
case XHIGH:
vmHeapSize = 192;
break;
case DPI_360:
vmHeapSize = 240;
break;
case DPI_400:
vmHeapSize = 288;
break;
case DPI_420:
vmHeapSize = 336;
break;
case XXHIGH:
vmHeapSize = 384;
break;
case DPI_560:
vmHeapSize = 576;
break;
case XXXHIGH:
vmHeapSize = 768;
break;
}
break;
}
}
return new Storage(vmHeapSize, Storage.Unit.MiB);
}
use of com.android.sdklib.devices.Storage 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());
}
}
use of com.android.sdklib.devices.Storage 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);
}
use of com.android.sdklib.devices.Storage in project android by JetBrains.
the class StorageField method updateStorage.
private void updateStorage() {
String text = myValueField.getText();
Storage storage;
if (text != null) {
try {
Double valueAsUnits = Double.parseDouble(text);
storage = new Storage(valueAsUnits.longValue(), myCurrentUnit);
} catch (NumberFormatException ex) {
storage = new Storage(0, DEFAULT_UNIT);
myValueField.setText("0");
myUnitsCombo.setSelectedItem(DEFAULT_UNIT);
}
myStorage.set(storage);
}
}
Aggregations