Search in sources :

Example 11 with AvdInfo

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

the class AvdDisplayListTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    myAvdInfo = new AvdInfo("name", new File("ini"), "folder", null, myPropertiesMap);
}
Also used : AvdInfo(com.android.sdklib.internal.avd.AvdInfo) File(java.io.File)

Example 12 with AvdInfo

use of com.android.sdklib.internal.avd.AvdInfo 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 13 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)

Example 14 with AvdInfo

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

the class DeviceMenuAction method createPopupActionGroup.

@Override
@NotNull
protected DefaultActionGroup createPopupActionGroup() {
    DefaultActionGroup group = new DefaultActionGroup(null, true);
    Configuration configuration = myRenderContext.getConfiguration();
    if (configuration == null) {
        return group;
    }
    Device current = configuration.getDevice();
    ConfigurationManager configurationManager = configuration.getConfigurationManager();
    List<Device> deviceList = configurationManager.getDevices();
    if (LIST_RECENT_DEVICES) {
        List<Device> recent = configurationManager.getDevices();
        if (recent.size() > 1) {
            boolean separatorNeeded = false;
            for (Device device : recent) {
                String label = getLabel(device, isNexus(device));
                Icon icon = getDeviceClassIcon(device);
                group.add(new SetDeviceAction(myRenderContext, label, device, icon, device == current));
                separatorNeeded = true;
            }
            if (separatorNeeded) {
                group.addSeparator();
            }
        }
    }
    AndroidFacet facet = AndroidFacet.getInstance(configurationManager.getModule());
    if (facet == null) {
        // Unlikely, but has happened - see http://b.android.com/68091
        return group;
    }
    if (!deviceList.isEmpty()) {
        Map<String, List<Device>> manufacturers = new TreeMap<>();
        for (Device device : deviceList) {
            List<Device> devices;
            if (manufacturers.containsKey(device.getManufacturer())) {
                devices = manufacturers.get(device.getManufacturer());
            } else {
                devices = new ArrayList<>();
                manufacturers.put(device.getManufacturer(), devices);
            }
            devices.add(device);
        }
        List<Device> nexus = new ArrayList<>();
        Map<FormFactor, List<Device>> deviceMap = Maps.newEnumMap(FormFactor.class);
        for (FormFactor factor : FormFactor.values()) {
            deviceMap.put(factor, Lists.newArrayList());
        }
        for (List<Device> devices : manufacturers.values()) {
            for (Device device : devices) {
                if (isNexus(device) && !device.getManufacturer().equals(MANUFACTURER_GENERIC) && !isWear(device) && !isTv(device)) {
                    nexus.add(device);
                } else {
                    deviceMap.get(FormFactor.getFormFactor(device)).add(device);
                }
            }
        }
        sortDevicesByScreenSize(nexus);
        for (List<Device> list : splitDevicesByScreenSize(nexus)) {
            addNexusDeviceSection(group, current, list);
            group.addSeparator();
        }
        addDeviceSection(group, current, deviceMap, false, FormFactor.WEAR);
        group.addSeparator();
        addDeviceSection(group, current, deviceMap, false, FormFactor.TV);
        group.addSeparator();
        final AvdManager avdManager = facet.getAvdManagerSilently();
        if (avdManager != null) {
            boolean separatorNeeded = false;
            boolean first = true;
            for (AvdInfo avd : avdManager.getValidAvds()) {
                Device device = configurationManager.createDeviceForAvd(avd);
                if (device != null) {
                    String avdName = "AVD: " + avd.getName();
                    boolean selected = current != null && (current.getDisplayName().equals(avdName) || current.getId().equals(avdName));
                    Icon icon = first ? getDeviceClassIcon(device) : null;
                    group.add(new SetDeviceAction(myRenderContext, avdName, device, icon, selected));
                    first = false;
                    separatorNeeded = true;
                }
            }
            if (separatorNeeded) {
                group.addSeparator();
            }
        }
        DefaultActionGroup genericGroup = new DefaultActionGroup("_Generic Phones and Tablets", true);
        sortDevicesByScreenSize(deviceMap.get(FormFactor.MOBILE));
        addDeviceSection(genericGroup, current, deviceMap, true, FormFactor.MOBILE);
        group.add(genericGroup);
    }
    group.add(new RunAndroidAvdManagerAction("Add Device Definition..."));
    return group;
}
Also used : Device(com.android.sdklib.devices.Device) AvdInfo(com.android.sdklib.internal.avd.AvdInfo) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) FormFactor(com.android.tools.idea.npw.FormFactor) AvdManager(com.android.sdklib.internal.avd.AvdManager) RunAndroidAvdManagerAction(org.jetbrains.android.actions.RunAndroidAvdManagerAction) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with AvdInfo

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

the class DeviceRenderer method renderDeviceName.

static void renderDeviceName(@NotNull IDevice d, @NotNull ColoredTextContainer component, @Nullable AvdManager avdManager) {
    component.setIcon(d.isEmulator() ? AndroidIcons.Ddms.Emulator2 : AndroidIcons.Ddms.RealDevice);
    String name;
    if (d.isEmulator()) {
        String avdName = d.getAvdName();
        if (avdManager != null) {
            AvdInfo info = avdManager.getAvd(avdName, true);
            if (info != null) {
                avdName = info.getProperties().get(AvdManager.AVD_INI_DISPLAY_NAME);
            }
        }
        if (avdName == null) {
            avdName = "unknown";
        }
        name = String.format("%1$s %2$s ", AndroidBundle.message("android.emulator"), avdName);
    } else {
        name = String.format("%1$s %2$s ", DevicePropertyUtil.getManufacturer(d, ""), DevicePropertyUtil.getModel(d, ""));
    }
    component.append(name, SimpleTextAttributes.REGULAR_ATTRIBUTES);
    IDevice.DeviceState deviceState = d.getState();
    if (deviceState != IDevice.DeviceState.ONLINE) {
        String state = String.format("%1$s [%2$s] ", d.getSerialNumber(), d.getState());
        component.append(state, SimpleTextAttributes.GRAYED_BOLD_ATTRIBUTES);
    }
    if (deviceState != IDevice.DeviceState.DISCONNECTED && deviceState != IDevice.DeviceState.OFFLINE) {
        component.append(DevicePropertyUtil.getBuild(d), SimpleTextAttributes.GRAY_ATTRIBUTES);
    }
}
Also used : AvdInfo(com.android.sdklib.internal.avd.AvdInfo) IDevice(com.android.ddmlib.IDevice)

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