Search in sources :

Example 6 with AvdInfo

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();
}
Also used : AvdManager(com.android.sdklib.internal.avd.AvdManager) AvdInfo(com.android.sdklib.internal.avd.AvdInfo) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with AvdInfo

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));
}
Also used : AvdManager(com.android.sdklib.internal.avd.AvdManager) IDevice(com.android.ddmlib.IDevice) AvdInfo(com.android.sdklib.internal.avd.AvdInfo) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with AvdInfo

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;
}
Also used : IdDisplay(com.android.sdklib.repository.IdDisplay) LaunchCompatibility(com.android.tools.idea.run.LaunchCompatibility) AvdManager(com.android.sdklib.internal.avd.AvdManager) AvdInfo(com.android.sdklib.internal.avd.AvdInfo) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) Module(com.intellij.openapi.module.Module) AndroidVersion(com.android.sdklib.AndroidVersion) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with AvdInfo

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);
    }
}
Also used : ArrayList(java.util.ArrayList) IDevice(com.android.ddmlib.IDevice) AvdInfo(com.android.sdklib.internal.avd.AvdInfo) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) IdDisplay(com.android.sdklib.repository.IdDisplay) Module(com.intellij.openapi.module.Module) HashSet(com.intellij.util.containers.HashSet) AndroidDebugBridge(com.android.ddmlib.AndroidDebugBridge)

Example 10 with AvdInfo

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

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