private static String getManagedProvisioningPackageName(final Context context) throws NameNotFoundException {
        @SuppressLint("WrongConstant") final List<ResolveInfo> candidates = context.getPackageManager().queryIntentActivities(
                new Intent(DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE), PackageManager.MATCH_DISABLED_COMPONENTS
                        | PackageManager.MATCH_UNINSTALLED_PACKAGES | PackageManager.MATCH_SYSTEM_ONLY);
        for (final ResolveInfo candidate : candidates)
            if ((candidate.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0)
                return candidate.activityInfo.applicationInfo.packageName;
        throw new NameNotFoundException();
    }
Runs the next task when all packages have been deleted or shuts down the activity if package
deletion fails.
engine/src/main/java/com/oasisfeng/island/provisioning/task/DeleteNonRequiredAppsTask.java