cosu
cosu copied to clipboard
Novice feelings: How can I avoid accidentally doing something wrong?
Hi there.
This is a fantastic code lab - and even as a beginner Android developer I have been able to understand the guide very well.
But - as I am about to 'hit the switch' on setting my application as the device owner, something inside me yells out, "Oh no! What happens if I have made a mistake! How do I set my device back to normal?! Especially if my function that sets the COSU policy to false never runs!".
Assuming that the developer just wants to create a nice Android kiosk, and still allow developers full access to change things how they wish, how do we alleviate the novices' concerns?
So, as I am living this experience, maybe my personal journey could help!
I set the device administrator to my application. However - unlike the default application, my application has only one activity (the one I want pinned). During some testing, when the COSU settings were unset, my applications launch Intents were no longer registered, and I could not relaunch my application through Android Studio.
I also could not remove the application (as expected), because it is a device administrator.
Now, I assume I could have relaunched my specific Activity some other way, but skipping this, I performed a factory reset on my device, because I know that will take me back to square one.
So, just so other beginners are aware - once you set a device owner, you cannot set a different administrator over adb. You must factory reset.
In this respect, if you are only testing your application, in the setDefaultCosuPolicies function, make sure you change
setUserRestriction(UserManager.DISALLOW_FACTORY_RESET, active);
to
setUserRestriction(UserManager.DISALLOW_FACTORY_RESET, false); // ALWAYS ALLOW FACTORY RESET
Then, when you are certain that your application works as desired, you set it back to active.
Also, another thing to note.
When you have installed and set your application to device administrator, it seems you cannot re-install (or debug) your application.
I changed my mind about using my own application as the device administrator, and instead used TestDPC!
I found some interesting information at http://www.sureshjoshi.com/mobile/android-kiosk-mode-without-root
You can use mDevicePolicyManager.clearDeviceOwnerApp("com.example.yourapplication"); somewhere in your code that will unset the device owner. You should then be able to re-debug or develop your application, without going through the full factory reset.