@OwnerUser @ProfileUser public static Set<String> detectCriticalSystemPackages(final PackageManager pm) {
		final Stopwatch stopwatch = Performances.startUptimeStopwatch();

		final Set<String> critical_sys_pkgs = new HashSet<>(sCriticalSystemPkgs);

		// Detect package names for critical intent actions, as an addition to the white-list of well-known ones.
		for (final Intent intent : sCriticalActivityIntents) try { @SuppressLint("WrongConstant")
			final ResolveInfo info = pm.resolveActivity(intent, MATCH_DEFAULT_ONLY | Hacks.RESOLVE_ANY_USER_AND_UNINSTALLED);
			if (info == null || (info.activityInfo.applicationInfo.flags & FLAG_SYSTEM) == 0) continue;
			final String pkg = info.activityInfo.packageName;
			Log.i(TAG, "Critical package for " + intent + ": " + pkg);
			critical_sys_pkgs.add(pkg);
		} catch (final RuntimeException e) {	// NPE on Android 6 for some ASUS devices (e.g. ZenFone 2)
			Analytics.$().report(e);
		}
		Performances.check(stopwatch, 1, "CriticalActivities");

		// Detect package names for critical content providers, as an addition to the white-list of well-known ones.
		for (final String authority : sCriticalContentAuthorities) {
			if (authority == null) continue;		// Nullable for version-specific authorities
			@SuppressLint("WrongConstant") final ProviderInfo provider = pm.resolveContentProvider(authority, Hacks.RESOLVE_ANY_USER_AND_UNINSTALLED);
			if (provider == null || (provider.applicationInfo.flags & FLAG_SYSTEM) == 0 || (provider.flags & FLAG_SINGLE_USER) != 0) continue;
			Log.i(TAG, "Critical package for authority \"" + authority + "\": " + provider.packageName);
			critical_sys_pkgs.add(provider.packageName);
		}
		Performances.check(stopwatch, 1, "CriticalProviders");

		return critical_sys_pkgs;
	}
Determine whether a package is a "system package", in which case certain things
(like disabling notifications or disabling the package altogether) should be disallowed.
shared/src/main/java/com/oasisfeng/island/provisioning/SystemAppsManager.java