Code example for PackageManager

Methods: checkSignaturesgetComponentEnabledSettingresolveService

0
	 * @return true if ads should be hidden 
	 */ 
	public static boolean hideAds(final Context context) { 
		PackageManager pm = context.getPackageManager(); 
		Intent donationCheck = new Intent(DONATOR_BROADCAST_CHECK); 
		ResolveInfo ri = pm.resolveService(donationCheck, 0); 
		// Log.d(TAG, "ri: " + ri); 
		int match = PackageManager.SIGNATURE_UNKNOWN_PACKAGE; 
		if (ri != null) { 
			Log.d(TAG, "found package: " + ri.serviceInfo.packageName); 
			ComponentName cn = new ComponentName(ri.serviceInfo.packageName, ri.serviceInfo.name); 
			// Log.d(TAG, "component name: " + cn); 
			int i = pm.getComponentEnabledSetting(cn); 
			// Log.d(TAG, "component status: " + i); 
			// Log.d(TAG, "package status: " + ri.serviceInfo.enabled); 
			if (i == PackageManager.COMPONENT_ENABLED_STATE_ENABLED 
					|| i == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT 
					&& ri.serviceInfo.enabled) { 
				match = pm.checkSignatures(context.getPackageName(), ri.serviceInfo.packageName); 
			} else { 
				Log.w(TAG, ri.serviceInfo.packageName + ": " + ri.serviceInfo.enabled); 
			} 
		}