Thx for answering!
Erel, Yes, the timers are process globals variables in the service module, and are initialized in service_create. However, as I say before, when the phone enters in sleep mode, the timers are frozen, and when I unlock the phone, the timers are unfrost. Its like the service is suspended during the time that the screen is off.
Thedesolatesoul, I was thinking about partialwakelock, but I am executing code all the time (like for months). I dont think that putting locks during sleep mode, would be a good idea because it will drain the battery a lot, and it will loose the sense of a battery saver.
For example, this should be a normal execution:
(Actual time: 20:00, Frequency: 15 min, Night time: 23:00 - 08:00)
20:00: Turn on wifi
20:01: Check wifi is actually connected
20:02: Turn off Wifi
20:15: Turn on Wifi
20:16: Check wifi is actually connected
20:17: Turn off wifi
20:30: Turn on Wifi
...
22:45: Turn On Wifi
22:46: Check wifi is actually connected
22:47: Turn off wifi
23:00: Night Time (no more conectivity, unless the user unlocks the phone)
08:00: Night time end, turn on wifi
08:01: Check conectivity
08:02: Turn off wifi
08:15: Turn on..
... (and so on)
I don't know which would be a good strategy using locks, maybe I'm missing something
Bluejay, thx for the idea, maybe using something like a list of triggers could do it, but I think that it would be kind of hard to apply, because I have like 10 timers, and using the StartServiceAt with 10 different times, it would be a mess.
I'm using the screen_on, screen_off, and user_present events to make some stuff, there is no problem there. The problem is just with the timers, that dont work during sleep time
I think I'll try modularizing the service into 3 or 4. I'm a little worry about the ram consumption, right now its about 5mb, but if each service needs that amount, it would be like 20mb, and for some devices that only have 512mb, that is a significant amount.