Skip to content

Use monotonic uptime clock for idle tracking and activity stop waits. - #2521

Merged
copybara-service[bot] merged 1 commit into
mainfrom
piper_1008793370
Oct 29, 2026
Merged

copybara-service[bot] merged 1 commit into
mainfrom
piper_1008793370

Conversation

@copybara-service

Copy link
Copy Markdown

Use monotonic uptime clock for idle tracking and activity stop waits.

MonitoringInstrumentation previously used System.currentTimeMillis() to record lastIdleTime when the main looper became idle and to bound the 2s polling loop in waitForActivitiesToComplete(). Because System.currentTimeMillis() follows wall-clock time, backward clock adjustments (such as an NTP sync on device) can cause waitForActivitiesToComplete() to block for the duration of the backward jump when an activity has not stopped yet, while forward clock jumps can cause the loop to exit before waiting the full 2s timeout. Wall-clock jumps also skew the lastIdleTime values reported when startActivitySync() times out.

Replace System.currentTimeMillis() with SystemClock.uptimeMillis() in MonitoringInstrumentation so that activity completion timeouts and looper idle timestamps are measured against a monotonic clock.

@copybara-service
copybara-service Bot force-pushed the piper_1008793370 branch 2 times, most recently from c481094 to b528bc3 Compare October 29, 2026 09:35
`MonitoringInstrumentation` previously used `System.currentTimeMillis()` to record `lastIdleTime` when the main looper became idle and to bound the 2s polling loop in `waitForActivitiesToComplete()`. Because `System.currentTimeMillis()` follows wall-clock time, backward clock adjustments (such as an NTP sync on device) can cause `waitForActivitiesToComplete()` to block for the duration of the backward jump when an activity has not stopped yet, while forward clock jumps can cause the loop to exit before waiting the full 2s timeout. Wall-clock jumps also skew the `lastIdleTime` values reported when `startActivitySync()` times out.

Replace `System.currentTimeMillis()` with `SystemClock.uptimeMillis()` in `MonitoringInstrumentation` so that activity completion timeouts and looper idle timestamps are measured against a monotonic clock.

PiperOrigin-RevId: 1009540928
@copybara-service
copybara-service Bot merged commit 43ce8c3 into main Oct 29, 2026
3 checks passed
@copybara-service
copybara-service Bot deleted the piper_1008793370 branch October 29, 2026 09:44
@mendozanathen1-stack

mendozanathen1-stack commented Oct 29, 2026 via email

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants