Skip to content

Android: Instant not advancing while the screen is off #71860

Open
@Hocuri

Description

@Hocuri

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-timeArea: TimeC-bugCategory: This is a bug.O-androidOperating system: AndroidT-libsRelevant to the library team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions