Is it possible to create a Profile Owner application that manages the entire user profile, that is, it will not be a jointly managed profile?
ACTION_PROVISION_MANAGED_PROFILE
The profile owner application creates a managed profile by submitting the intent using the DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE action. (A source.)
Let DevicePolicyManager.java open.
The Javadoc comment for ACTION_PROVISION_MANAGED_PROFILE says:
/** * ... Starts the provisioning flow which sets up a managed profile. * ... * ... The user which provisioning is started from and * the managed profile share a launcher. ... */
So ACTION_PROVISION_MANAGED_PROFILE probably won't help you do what you want.
Hmmm.
ACTION_PROVISION_MANAGED_USER
The only other action in this file that looks like this can help: ACTION_PROVISION_MANAGED_USER.
Take a look at the Javadoc comment. It says:
/** * ... Starts the provisioning flow which sets up a managed user. * ... * This intent will typically be sent by a mobile device management application (MDM). * Provisioning configures the user as managed user and sets the MDM as the profile * owner who has full control over the user.
Fine! What is the catch?
* ... Provisioning can only happen before user setup has * been completed. ... */
O. :( So, if your device is not deployed, I think you need to somehow install the application for your profile owner right after the factory reset and before the installation wizard is completed.
Side note
I looked at a specific technical document. It states: "During a managed initialization process, an intent known as ACTION_PROVISION_MANAGED_PROFILE is invoked. If the user has a pre-existing personal account, the managed profile is separate, but is shared." It seems to me that if you call ACTION_PROVISION_MANAGED_PROFILE on a device without user accounts, your application can control the entire user profile. But, again, I think you need to somehow install your application for the profile owner right after the factory reset and before the installation wizard is completed.
Doing what you want
I think that what you want is unfortunately impossible. If you want, you can request an Android feature and ask them to make it possible. If you do, leave a comment below with the function url. If you do not have enough reputation points for comments, write me at tealhill at gmail.com and ask me to leave a comment on your behalf.
Workaround
I assume that for your application there may be a problem downloading and launching a third-party application that has the roots of the phone. Most phones are root. Once the phone is rooted, your application can become the owner of the device. Subsequently, maybe your application can turn off the phone and still remain the owner of the device. Or maybe not. I dont know.
If your application fails to disconnect the phone, or if it does not try, the phone will remain forever. This may pose a security risk. You should probably warn the user.