Component(s): sdk, common, bootstrap
Environment: Cross-platform (JVM & Android)
Summary
Clock.getDefault() effectively hardwires System.nanoTime(). On Android this ignores deep sleep, leading to incorrect elapsed-time semantics for features like timeouts and background durations. There’s no easy global way to swap the default clock per platform.
Expected behavior
The SDK should choose a platform-appropriate default clock and allow an explicit override:
- JVM/server:
System.nanoTime() is fine for monotonic elapsed durations.
- Android: prefer
SystemClock.elapsedRealtimeNanos() (includes deep sleep).
Actual behavior
Users cannot globally configure the default clock. Each component must be hand-wired (if possible), which is fragile and easy to miss.
Proposed change
Introduce a lightweight, platform-aware ClockProvider SPI with discovery (optimized for Android, similar in spirit to kotlinx.coroutines’ FastServiceLoader):
Component(s):
sdk,common,bootstrapEnvironment: Cross-platform (JVM & Android)
Summary
Clock.getDefault()effectively hardwiresSystem.nanoTime(). On Android this ignores deep sleep, leading to incorrect elapsed-time semantics for features like timeouts and background durations. There’s no easy global way to swap the default clock per platform.Expected behavior
The SDK should choose a platform-appropriate default clock and allow an explicit override:
System.nanoTime()is fine for monotonic elapsed durations.SystemClock.elapsedRealtimeNanos()(includes deep sleep).Actual behavior
Users cannot globally configure the default clock. Each component must be hand-wired (if possible), which is fragile and easy to miss.
Proposed change
Introduce a lightweight, platform-aware
ClockProviderSPI with discovery (optimized for Android, similar in spirit to kotlinx.coroutines’ FastServiceLoader):