List of usage examples for com.google.common.collect SetMultimap containsEntry
boolean containsEntry(@Nullable Object key, @Nullable Object value);
From source file:com.android.sdklib.repository.local.LocalAddonPkgInfo.java
/** * Get all the system images supported by an add-on target. * For an add-on, we first look in the new sdk/system-images folders then we look * for sub-folders in the addon/images directory. * If none are found but the directory exists and is not empty, assume it's a legacy * arm eabi system image./*from ww w . j av a 2s . co m*/ * If any given API appears twice or more, the first occurrence wins. * <p/> * Note that it's OK for an add-on to have no system-images at all, since it can always * rely on the ones from its base platform. * * @param fileOp File operation wrapper. * @return an array of ISystemImage containing all the system images for the target. * The list can be empty but not null. */ @NonNull private ISystemImage[] getAddonSystemImages(IFileOp fileOp) { Set<ISystemImage> found = new TreeSet<ISystemImage>(); SetMultimap<IdDisplay, String> tagToAbiFound = TreeMultimap.create(); // Look in the system images folders: // - SDK/system-image/platform/addon-id-tag/abi // - SDK/system-image/addon-id-tag/abi (many abi possible) // Optional: look for skins under // - SDK/system-image/platform/addon-id-tag/abi/skins/skin-name // - SDK/system-image/addon-id-tag/abi/skins/skin-name // If we find multiple occurrences of the same platform/abi, the first one read wins. LocalPkgInfo[] sysImgInfos = getLocalSdk().getPkgsInfos(PkgType.PKG_ADDON_SYS_IMAGE); for (LocalPkgInfo pkg : sysImgInfos) { IPkgDesc d = pkg.getDesc(); if (pkg instanceof LocalAddonSysImgPkgInfo && d.hasVendor() && mAddonDesc.getVendor().equals(d.getVendor()) && mAddonDesc.getName().equals(d.getTag()) && Objects.equal(mAddonDesc.getAndroidVersion(), pkg.getDesc().getAndroidVersion())) { final IdDisplay tag = mAddonDesc.getName(); final String abi = d.getPath(); if (abi != null && !tagToAbiFound.containsEntry(tag, abi)) { found.add(((LocalAddonSysImgPkgInfo) pkg).getSystemImage()); tagToAbiFound.put(tag, abi); } } } // Look for sub-directories: // - SDK/addons/addon-name/images/abi (multiple abi possible) // - SDK/addons/addon-name/armeabi (legacy support) boolean useLegacy = true; boolean hasImgFiles = false; final IdDisplay defaultTag = SystemImage.DEFAULT_TAG; File imagesDir = new File(getLocalDir(), SdkConstants.OS_IMAGES_FOLDER); File[] files = fileOp.listFiles(imagesDir); for (File file : files) { if (fileOp.isDirectory(file)) { useLegacy = false; String abi = file.getName(); if (!tagToAbiFound.containsEntry(defaultTag, abi)) { found.add(new SystemImage(file, LocationType.IN_IMAGES_SUBFOLDER, SystemImage.DEFAULT_TAG, mAddonDesc.getVendor(), abi, FileOp.EMPTY_FILE_ARRAY)); tagToAbiFound.put(defaultTag, abi); } } else if (!hasImgFiles && fileOp.isFile(file)) { if (file.getName().endsWith(".img")) { //$NON-NLS-1$ // The legacy images folder is only valid if it contains some .img files hasImgFiles = true; } } } if (useLegacy && hasImgFiles && fileOp.isDirectory(imagesDir) && !tagToAbiFound.containsEntry(defaultTag, SdkConstants.ABI_ARMEABI)) { // We found no sub-folder system images but it looks like the top directory // has some img files in it. It must be a legacy ARM EABI system image folder. found.add(new SystemImage(imagesDir, LocationType.IN_LEGACY_FOLDER, SystemImage.DEFAULT_TAG, SdkConstants.ABI_ARMEABI, FileOp.EMPTY_FILE_ARRAY)); } return found.toArray(new ISystemImage[found.size()]); }