Avoid recomputing the privacy report notification schedule on every app resume
Categories
(Firefox for Android :: Experimentation and Telemetry, task)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox159 | --- | fixed |
People
(Reporter: towhite, Assigned: rebecatudor273)
References
Details
(Whiteboard: [android-activation-trust] [fxdroid])
Attachments
(1 external file)
PrivacyReportNotificationScheduler.onResume() calls updatePrivacyReportNotificationWorker() on every resume of its host, which calls PrivacyReportNotificationWorker.schedule() unconditionally whenever tracking protection, the feature flag, and the notification channel are all enabled.
schedule() always recomputes the initial delay through several ZonedDateTime/Instant/LocalTime conversions (initialNotificationTimeMillis() and calculateNotificationTimeMillis()) and builds a new PeriodicWorkRequest, even though enqueueUniquePeriodicWork() is called with ExistingPeriodicWorkPolicy.KEEP, which discards the newly built request whenever work is already registered under PRIVACY_REPORT_NOTIFICATION_WORK_NAME.
So after the first successful scheduling, every later onResume — a lifecycle callback that fires very frequently — repeats this date math and object construction for no effect.
One approach: short-circuit schedule() with an in-memory "already scheduled" flag, reset in cancel(), so the work is skipped once WorkManager already has the periodic work registered.
Found during code review of commit de0e82ccac4a ("Bug 2065551 - Schedule the privacy report notification for noon").
Updated•2 months ago
|
| Assignee | ||
Updated•2 months ago
|
| Assignee | ||
Comment 1•2 months ago
|
||
Tracks whether the worker has already been scheduled.
This is only an in-memory optimization to avoid repeatedly performing the scheduling
calculations when the host resumes. WorkManager remains the source of truth for the
actual scheduled work.
Description
•