am e65fba45: am 78d504f1: am 95180a01: Forbid profile owners outside device owner package

* commit 'e65fba452b04e82fb51f10405965c1730520099d':
  Forbid profile owners outside device owner package
diff --git a/src/com/android/managedprovisioning/ProfileOwnerPreProvisioningActivity.java b/src/com/android/managedprovisioning/ProfileOwnerPreProvisioningActivity.java
index e22633e..2b5ac5f 100644
--- a/src/com/android/managedprovisioning/ProfileOwnerPreProvisioningActivity.java
+++ b/src/com/android/managedprovisioning/ProfileOwnerPreProvisioningActivity.java
@@ -23,6 +23,7 @@
 import static com.android.managedprovisioning.EncryptDeviceActivity.TARGET_PROFILE_OWNER;
 
 import android.app.Activity;
+import android.app.admin.DevicePolicyManager;
 import android.app.AlertDialog;
 import android.app.ProgressDialog;
 import android.content.BroadcastReceiver;
@@ -134,6 +135,15 @@
             }
         }
 
+        DevicePolicyManager dpm =
+                (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
+        String deviceOwner = dpm.getDeviceOwner();
+        if (deviceOwner != null && !deviceOwner.equals(mMdmPackageName)) {
+            showErrorAndClose(R.string.managed_provisioning_error_text, "Permission denied, "
+                    + "profile owner must be in the same package as device owner.");
+            return;
+        }
+
         // If there is already a managed profile, allow the user to cancel or delete it.
         int existingManagedProfileUserId = alreadyHasManagedProfile();
         if (existingManagedProfileUserId != -1) {