I developed a CIQ module to track elapsed, moving and stopped metrics for time, speed and distance. This works regardless of the auto-pause setting. And lets me present in a data field both type of stats: elapsed time and speed, and moving time and speed, as well as stopped time and percent stopped -vs- elapsed. This really helps for situations where you care about BOTH the elapsed metrics (eg: auto-pause off) but also want to watch your moving speed your total stop time (eg: auto-pause on). Can't watch both metric types by default.
Anyway, I wanted to test that my metrics worked under all scenarios, including a device crash, a "discard activity and restart without a power cycle", and putting the device to sleep or powering off and back on and restarting the same activity.
In doing so, I uncovered a few Garmin firmware bugs and had to work around those in my code to get accurate stats. For example, the built-in system "elapsed time" is wrong if you are in an activity, and then put the device to sleep (test case #4), wake it back up and restart the activity - which is an option on the latest Garmin Edge devices. Strangely, if you then perform test case #5, the internal elapsed time counter reverts back to an accurate value.
I found that startTime does the right thing in all situations, so the best way to keep an accurate elapsedTime is simply to track the difference between the current time and the startTime, also applying "timezoneoffset" for the corner case that your activity crosses a timezone. Then accumulate moving time when currentSpeed exceeds a threshold. And stopped time is just elapsed - moving. But you need to put some logic in the "reset" and "start" handlers to zero out the moving and stop accumulators for time and distance.
In case this helps others, here is the set of test cases I used to assure my module reports accurate values under all these situations. These probably are most useful if you use Activity.getActivityInfo(): elapsedTime, timerTime, startTime in your code.
TEST CASES (Garmin Edge 820)
=================================================
NOTES:
- turn battery save mode on, turn auto-sleep on
- wait a bit of time between each action
- if testing while stopped, turn auto-pause off. better if moving (easier during a car ride)
- between each test case, discard activity, and cycle the power
1. Start Activity
2. Start, stop, restart
3. Start, Stop, Tap Power Button (sleeps?), Wake, Restart
4. Start, Stop, Hold Power Button, select Sleep, Wake, Restart
5. Start, Stop Hold Power Button, select Power Off, Power On, Restart
6. Start, Hold Power button 10 seconds to "crash", Power On, Restart
7. Start, goto Home screen, switch Profiles, switch profile back
8. Start, remove data field, add data field back
9. Start, stop, discard activity, restart without a power cycle
10. Start, allow to enter low power mode, wake back up
11. Start, stop, allow auto-sleep to engage, wake up, restart
12. Start, turn GPS sensor off, turn GPS sensor back on
12. 9. Start, stop, save activity, start new activity without a power cycle