use of com.android.tools.idea.avdmanager.AvdManagerConnection in project android by JetBrains.
the class AndroidVirtualDeviceTest method testCreateDevice.
public void testCreateDevice() throws Exception {
MockFileOp fop = new MockFileOp();
recordPlatform23(fop);
recordGoogleApisAddon23(fop);
recordGoogleApisSysImg23(fop);
fop.recordExistingFile(new File(DeviceArtDescriptor.getBundledDescriptorsFolder(), "nexus_5x"));
AndroidSdkHandler sdkHandler = new AndroidSdkHandler(new File("/sdk"), new File("/android-home"), fop);
final AvdManagerConnection connection = new AvdManagerConnection(sdkHandler);
FakePackage.FakeRemotePackage remotePlatform = new FakePackage.FakeRemotePackage("platforms;android-23");
RepoFactory factory = AndroidSdkHandler.getRepositoryModule().createLatestFactory();
DetailsTypes.PlatformDetailsType platformDetailsType = factory.createPlatformDetailsType();
platformDetailsType.setApiLevel(23);
remotePlatform.setTypeDetails((TypeDetails) platformDetailsType);
Map<String, RemotePackage> remotes = Maps.newHashMap();
remotes.put("platforms;android-23", remotePlatform);
AndroidVirtualDevice avd = new AndroidVirtualDevice(new ScopedStateStore(ScopedStateStore.Scope.STEP, null, null), remotes, true, fop);
final AvdInfo avdInfo = avd.createAvd(connection, sdkHandler);
assertNotNull(avdInfo);
disposeOnTearDown(() -> connection.deleteAvd(avdInfo));
assertNotNull(avdInfo);
Map<String, String> properties = avdInfo.getProperties();
Map<String, String> referenceMap = getReferenceMap();
for (Map.Entry<String, String> entry : referenceMap.entrySet()) {
assertEquals(entry.getKey(), entry.getValue(), FileUtil.toSystemIndependentName(properties.get(entry.getKey())));
}
// AVD manager will set some extra properties that we don't care about and that may be system dependant.
// We do not care about those so we only ensure we have the ones we need.
File skin = new File(properties.get(AvdManager.AVD_INI_SKIN_PATH));
assertEquals("nexus_5x", skin.getName());
}
use of com.android.tools.idea.avdmanager.AvdManagerConnection 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;
}
use of com.android.tools.idea.avdmanager.AvdManagerConnection in project android by JetBrains.
the class DeployTargetPickerDialog method canLaunchDevices.
/**
* Check the AVDs for missing system images and offer to download them.
* @return true if the devices are able to launch, false if the user cancelled.
*/
private boolean canLaunchDevices(@NotNull List<AndroidDevice> devices) {
Set<String> requiredPackages = Sets.newHashSet();
for (AndroidDevice device : devices) {
if (device instanceof LaunchableAndroidDevice) {
LaunchableAndroidDevice avd = (LaunchableAndroidDevice) device;
AvdInfo info = avd.getAvdInfo();
if (AvdManagerConnection.isSystemImageDownloadProblem(info.getStatus())) {
requiredPackages.add(AvdManagerConnection.getRequiredSystemImagePath(info));
}
}
}
if (requiredPackages.isEmpty()) {
return true;
}
String title;
StringBuilder message = new StringBuilder();
if (requiredPackages.size() == 1) {
title = "Download System Image";
message.append("The system image: ").append(Iterables.getOnlyElement(requiredPackages)).append(" is missing.\n\n");
message.append("Download it now?");
} else {
title = "Download System Images";
message.append("The following system images are missing:\n");
for (String packageName : requiredPackages) {
message.append(packageName).append("\n");
}
message.append("\nDownload them now?");
}
int response = Messages.showOkCancelDialog(message.toString(), title, Messages.getQuestionIcon());
if (response != Messages.OK) {
return false;
}
ModelWizardDialog sdkQuickfixWizard = SdkQuickfixUtils.createDialogForPaths(myFacet.getModule().getProject(), requiredPackages);
if (sdkQuickfixWizard == null) {
return false;
}
sdkQuickfixWizard.show();
myDevicePicker.refreshAvds(null);
if (!sdkQuickfixWizard.isOK()) {
return false;
}
AvdManagerConnection manager = AvdManagerConnection.getDefaultAvdManagerConnection();
for (AndroidDevice device : devices) {
if (device instanceof LaunchableAndroidDevice) {
LaunchableAndroidDevice avd = (LaunchableAndroidDevice) device;
AvdInfo info = avd.getAvdInfo();
String problem;
try {
AvdInfo reloadedAvdInfo = manager.reloadAvd(info);
problem = reloadedAvdInfo.getErrorMessage();
} catch (AndroidLocation.AndroidLocationException e) {
problem = "AVD cannot be loaded";
}
if (problem != null) {
Messages.showErrorDialog(myFacet.getModule().getProject(), problem, "Emulator Launch Failed");
return false;
}
}
}
return true;
}
Aggregations