Search in sources :

Example 21 with AvdInfo

use of com.android.sdklib.internal.avd.AvdInfo in project android by JetBrains.

the class EmulatorTargetChooser method chooseAvd.

@Nullable
private String chooseAvd() {
    IAndroidTarget buildTarget = myFacet.getConfiguration().getAndroidTarget();
    assert buildTarget != null;
    AvdInfo[] avds = myFacet.getValidCompatibleAvds();
    if (avds.length > 0) {
        return avds[0].getName();
    }
    final Project project = myFacet.getModule().getProject();
    AvdManager manager;
    try {
        manager = myFacet.getAvdManager(new AvdManagerLog() {

            @Override
            public void error(Throwable t, String errorFormat, Object... args) {
                super.error(t, errorFormat, args);
                if (errorFormat != null) {
                    final String msg = String.format(errorFormat, args);
                    LOG.error(msg);
                }
            }
        });
    } catch (final AndroidLocation.AndroidLocationException e) {
        LOG.info(e);
        UIUtil.invokeLaterIfNeeded(new Runnable() {

            @Override
            public void run() {
                Messages.showErrorDialog(project, e.getMessage(), CommonBundle.getErrorTitle());
            }
        });
        return null;
    }
    final AvdManager finalManager = manager;
    assert finalManager != null;
    return UIUtil.invokeAndWaitIfNeeded(new Computable<String>() {

        @Override
        public String compute() {
            int result = Messages.showDialog(project, "To run using the emulator, you must have an AVD defined.", "Define AVD", new String[] { "Cancel", "Create AVD" }, 1, null);
            AvdInfo createdAvd = null;
            if (result == 1) {
                AvdOptionsModel avdOptionsModel = new AvdOptionsModel(null);
                ModelWizardDialog dialog = AvdWizardUtils.createAvdWizard(null, project, avdOptionsModel);
                if (dialog.showAndGet()) {
                    createdAvd = avdOptionsModel.getCreatedAvd();
                }
            }
            return createdAvd == null ? null : createdAvd.getName();
        }
    });
}
Also used : AvdManagerLog(org.jetbrains.android.sdk.AvdManagerLog) AvdInfo(com.android.sdklib.internal.avd.AvdInfo) IAndroidTarget(com.android.sdklib.IAndroidTarget) AvdOptionsModel(com.android.tools.idea.avdmanager.AvdOptionsModel) Project(com.intellij.openapi.project.Project) AvdManager(com.android.sdklib.internal.avd.AvdManager) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog) AndroidLocation(com.android.prefs.AndroidLocation) Nullable(org.jetbrains.annotations.Nullable)

Example 22 with AvdInfo

use of com.android.sdklib.internal.avd.AvdInfo in project android by JetBrains.

the class AndroidVirtualDevice method configure.

@Override
public void configure(@NotNull InstallContext installContext, @NotNull AndroidSdkHandler sdkHandler) {
    myProgressStep.getProgressIndicator().setIndeterminate(true);
    myProgressStep.getProgressIndicator().setText("Creating Android virtual device");
    installContext.print("Creating Android virtual device\n", ConsoleViewContentType.SYSTEM_OUTPUT);
    try {
        AvdInfo avd = createAvd(AvdManagerConnection.getAvdManagerConnection(sdkHandler), sdkHandler);
        if (avd == null) {
            throw new WizardException("Unable to create Android virtual device");
        }
        String successMessage = String.format("Android virtual device %s was successfully created\n", avd.getName());
        installContext.print(successMessage, ConsoleViewContentType.SYSTEM_OUTPUT);
    } catch (WizardException e) {
        LOG.error(e);
        String failureMessage = String.format("Unable to create a virtual device: %s\n", e.getMessage());
        installContext.print(failureMessage, ConsoleViewContentType.ERROR_OUTPUT);
    }
}
Also used : AvdInfo(com.android.sdklib.internal.avd.AvdInfo)

Example 23 with AvdInfo

use of com.android.sdklib.internal.avd.AvdInfo in project android by JetBrains.

the class DevicePickerListModelTest method testRunningAvdsAreNotDuplicated.

