use of com.android.sdklib.internal.avd.AvdInfo 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.AvdInfo 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.AvdInfo 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.AvdInfo in project android by JetBrains.
the class AvdComboBox method doUpdateAvds.
private void doUpdateAvds() {
final Module module = getModule();
if (module == null || module.isDisposed()) {
return;
}
final AndroidFacet facet = AndroidFacet.getInstance(module);
final IdDisplay[] newAvds;
if (facet != null) {
final Set<String> filteringSet = new HashSet<String>();
if (myShowNotLaunchedOnly) {
final AndroidDebugBridge debugBridge = AndroidSdkUtils.getDebugBridge(facet.getModule().getProject());
if (debugBridge != null) {
for (IDevice device : debugBridge.getDevices()) {
final String avdName = device.getAvdName();
if (avdName != null && avdName.length() > 0) {
filteringSet.add(avdName);
}
}
}
}
final List<IdDisplay> newAvdList = new ArrayList<IdDisplay>();
if (myAddEmptyElement) {
newAvdList.add(IdDisplay.create("", ""));
}
for (AvdInfo avd : facet.getAllAvds()) {
String displayName = avd.getProperties().get(AvdManager.AVD_INI_DISPLAY_NAME);
final String avdName = displayName == null || displayName.isEmpty() ? avd.getName() : displayName;
if (!filteringSet.contains(avdName)) {
newAvdList.add(IdDisplay.create(avd.getName(), avdName));
}
}
newAvds = ArrayUtil.toObjectArray(newAvdList, IdDisplay.class);
} else {
newAvds = new IdDisplay[0];
}
if (!Arrays.equals(myOldAvds, newAvds)) {
myOldAvds = newAvds;
final Object selected = getComboBox().getSelectedItem();
getComboBox().setModel(new DefaultComboBoxModel(newAvds));
getComboBox().setSelectedItem(selected);
}
}
use of com.android.sdklib.internal.avd.AvdInfo in project android by JetBrains.
the class AndroidVirtualDevice method isSelectedByDefault.
@Override
protected boolean isSelectedByDefault() {
if (mySdkHandler == null) {
return false;
}
SystemImageDescription desired;
try {
desired = getSystemImageDescription(mySdkHandler);
} catch (WizardException e) {
// ignore, error will be shown during configure if they opt to try to create.
return false;
}
AvdManagerConnection connection = AvdManagerConnection.getAvdManagerConnection(mySdkHandler);
List<AvdInfo> avds = connection.getAvds(false);
for (AvdInfo avd : avds) {
if (avd.getAbiType().equals(desired.getAbiType()) && avd.getAndroidVersion().equals(desired.getVersion())) {
// We have a similar avd already installed. Deselect by default.
return false;
}
}
return true;
}
Aggregations