I am writing Android functional tests. I need the device to be awake and the application to be visualized in order for them to work. I have consulted with Android developers for that. However, there are several problems with the proposed solution:
- The proposed method now has several deprecated methods. Android API now advises me to use flags on the window:
This class was deprecated in API level 13. Use FLAG_DISMISS_KEYGUARD and/or FLAG_SHOW_WHEN_LOCKED instead; this allows you to seamlessly hide the keyguard as your application moves in and out of the foreground and does not require that any special permissions be requested. Handle returned by newKeyguardLock(String) that allows you to disable / reenable the keyguard.
I tried this suggestion, however, as opposed to the deprecated solution, the flag one jsut does not work for me - it does not unlock the device. I also found sources confirming the instability of the flag solution (e.g. the comments on this answer).
- The second problem is that I need to add permissions to the application under test. I find this as quite wrong approach (modifying the code under test in order to be able to test it). I found several places that advise me to use
src/debug/AndroidManifest.xml
for that (this one and this one for example). However, it just not happen as stated - the debug Mainfest does not get included to the deployed things on the device. Is it related to the way I build and deploy? I use Eclipse for development (ADT). Will this manifest injection work only if I use build tool like ant?
All in all - can somebody advise on a stable solution for unlcoking and keeping awake the device while my test are being executed?
EDIT
I have now found that Robotium also included unlockScreen
method in their latest version of the framework. It uses exactly the window flags proposed above and is also not working on my device.