We are trying to implement timer for native code in android .The timer should work precisely during wake and sleep mode .When timer expires then our native code will send DPD(Dead peer detection) messages to the network We tried following approaches .
Using android framework API's for alarm manager in userspace code and below are the results:
- This doesn't give the accurate results even during wake state for small timers like 2s,3s,5s.
- Does not work precisely for sleep mode also.
We tried to use kernel timer in kernel space code and below are the results:
- Works perfectly for wake state.
- But for sleep state timers do not expire at all.When we wake the device up manually then the timers get expire .So,in conclusion kernel timers do not work during sleep state.
3.Using wake lock *We are trying to avoid use of wake lock as it may cause significant performance issues
P.S - Open source Ipsec implementation strongswan sends the DPD messages precise time even during sleep mode .But it seems that strongswan does not use wake lock ,so we are still trying to figure out how it works during sleep mode.Anybody searching for answer to this question might want to look into that code.
Can anyone please suggest something to resolve this issue.