public static @CheckResult SetupViewModel checkManagedProvisioningPrerequisites(final Context context, final boolean ignore_incomplete_setup) {
		final PackageManager pm = context.getPackageManager();
		if (buildManagedProfileProvisioningIntent(context).resolveActivity(pm) == null)
			return buildErrorVM(R.string.setup_error_missing_managed_provisioning, reason("lack_managed_provisioning"));

		// Check for incomplete provisioning, before DPM.isProvisioningAllowed() check which returns true in this case.
		if (Users.profile == null) for (final int profile_id : IslandManager.getProfileIdsIncludingDisabled(context)) {
			if (Users.isOwner(profile_id)) continue;
			final Optional<ComponentName> owner = DevicePolicies.getProfileOwnerAsUser(context, UserHandles.of(profile_id));
			if (owner == null || ! owner.isPresent()) continue;
			final ComponentName profile_owner = owner.get();
			if (! Modules.MODULE_ENGINE.equals(profile_owner.getPackageName())) {
				final CharSequence label = readOwnerLabel(context, profile_owner);
				reason("existent_work_profile").with(ITEM_ID, profile_owner.getPackageName()).with(ITEM_NAME, label != null ? label.toString() : null).send();
				continue;
			}
			if (ignore_incomplete_setup) continue;
			return buildErrorVM(R.string.setup_error_provisioning_incomplete, reason("provisioning_incomplete")).withExtraAction(R.string.button_have_checked);
		}

		// DPM.isProvisioningAllowed() is the one-stop prerequisites checking.
		final DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class);
		if (dpm != null && dpm.isProvisioningAllowed(DevicePolicyManager.ACTION_PROVISION_MANAGED_DEVICE))
			Analytics.$().event("device_provision_allowed").send();	// Special analytics
		if (dpm != null && dpm.isProvisioningAllowed(ACTION_PROVISION_MANAGED_PROFILE)) return null;

		final boolean has_managed_users = pm.hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS);
		if (! has_managed_users)
			return buildErrorVM(R.string.setup_error_managed_profile_not_supported, reason("lack_managed_users"));

		final String device_owner = new DevicePolicies(context).getDeviceOwner();
		if (device_owner != null) {
			CharSequence owner_label = null;
			try {
				owner_label = pm.getApplicationInfo(device_owner, PackageManager.MATCH_UNINSTALLED_PACKAGES).loadLabel(pm);
			} catch (final PackageManager.NameNotFoundException ignored) {}		// Should never happen.

			final SetupViewModel error = buildErrorVM(R.string.setup_error_managed_device, reason("managed_device").with(ITEM_ID, device_owner));
			error.message_params = new String[] { owner_label != null ? owner_label.toString() : device_owner };
			error.action_extra = 0;		// Disable the manual-setup prompt, because device owner cannot be removed by 3rd-party.
			return error;
		}

		reason("disallowed").send();		// Disallowed by DPC for unknown reason, just log this but let user have a try.
		return null;
	}
@return null if all prerequisites met TODO: Move this method to IslandSetup
mobile/src/main/java/com/oasisfeng/island/setup/SetupViewModel.java