screentime: fix week stats double-count at midnight boundary
- Commit
39fbd7ee1930109e91992d83d62acbc2e53c0b75- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-17 02:44 UTC (19 days ago)
- Parents
d687bc3
The week tests seeded UsageStats exactly at midnight. Robolectric's ShadowUsageStatsManager connects timestamp ranges that merely touch at an endpoint, so the previous day's week-loop query also returned today's stats and per-app totals doubled whenever today was not Monday in the local timezone (CI runs UTC). Offset the seeded range one minute into the day. Assertions unchanged. Verified: TZ=UTC :screentime:testDevUnitTest UsageHistoryDeepTest green.
Diff
screentime/src/test/java/com/vayunmathur/screentime/platform/UsageHistoryDeepTest.kt
diff --git a/screentime/src/test/java/com/vayunmathur/screentime/platform/UsageHistoryDeepTest.kt b/screentime/src/test/java/com/vayunmathur/screentime/platform/UsageHistoryDeepTest.ktindex eb8fa7f073..e84c06c71e 100644--- a/screentime/src/test/java/com/vayunmathur/screentime/platform/UsageHistoryDeepTest.kt+++ b/screentime/src/test/java/com/vayunmathur/screentime/platform/UsageHistoryDeepTest.kt@@ -35,7 +35,12 @@ class UsageHistoryDeepTest { private fun addStats(pkg: String, day: LocalDate, foregroundMs: Long) { val stats = ShadowUsageStatsManager.UsageStatsBuilder.newBuilder() .setPackageName(pkg)- .setFirstTimeStamp(dayStart(day))+ // One minute into the day, not exactly at midnight: the shadow's+ // queryUsageStats connects ranges that merely touch at an endpoint,+ // so a midnight-aligned range is also returned for the previous+ // day's query and the week loop would count it twice (which day+ // that is depends on the local timezone's current weekday).+ .setFirstTimeStamp(dayStart(day) + 60_000) .setLastTimeStamp(dayStart(day) + 3_600_000) .setTotalTimeInForeground(foregroundMs) .build()