Return the BundleCapability of a bundle exporting the package packageName.

@param context     The BundleContext
@param packageName The package name
@return the BundleCapability of a bundle exporting the package packageName
185205
private static BundleCapability getExportedPackage(BundleContext context, String packageName) {
        List<BundleCapability> packages = new ArrayList<BundleCapability>();
        for (Bundle bundle : context.getBundles()) {
            BundleRevision bundleRevision = bundle.adapt(BundleRevision.class);
            for (BundleCapability packageCapability : bundleRevision.getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE)) {
                String pName = (String) packageCapability.getAttributes().get(BundleRevision.PACKAGE_NAMESPACE);
                if (pName.equalsIgnoreCase(packageName)) {
                    packages.add(packageCapability);
                }
            }
        }

        Version max = Version.emptyVersion;
        BundleCapability maxVersion = null;
        for (BundleCapability aPackage : packages) {
            Version version = (Version) aPackage.getAttributes().get("version");
            if (max.compareTo(version) <= 0) {
                max = version;
                maxVersion = aPackage;
            }
        }

        return maxVersion;
    }
825123
public void getExportedPackages(Set<String> exportedPackages) {
		if (exportedPackages != null) {
			exportedPackages.add(getCodeElementExtractor().getBasePackage());
			exportedPackages.add(getCodeElementExtractor().getBuilderPackage());
			if (getCodeBuilderConfig().isISourceAppendableEnable()) {
				exportedPackages.add(getCodeElementExtractor().getAppenderPackage());
			}
		}
	}
534264
public List<String> getCustomBundlePropertyAsList(String bundleName, String key) {
		List<String> propertiesList = new ArrayList<>();
		StringTokenizer tk = new StringTokenizer(getCustomBundleProperty(bundleName, key, ""), ",");
		while (tk.hasMoreTokens())
			propertiesList.add(tk.nextToken().trim());
		return propertiesList;
	}
1340909
static String getParentPackageName(final String packageOrClassName) {
        if (packageOrClassName.isEmpty()) {
            return null;
        }
        final int lastDotIdx = packageOrClassName.lastIndexOf('.');
        return lastDotIdx < 0 ? "" : packageOrClassName.substring(0, lastDotIdx);
    }
21117
public boolean isIBMPackage(String packageName) {
        if (packageName != null) {
            BundlePackages p = populatePackageLists();
            // If we still can't get our list of packages (for example, in unit tests), let everything pass
            if (p != null) {
                if (p.containsPrivatePackage(packageName)) {
                    return true;
                } else if (p.containsExportedPackage(packageName)) {
                    // Add an extra check - if this is an exported package, it could be spec or third-party, not IBM
                    SharedPackageInspector inspector = st.getService();
                    if (inspector != null) {
                        PackageType exported = inspector.getExportedPackageType(packageName);
                        // If it's spec, third party, or stable it's not internal - otherwise, it is
                        if ( exported == null )
                            return true;
                        if ( exported.isSpecApi() || exported.isThirdPartyApi() || exported.isStableApi() ) 
                            return false;
                        
                        return true;
                    }

                    // If we couldn't get hold of the service, assume it was internal if our bundles export it
                    return true;
                }

            }
        }
        return false;
    }
772608
public static List<Package> getAllPackages(String packageName) throws CachingException {
        List<Package> allPackages = new ArrayList<>();
        for (Package packageVO : getPackageList()) {
            if (packageVO.getName().equals(packageName)) {
                allPackages.add(packageVO);
            }
        }
        return allPackages;
    }
73034
private BundleContext getBundleContext(Bundle bundle, long timeout) {
        long endTime = System.currentTimeMillis() + timeout;
        BundleContext bc = null;
        while (bc == null) {
            bc = bundle.getBundleContext();
            if (bc == null) {
                if (System.currentTimeMillis() >= endTime) {
                    throw new TestContainerException(
                        "Unable to retrieve bundle context from bundle " + bundle);
                }
                try {
                    Thread.sleep(100);
                }
                catch (InterruptedException e) {
                    // Ignore
                }
            }
        }
        return bc;
    }
625079
public static boolean isTopApplication(Context context) {
		ComponentName activity = getTopActivity(context);
		if (activity == null) {
			return false;
		}
		return activity.getPackageName().equals(context.getApplicationInfo().packageName);
	}
1301838
public static Object getExtraObject(Activity context, String key) {
        Object param = null;
        Bundle bundle = context.getIntent().getExtras();
        if (bundle != null) {
            param = bundle.get(key);
        }
        return param;
    }
372904
String getPackage() {
        if (this.packageName != null)
            return this.packageName;
        if (this.parent != null)
            return this.parent.getPackage();
        return null;
    }
468738
public static BundleContext getBundleContextByBundleId(long bundleId) {
        Bundle bundle = bundleContext.getBundle(bundleId);
        if (bundle != null) {
            return bundle.getBundleContext();
        } else {
            return null;
        }
    }
608073
private static ResourceBundle getResourceBundle(String enumClassName) {
    String bundleName = enumClassName.replace('$','_');
    return ResourceBundle.getBundle(bundleName);
  }
1020496
@TargetApi(Build.VERSION_CODES.KITKAT)
    public static boolean hasStepCounterSensorFeature(Context context) {
        return hasStepCounterSensorFeature(context.getPackageManager());
    }
898793
public static boolean isPackageInstalled(Context context, String packageName) {
		try {
			context.getPackageManager().getApplicationInfo(packageName, 0);
			return true;
		} catch (Exception e) {
			return false;
		}
	}
986852
public static boolean launchAppForPackage(final Context context, final String packageName) {
        try {
            final PackageManager packageManager = context.getPackageManager();
            final Intent intent = packageManager.getLaunchIntentForPackage(packageName);
            intent.addCategory(Intent.CATEGORY_LAUNCHER);
            context.startActivity(intent);
            return true;
        } catch (Exception ex) {
            Log.e("Caffeine", "Failed to launch application for package name [" + packageName + "]", ex);
            return false;
        }
    }
1247580
public Bundle findBundle(Object objResource, Object bundleContext, String packageName, String versionRange)
    {
        if (bundleContext == null)
            bundleContext = this.bundleContext;
        if (bundleContext == null)
            return null;
        if (objResource == null)
            return BaseClassFinderService.findBundle((BundleContext)bundleContext, packageName, versionRange);
        Bundle[] bundles = ((BundleContext)bundleContext).getBundles();
        for (Bundle bundle : bundles)
        {
            if (objResource != null)
            {
                if (this.isResourceBundleMatch(objResource, bundle))
                    return bundle;               
            }
        }
        return null;
    }
282593
public static ResourceBundle getResourceBundle(String bundleName, Locale locale) {
        ResourceBundle bundle = null;

        boolean isDev = false;
        if (Ameba.getApp() != null) {
            isDev = Ameba.getApp().getMode().isDev();
            BUNDLE_CONTROL.noCache = isDev;
        }
        if (!isDev) {
            bundle = RESOURCE_BUNDLES.get(bundleName, locale);
        }
        if (bundle == null) {
            try {
                bundle = ResourceBundle.getBundle(
                        bundleName,
                        locale,
                        ClassUtils.getContextClassLoader(),
                        BUNDLE_CONTROL
                );
            } catch (MissingResourceException e) {
                // no op
            }
        }

        if (bundle != null && !isDev) {
            RESOURCE_BUNDLES.put(bundleName, locale, bundle);
        }

        return bundle;
    }