Skip to content

fix: sync notification permission changes on app resume - #4

Merged
mohn93 merged 1 commit into
mainfrom
fix/notification-permission-resume-sync
Jul 21, 2026
Merged

fix: sync notification permission changes on app resume#4
mohn93 merged 1 commit into
mainfrom
fix/notification-permission-resume-sync

Conversation

@mohn93

@mohn93 mohn93 commented Jul 21, 2026

Copy link
Copy Markdown
Member

Problem

On devices that do not kill the app when the notification permission is toggled in system settings (e.g. Samsung), a permission change did not update the device's status in PushFire. Most visibly, re-granting the permission kept the device showing as denied.

Root cause

The app reconciles permission changes on resume via checkAndHandlePermissionStatusChange(). It saved the new OS permission status to pushfire_last_permission_status before calling registerDevice(). registerDevice() compares the device's value against that saved status to decide whether to PATCH the server — so it saw "no change" and skipped the update. The server kept its stale value. (On a Pixel/emulator the OS kills the app on the toggle, so it comes back through the cold-start path, which registers directly and works — hence the intermittency.)

Fix

Stop pre-writing the last-known status in checkAndHandlePermissionStatusChange(). registerDevice() now detects the change and PATCHes, and persists the status only after a successful sync (so a failed sync retries on the next resume instead of being lost). The developer opt-out branch (setNotificationEnabled(false)) still records the status itself, so an OS re-grant does not override the opt-out.

Tests

  • device_service_resume_permission_repro_test.dart — resume path vs cold-start path for the same permission change (the resume assertion failed before this fix).
  • device_service_permission_resume_scenarios_test.dart — the reported Samsung scenarios: revoke-on-resume, re-grant-on-resume (restore), opt-out survives re-grant, no-change no-op, no duplicate PATCH on repeat resume.

Full suite: 389 tests passing. flutter analyze clean (no new issues).

Release

Patch bump 0.3.0 -> 0.3.1; CHANGELOG updated.

The resume-time reconciliation (checkAndHandlePermissionStatusChange) saved
the new OS permission status before registerDevice compared against it, so
registerDevice saw no change and skipped the server update. On devices that
do not kill the app on a permission toggle (e.g. Samsung), this left the
device stuck at its previous pushNotificationEnabled value in PushFire.

Stop pre-writing the last-known status; registerDevice now detects the
change, PATCHes, and persists the status only after a successful sync (so a
failed sync retries on the next resume). Developer opt-out via
setNotificationEnabled(false) still survives an OS re-grant.

Adds regression coverage for the resume vs cold-start paths and the reported
Samsung scenarios.
@mohn93
mohn93 merged commit c1369b9 into main Jul 21, 2026
2 of 3 checks passed
@mohn93
mohn93 deleted the fix/notification-permission-resume-sync branch July 21, 2026 18:26
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.

1 participant