I'm have created a kiosk application by following this guide in android developers - Lock Task Mode. The application can start itself automatically whenever the device finish booting up but the problem is whenever I restart/shutdown and start my device that has this restriction the device will not be able to boot it will stuck in the brand logo screen of the device and have to factory reset it to work again.
dpm.addUserRestriction(componentName, UserManager.DISALLOW_USB_FILE_TRANSFER);
This restriction is working fine if I don't restart the device but at some point the device needs to be shutdown. How can I set this restriction properly during start without breaking the deivce?