@WorkerThread private static void proceed(final Context context, final Intent intent) {
		if (DevicePolicyManager.ACTION_PROVISION_MANAGED_DEVICE.equals(intent.getAction())) {
			Log.d(TAG, "Re-provisioning Mainland.");
			if (! Users.isOwner()) throw new IllegalStateException("Not running in owner user");
			startDeviceOwnerPostProvisioning(context, new DevicePolicies(context));
			Toasts.show(context, R.string.toast_reprovision_done, Toast.LENGTH_SHORT);
			return;
		}
		if (DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE.equals(intent.getAction())) {		// Borrow this activity intent for re-provision.
			Log.d(TAG, "Re-provisioning Island.");
			reprovisionManagedProfile(context);
			Toasts.show(context, R.string.toast_reprovision_done, Toast.LENGTH_SHORT);
			return;
		}
		if (Users.isOwner() && DevicePolicyManager.ACTION_DEVICE_OWNER_CHANGED.equals(intent.getAction())) {	// ACTION_DEVICE_OWNER_CHANGED is added in Android 6.
			Analytics.$().event("device_provision_manual_start").send();
			startDeviceOwnerPostProvisioning(context, new DevicePolicies(context));
			return;
		}

		final boolean is_manual_setup = Intent.ACTION_USER_INITIALIZE.equals(intent.getAction()) || intent.getAction() == null/* recovery procedure triggered by MainActivity */;
		Analytics.$().setProperty(Analytics.Property.IslandSetup, is_manual_setup ? "manual" : "managed");
		Log.d(TAG, "Provisioning profile (" + Users.toId(android.os.Process.myUserHandle()) + (is_manual_setup ? ", manual) " : ")"));

		final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
		prefs.edit().putInt(PREF_KEY_PROVISION_STATE, 1).putInt(PREF_KEY_PROFILE_PROVISION_TYPE, is_manual_setup ? 1 : 0).apply();
		final DevicePolicies policies = new DevicePolicies(context);
		if (is_manual_setup) {		// Do the similar job of ManagedProvisioning here.
			Log.d(TAG, "Manual provisioning");
			Analytics.$().event("profile_post_provision_manual_start").send();
			ProfileOwnerManualProvisioning.start(context, policies);	// Mimic the stock managed profile provision
		} else Analytics.$().event("profile_post_provision_start").send();

		Log.d(TAG, "Start post-provisioning.");
		try {
			startProfileOwnerPostProvisioning(context, policies);
		} catch (final Exception e) {
			Analytics.$().event("profile_post_provision_error").with(Analytics.Param.ITEM_NAME, e.toString()).send();
			Analytics.$().report(e);
		}

		// Prepare critical apps
		enableCriticalAppsIfNeeded(context, policies);
		// Disable unnecessarily enabled apps
		if (! Users.isOwner()) hideUnnecessaryAppsInManagedProfile(context);	// Users.isProfile() does not work before setProfileEnabled().

		setupLauncherActivityInIsland(context);     // Must before setProfileEnabled() is invoked.

		if (! is_manual_setup) {	// Enable the profile here, launcher will show all apps inside.
			Log.d(TAG, "Enable profile now.");
			policies.execute(DevicePolicyManager::setProfileEnabled);
		}
		Analytics.$().event("profile_post_provision_done").send();

		prefs.edit().putInt(PREF_KEY_PROVISION_STATE, POST_PROVISION_REV).apply();

		if (! launchMainActivityInOwnerUser(context)) {
			Analytics.$().event("error_launch_main_ui").send();
			Log.e(TAG, "Failed to launch main activity in owner user.");
			Toasts.show(context, R.string.toast_setup_complete, Toast.LENGTH_LONG);
		}
	}
This is the normal procedure after ManagedProvision finished its provisioning, running in profile.
engine/src/main/java/com/oasisfeng/island/provisioning/IslandProvisioning.java