I'm trying to build a kiosk app using android 5's screen pinning feature. It seems that all I need to do in the app was to call startLockTask()
, but this still allows the user to leave the app by pressing the recent and back buttons.
To pin the app in a way that does not allow the user to leave it requires the app to be a device owner. Based on sites such as this one, one needs to run
adb shell dpm set-device-owner my.package.name/.MyAdminReceiver
in order to set the device owner. However, that command failed with
java.lang.IllegalStateException: Trying to set device owner but device is already provisioned.
which, I heard, is caused by the file /data/system/device_owner.xml
already being present on the device.
Since the device had just been freshly factory-reset, I suspect that it had come with an app already provisioned by the manufacturer, so I rooted the device. I would rather do it without rooting (since there will be some 70 devices I have to run the procedure on) but for research purposes, it can't be helped.
After rooting the device, I tried to find the device_owner.xml
file but it wasn't there. I tried creating one anyway based on this answer, but the app still shows the pinning message and the recent+back buttons still unpinned the app.
So why can't I set the device owner? is there any way around it?
While it's true that I tried dpm provisioning on a newly reset device, @basilisk's comment hinted me at the answer. The device comes loaded with bloatware that provides default accounts. Disabling these apps finally allowed me to provision the device with dpm.