diff --git a/library/std/src/sys/pal/unix/time.rs b/library/std/src/sys/pal/unix/time.rs index 328fe0bc9603f..add7abedb3482 100644 --- a/library/std/src/sys/pal/unix/time.rs +++ b/library/std/src/sys/pal/unix/time.rs @@ -275,7 +275,9 @@ pub struct Instant { impl Instant { #[cfg(target_vendor = "apple")] pub(crate) const CLOCK_ID: libc::clockid_t = libc::CLOCK_UPTIME_RAW; - #[cfg(not(target_vendor = "apple"))] + #[cfg(target_os = "android")] + pub(crate) const CLOCK_ID: libc::clockid_t = libc::CLOCK_BOOTTIME; + #[cfg(not(any(target_vendor = "apple", target_os = "android")))] pub(crate) const CLOCK_ID: libc::clockid_t = libc::CLOCK_MONOTONIC; pub fn now() -> Instant { // https://www.manpagez.com/man/3/clock_gettime/ @@ -289,6 +291,9 @@ impl Instant { // // Instant on macos was historically implemented using mach_absolute_time; // we preserve this value domain out of an abundance of caution. + // + // On Android, we use CLOCK_BOOTTIME because we want the duration between + // Instants to not be affected by suspends. Instant { t: Timespec::now(Self::CLOCK_ID) } }