std::time::Instant::now() with Android

We are building the backend for (among others) an Android application.

When using std::time::Instant on Android, only some minutes are reported when it actually ran for an hour; probably the time while the process is sleeping / the app is "dozing" is not counted.

Is this on purpose or a bug?

(seems to be possible to use SystemTime::now() instead)

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. 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.

2 Likes

So, shall I make a request for this at internals or GitHub?

A GitHub issue would probably be best.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.