We're currently trying to work on an application that's based on Android's mobile device management APIs. We have managed to figure out how to get device admin permissions and wipe off the phone data with the help of the same, but are unable to restrict the user from not using WiFi/Bluetooth/Location/USB/Tethering etc.
The moment we did tried to do this directly in our app it crashed with an exception stating that the current user isn't an owner/work user along with the user ID.
After that we got to know that, these user restrictions can't be directly applied on any profile via the DeviceAdminPolicy manager, but just on a work profile provisioned by the app.. So we tried following this stackoverflow answer to see if provisioning a work profile helps us with the following code. (changes were made to adapt to the deprecation)
val intent = Intent(ACTION_PROVISION_MANAGED_PROFILE)
intent.putExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME, deviceAdmin)
startActivityForResult(intent, REQUEST_PROVISION_MANAGED_PROFILE)
The app now prompts the user for MDM permission as per our earlier flow/code and then takes the user through a series of animations until the entire process of setting up the workflow is done, but then nothing really happens. We can't find the newly created profile and the app resumes back to the initial activity.
Trying to trigger the provisioning of work profile again causes the app to alert us that the work profile could not be added and to contact our IT admin for the same. This behavior remains the same until we wipe of the entire data on the device.
Are we missing out something out on something from the docs or maybe are doing something incorrect? Could someone please help us out with this?
An existing proper guide to setup restrictions via device admin APIs would be really helpful. Please do let us know if any additional information is required.
Thanks a lot in advance!