use of com.android.sdklib.internal.avd.AvdManager 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);
}
use of com.android.sdklib.internal.avd.AvdManager in project android by JetBrains.
the class EmulatorTargetChooser method validate.
@NotNull
public List<ValidationError> validate() {
if (myAvd == null) {
return ImmutableList.of();
}
AvdManager avdManager = myFacet.getAvdManagerSilently();
if (avdManager == null) {
return ImmutableList.of(ValidationError.fatal(AndroidBundle.message("avd.cannot.be.loaded.error")));
}
AvdInfo avdInfo = avdManager.getAvd(myAvd, false);
if (avdInfo == null) {
return ImmutableList.of(ValidationError.fatal(AndroidBundle.message("avd.not.found.error", myAvd)));
}
if (avdInfo.getStatus() != AvdInfo.AvdStatus.OK) {
String message = avdInfo.getErrorMessage();
message = AndroidBundle.message("avd.not.valid.error", myAvd) + (message != null ? ": " + message : "") + ". Try to repair it through AVD manager";
return ImmutableList.of(ValidationError.fatal(message));
}
return ImmutableList.of();
}
use of com.android.sdklib.internal.avd.AvdManager in project android by JetBrains.
the class EmulatorTargetChooser method getDevices.
@Nullable
public DeviceFutures getDevices(@NotNull DeviceCount deviceCount) {
TargetDeviceFilter deviceFilter = new TargetDeviceFilter.EmulatorFilter(myFacet, myAvd);
Collection<IDevice> runningDevices = DeviceSelectionUtils.chooseRunningDevice(myFacet, deviceFilter, deviceCount);
if (runningDevices == null) {
// The user canceled.
return null;
}
if (!runningDevices.isEmpty()) {
return DeviceFutures.forDevices(runningDevices);
}
// We need to launch an emulator.
final String avd = myAvd != null ? myAvd : chooseAvd();
if (avd == null) {
// The user canceled.
return null;
}
AvdManager manager = myFacet.getAvdManagerSilently();
if (manager == null) {
LOG.warn("Could not obtain AVD Manager.");
return null;
}
AvdInfo avdInfo = manager.getAvd(avd, true);
if (avdInfo == null) {
LOG.warn("Unable to obtain info for AVD: " + avd);
return null;
}
LaunchableAndroidDevice androidDevice = new LaunchableAndroidDevice(avdInfo);
// LAUNCH EMULATOR
androidDevice.launch(myFacet.getModule().getProject());
return new DeviceFutures(Collections.<AndroidDevice>singletonList(androidDevice));
}
use of com.android.sdklib.internal.avd.AvdManager in project android by JetBrains.
the class EmulatorTargetConfigurable method getAvdCompatibilityWarning.
@Nullable
private String getAvdCompatibilityWarning() {
IdDisplay selectedItem = (IdDisplay) myAvdCombo.getComboBox().getSelectedItem();
if (selectedItem != null) {
final String selectedAvdName = selectedItem.getId();
final Module module = myContext.getModule();
if (module == null) {
return null;
}
final AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet == null) {
return null;
}
final AvdManager avdManager = facet.getAvdManagerSilently();
if (avdManager == null) {
return null;
}
final AvdInfo avd = avdManager.getAvd(selectedAvdName, false);
if (avd == null || avd.getSystemImage() == null) {
return null;
}
AndroidPlatform platform = facet.getConfiguration().getAndroidPlatform();
if (platform == null) {
return null;
}
AndroidVersion minSdk = AndroidModuleInfo.get(facet).getRuntimeMinSdkVersion();
LaunchCompatibility compatibility = LaunchCompatibility.canRunOnAvd(minSdk, platform.getTarget(), avd.getSystemImage());
if (compatibility.isCompatible() == ThreeState.NO) {
// todo: provide info about current module configuration
return String.format("'%1$s' may be incompatible with your configuration (%2$s)", selectedAvdName, StringUtil.notNullize(compatibility.getReason()));
}
}
return null;
}
use of com.android.sdklib.internal.avd.AvdManager in project android by JetBrains.
the class DeviceMenuAction method createPopupActionGroup.
@Override
@NotNull
protected DefaultActionGroup createPopupActionGroup() {
DefaultActionGroup group = new DefaultActionGroup(null, true);
Configuration configuration = myRenderContext.getConfiguration();
if (configuration == null) {
return group;
}
Device current = configuration.getDevice();
ConfigurationManager configurationManager = configuration.getConfigurationManager();
List<Device> deviceList = configurationManager.getDevices();
if (LIST_RECENT_DEVICES) {
List<Device> recent = configurationManager.getDevices();
if (recent.size() > 1) {
boolean separatorNeeded = false;
for (Device device : recent) {
String label = getLabel(device, isNexus(device));
Icon icon = getDeviceClassIcon(device);
group.add(new SetDeviceAction(myRenderContext, label, device, icon, device == current));
separatorNeeded = true;
}
if (separatorNeeded) {
group.addSeparator();
}
}
}
AndroidFacet facet = AndroidFacet.getInstance(configurationManager.getModule());
if (facet == null) {
// Unlikely, but has happened - see http://b.android.com/68091
return group;
}
if (!deviceList.isEmpty()) {
Map<String, List<Device>> manufacturers = new TreeMap<>();
for (Device device : deviceList) {
List<Device> devices;
if (manufacturers.containsKey(device.getManufacturer())) {
devices = manufacturers.get(device.getManufacturer());
} else {
devices = new ArrayList<>();
manufacturers.put(device.getManufacturer(), devices);
}
devices.add(device);
}
List<Device> nexus = new ArrayList<>();
Map<FormFactor, List<Device>> deviceMap = Maps.newEnumMap(FormFactor.class);
for (FormFactor factor : FormFactor.values()) {
deviceMap.put(factor, Lists.newArrayList());
}
for (List<Device> devices : manufacturers.values()) {
for (Device device : devices) {
if (isNexus(device) && !device.getManufacturer().equals(MANUFACTURER_GENERIC) && !isWear(device) && !isTv(device)) {
nexus.add(device);
} else {
deviceMap.get(FormFactor.getFormFactor(device)).add(device);
}
}
}
sortDevicesByScreenSize(nexus);
for (List<Device> list : splitDevicesByScreenSize(nexus)) {
addNexusDeviceSection(group, current, list);
group.addSeparator();
}
addDeviceSection(group, current, deviceMap, false, FormFactor.WEAR);
group.addSeparator();
addDeviceSection(group, current, deviceMap, false, FormFactor.TV);
group.addSeparator();
final AvdManager avdManager = facet.getAvdManagerSilently();
if (avdManager != null) {
boolean separatorNeeded = false;
boolean first = true;
for (AvdInfo avd : avdManager.getValidAvds()) {
Device device = configurationManager.createDeviceForAvd(avd);
if (device != null) {
String avdName = "AVD: " + avd.getName();
boolean selected = current != null && (current.getDisplayName().equals(avdName) || current.getId().equals(avdName));
Icon icon = first ? getDeviceClassIcon(device) : null;
group.add(new SetDeviceAction(myRenderContext, avdName, device, icon, selected));
first = false;
separatorNeeded = true;
}
}
if (separatorNeeded) {
group.addSeparator();
}
}
DefaultActionGroup genericGroup = new DefaultActionGroup("_Generic Phones and Tablets", true);
sortDevicesByScreenSize(deviceMap.get(FormFactor.MOBILE));
addDeviceSection(genericGroup, current, deviceMap, true, FormFactor.MOBILE);
group.add(genericGroup);
}
group.add(new RunAndroidAvdManagerAction("Add Device Definition..."));
return group;
}
Aggregations