Description
I tried this code on Android:
let now = Instant::now();
// Wait some hours
now.elapsed().as_secs()
I expected to see this happen: Get some hours as a result
Instead, this happened: Got only minutes because the time while the process is sleeping / the app is "dozing" is not counted.
Nice explanation from mbrubeck (https://users.rust-lang.org/t/std-now-with-android/41774):
Instant::now()
on Android (and other Linux platforms) is currently implemented using libc::clock_gettime(CLOCK_MONOTONIC)
. Apparently this clock does not advance while the CPU is in deep sleep modes ("Doze"). This is also how Android's SystemClock.uptimeMillis
method works.
Android also offers a SystemClock.elapsedRealTime
method, which seems to be implemented using an Android-specific ioctl . Perhaps it would be possible to migrate the Rust standard library to use this call on Android, if there are no trade-offs in precision.