Search in sources :

Example 1 with AvdManagerConnection

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());
}
Also used : DetailsTypes(com.android.sdklib.repository.meta.DetailsTypes) ScopedStateStore(com.android.tools.idea.wizard.dynamic.ScopedStateStore) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) RepoFactory(com.android.sdklib.repository.meta.RepoFactory) AvdInfo(com.android.sdklib.internal.avd.AvdInfo) MockFileOp(com.android.repository.testframework.MockFileOp) AvdManagerConnection(com.android.tools.idea.avdmanager.AvdManagerConnection) FakePackage(com.android.repository.testframework.FakePackage) File(java.io.File) RemotePackage(com.android.repository.api.RemotePackage) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 2 with AvdManagerConnection

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;
}
Also used : AvdInfo(com.android.sdklib.internal.avd.AvdInfo) AvdManagerConnection(com.android.tools.idea.avdmanager.AvdManagerConnection) SystemImageDescription(com.android.tools.idea.avdmanager.SystemImageDescription)

Example 3 with AvdManagerConnection

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;
}
Also used : AvdInfo(com.android.sdklib.internal.avd.AvdInfo) AvdManagerConnection(com.android.tools.idea.avdmanager.AvdManagerConnection) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog) AndroidLocation(com.android.prefs.AndroidLocation)

Aggregations

AvdInfo (com.android.sdklib.internal.avd.AvdInfo)3 AvdManagerConnection (com.android.tools.idea.avdmanager.AvdManagerConnection)3 AndroidLocation (com.android.prefs.AndroidLocation)1 RemotePackage (com.android.repository.api.RemotePackage)1 FakePackage (com.android.repository.testframework.FakePackage)1 MockFileOp (com.android.repository.testframework.MockFileOp)1 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)1 DetailsTypes (com.android.sdklib.repository.meta.DetailsTypes)1 RepoFactory (com.android.sdklib.repository.meta.RepoFactory)1 SystemImageDescription (com.android.tools.idea.avdmanager.SystemImageDescription)1 ScopedStateStore (com.android.tools.idea.wizard.dynamic.ScopedStateStore)1 ModelWizardDialog (com.android.tools.idea.wizard.model.ModelWizardDialog)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 File (java.io.File)1 Map (java.util.Map)1