@Test
public void testRunningAvdsAreNotDuplicated() {
    IDevice device = createMockDevice(false, null, 23, "6.0");
    IDevice runningAvd = createMockDevice(true, "emu1", 22, "5.0");
    AvdInfo emu1Info = createMockAvd("emu1");
    AvdInfo emu2Info = createMockAvd("emu2");
    myModel.reset(Arrays.asList(device, runningAvd), Arrays.asList(emu1Info, emu2Info));
    List<DevicePickerEntry> items = myModel.getItems();
    assertEquals("Expected 5 items (marker, 2 devices, marker, 1 avd info)", 5, items.size());
    assertEquals("emu2", items.get(4).getAndroidDevice().getName());
}
Also used : IDevice(com.android.ddmlib.IDevice) AvdInfo(com.android.sdklib.internal.avd.AvdInfo) Test(org.junit.Test)

Example 24 with AvdInfo

use of com.android.sdklib.internal.avd.AvdInfo in project android by JetBrains.

the class DeviceSelectionPopup method findMatchingAvd.

/**
   * Find a avd matching the image size or ratio.
   *
   * @param configurationManager configuration managet to get the Android Facet
   * @param imageRatio           ratio of the imgage
   * @return true if a matching avd has been found
   */
private boolean findMatchingAvd(ConfigurationManager configurationManager, double imageRatio) {
    AndroidFacet facet = AndroidFacet.getInstance(configurationManager.getModule());
    if (facet == null) {
        // Unlikely, but has happened - see http://b.android.com/68091
        return false;
    }
    final AvdManager avdManager = facet.getAvdManagerSilently();
    if (avdManager != null) {
        final AvdInfo[] allAvds = avdManager.getAllAvds();
        for (AvdInfo avd : allAvds) {
            Device device = configurationManager.createDeviceForAvd(avd);
            if (device != null) {
                final Dimension screenSize = device.getScreenSize(myScreenOrientation);
                if (myImageSize.equals(screenSize) || ratioAlmostEqual(imageRatio, screenSize)) {
                    String avdName = "AVD: " + avd.getName();
                    myDevicesComboBox.addItem(avdName);
                    myMatchingDevices.add(device);
                }
            }
        }
    }
    return !myMatchingDevices.isEmpty();
}
Also used : AvdManager(com.android.sdklib.internal.avd.AvdManager) Device(com.android.sdklib.devices.Device) AvdInfo(com.android.sdklib.internal.avd.AvdInfo) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 25 with AvdInfo

use of com.android.sdklib.internal.avd.AvdInfo in project otertool by wuntee.

the class AvdWorkshop method isAvdExist.

public static boolean isAvdExist(String avd) throws AndroidLocationException {
    ISdkLog sdkLogger = AvdWorkshop.getAvdLogger();
    SdkManager sdkManager = SdkManager.createManager(OterStatics.getAndroidHome(), sdkLogger);
    AvdManager avdManager = new AvdManager(sdkManager, sdkLogger);
    for (AvdInfo i : avdManager.getAllAvds()) {
        if (i.getName().equals(avd)) {
            return (true);
        }
    }
    return (false);
}
Also used : AvdManager(com.android.sdklib.internal.avd.AvdManager) SdkManager(com.android.sdklib.SdkManager) AvdInfo(com.android.sdklib.internal.avd.AvdInfo) ISdkLog(com.android.sdklib.ISdkLog)

Aggregations

AvdInfo (com.android.sdklib.internal.avd.AvdInfo)25 AvdManager (com.android.sdklib.internal.avd.AvdManager)9 NotNull (org.jetbrains.annotations.NotNull)5 IDevice (com.android.ddmlib.IDevice)4 File (java.io.File)4 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)4 AndroidLocation (com.android.prefs.AndroidLocation)3 AndroidVersion (com.android.sdklib.AndroidVersion)3 AvdManagerConnection (com.android.tools.idea.avdmanager.AvdManagerConnection)3 ModelWizardDialog (com.android.tools.idea.wizard.model.ModelWizardDialog)3 Nullable (org.jetbrains.annotations.Nullable)3 IAndroidTarget (com.android.sdklib.IAndroidTarget)2 ISdkLog (com.android.sdklib.ISdkLog)2 ISystemImage (com.android.sdklib.ISystemImage)2 SdkManager (com.android.sdklib.SdkManager)2 Device (com.android.sdklib.devices.Device)2 IdDisplay (com.android.sdklib.repository.IdDisplay)2 Module (com.intellij.openapi.module.Module)2 Map (java.util.Map)2 AndroidDebugBridge (com.android.ddmlib.AndroidDebugBridge)1