Hello everyone,
I'm currently developing an Android application that operates within a work profile and is designated as the Profile Owner. My objective is to enable the app to programmatically delete its own work profile. Here's a summary of the approaches I've attempted and the issues encountered:
- Using DevicePolicyManager.wipeData() Method:
I invoked the wipeData() method from the DevicePolicyManager within my app. Instead of deleting the work profile, this method switches the context back to the primary user without removing the profile.
- Executing pm remove-user via ADB:
Running the following command via ADB successfully removes the work profile:
adb shell pm remove-user X
However, attempting to execute this command programmatically within the app using Runtime.getRuntime().exec("pm remove-user X") results in an error with exit code 255.
Has anyone successfully implemented a method to programmatically delete a work profile from within an app acting as the Profile Owner? Are there specific permissions or alternative approaches required to achieve this functionality? Any insights or suggestions would be greatly appreciated.
Thank you in advance for your help.