Closed Bug 2070591 Opened 2 months ago Closed 2 months ago

Avoid recomputing the privacy report notification schedule on every app resume

Categories

(Firefox for Android :: Experimentation and Telemetry, task)

All
Android
task

Tracking

()

RESOLVED FIXED
159 Branch
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").

Assignee: nobody → rebecatudor273

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.

Pushed by rtudor@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/ec5f022f401a https://hg.mozilla.org/integration/autoland/rev/47262521ae9f [experiment] Avoid recomputing the privacy report notification schedule on every app resume r=android-reviewers,twhite
Status: NEW → RESOLVED
Closed: 2 months ago
Resolution: --- → FIXED
Target Milestone: --- → 159 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: