I am working at an app that is meant to fully take over a phone if it has root access. The application takes pictures at a set interval, and uploads them to a ftp server. The use case for it is to turn old phones into security cameras, or for timelapse photography in general. I am also trying to conserve as much power as possible, so that the phone can be used in remote locations with a solar USB charger.
Ideally, the phone should wake up every minute or so using setAndAllowWhileIdle(), take a picture, go to sleep. Once every x number of pictures are taken, it would turn off the airplane mode, connect to the internet, upload the pictures, turn on the airplane mode.
My problem is that once I force the phone to doze mode by using "dumpsys deviceidle force-idle", setAndAllowWhileIdle() becomes very inexact. An alarm set for the next 20 seconds can arrive even in 15 minutes.
I was wondering if there is any way as root to set the idle maintenance window to whatever interval I want, so that I can get my alarms at reasonable times. Or if there is any other way as root to get reliable alarms (reliable as in minute accuracy). Or if I can suspend the entire phone for a set period of time.
Ok, so after a lot of reading and experimenting, I found the magic solution. It's not exactly what I wanted, because I can't allow only my application to wake up more often in doze mode. I can only change it on a global scale, so all the apps can do that. But since for my specific need I can remove all the not needed apps, it works quite nicely.
The solution is this: "su -c settings put global alarm_manager_constants allow_while_idle_long_time=20000,allow_while_idle_whitelist_duration=30000"
Other alarm settings can be modified this way, you can see them by doing a "dumpsys alarm"