Create managed profile setup flow

Change-Id: I42f8255bea3c7126526430b28c384538fa204c28
diff --git a/res/raw/lineage_wizard_script_managed_profile.xml b/res/raw/lineage_wizard_script_managed_profile.xml
new file mode 100644
index 0000000..d32f5bb
--- /dev/null
+++ b/res/raw/lineage_wizard_script_managed_profile.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+     Copyright (C) 2016 The CyanogenMod Project
+     Copyright (C) 2021 The Calyx Institute
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+
+<WizardScript xmlns:wizard="http://schemas.android.com/apk/res/com.google.android.setupwizard"
+              wizard:firstAction="welcome">
+
+    <WizardAction wizard:uri="intent:#Intent;action=org.lineageos.setupwizard.LINEAGE_WELCOME;end" id="welcome">
+        <result wizard:action="restore" />
+    </WizardAction>
+
+    <WizardAction wizard:uri="intent:#Intent;action=org.lineageos.setupwizard.LINEAGE_RESTORE_BACKUP;end" id="restore">
+        <result wizard:action="finish" />
+    </WizardAction>
+
+    <WizardAction wizard:uri="intent:#Intent;action=org.lineageos.setupwizard.LINEAGE_SETUP_COMPLETE;end" id="finish">
+        <result wizard:action="exit" />
+    </WizardAction>
+
+    <WizardAction wizard:uri="intent:#Intent;action=org.lineageos.setupwizard.EXIT;end" id="exit" />
+
+</WizardScript>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 8253bc5..3924703 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -21,6 +21,7 @@
 
     <string name="lineage_wizard_script_uri" translatable="false">android.resource://org.lineageos.setupwizard/raw/lineage_wizard_script</string>
     <string name="lineage_wizard_script_user_uri" translatable="false">android.resource://org.lineageos.setupwizard/raw/lineage_wizard_script_user</string>
+    <string name="lineage_wizard_script_managed_profile_uri" translatable="false">android.resource://org.lineageos.setupwizard/raw/lineage_wizard_script_managed_profile</string>
 
     <string name="activity_label_empty" />
 
diff --git a/src/org/lineageos/setupwizard/SetupWizardActivity.java b/src/org/lineageos/setupwizard/SetupWizardActivity.java
index 7d7ddfe..876b63d 100644
--- a/src/org/lineageos/setupwizard/SetupWizardActivity.java
+++ b/src/org/lineageos/setupwizard/SetupWizardActivity.java
@@ -26,6 +26,7 @@
 import android.annotation.Nullable;
 import android.content.Intent;
 import android.os.Bundle;
+import android.os.UserManager;
 import android.util.Log;
 
 import com.google.android.setupcompat.util.WizardManagerHelper;
@@ -54,6 +55,9 @@
             Intent intent = new Intent(ACTION_LOAD);
             if (isPrimaryUser()) {
                 intent.putExtra(EXTRA_SCRIPT_URI, getString(R.string.lineage_wizard_script_uri));
+            } else if (getSystemService(UserManager.class).isManagedProfile()) {
+                intent.putExtra(EXTRA_SCRIPT_URI, getString(
+                        R.string.lineage_wizard_script_managed_profile_uri));
             } else {
                 intent.putExtra(EXTRA_SCRIPT_URI,
                         getString(R.string.lineage_wizard_script_user_uri));
diff --git a/src/org/lineageos/setupwizard/SetupWizardExitActivity.java b/src/org/lineageos/setupwizard/SetupWizardExitActivity.java
index a209ebb..3ec6587 100644
--- a/src/org/lineageos/setupwizard/SetupWizardExitActivity.java
+++ b/src/org/lineageos/setupwizard/SetupWizardExitActivity.java
@@ -24,6 +24,7 @@
 import android.annotation.Nullable;
 import android.content.Intent;
 import android.os.Bundle;
+import android.os.UserManager;
 import android.util.Log;
 
 import org.lineageos.setupwizard.util.PhoneMonitor;
@@ -41,7 +42,9 @@
         }
         SetupWizardUtils.enableCaptivePortalDetection(this);
         PhoneMonitor.onSetupFinished();
-        launchHome();
+        if (!getSystemService(UserManager.class).isManagedProfile()) {
+            launchHome();
+        }
         finish();
         applyForwardTransition(TRANSITION_ID_FADE);
         Intent i = new Intent();