Skip to content

fix: retrieve push token on startup when notification permission already granted#2622

Open
tp26610 wants to merge 1 commit intoOneSignal:mainfrom
tp26610:fix/subscription-stuck-no-permission-on-reinstall
Open

fix: retrieve push token on startup when notification permission already granted#2622
tp26610 wants to merge 1 commit intoOneSignal:mainfrom
tp26610:fix/subscription-stuck-no-permission-on-reinstall

Conversation

@tp26610
Copy link
Copy Markdown

@tp26610 tp26610 commented Apr 23, 2026

Description

One Line Summary

Fix push subscription stuck at NO_PERMISSION after reinstall when notification permission is already granted.

Details

Motivation

After reinstall or app data clear, the push subscription is created fresh with status = NO_PERMISSION. If the system notification permission was already granted before reinstall, no permission-change event fires on startup — because NotificationsManager.permission is initialized to the correct value of true, so oldPermission == newPermission and setPermissionStatusAndFire() never emits an event.

The onModelReplaced(HYDRATE) path only fires when the config cache is invalid, so it cannot be relied on either.

Result: retrievePushTokenAndUpdateSubscription() is never called → subscription stays stuck at NO_PERMISSION indefinitely → user cannot receive push notifications even though system permission is granted.

Fixes #2621

Scope

Only affects DeviceRegistrationListener.start(). The change adds one conditional call to retrievePushTokenAndUpdateSubscription() which is already called from two other places in the same class. No behaviour changes when permission is not granted at startup.

Testing

Unit testing

No unit tests added — the existing test suite for DeviceRegistrationListener covers onNotificationPermissionChange and onModelReplaced. A new test case for the start() path when permission = true would be the appropriate addition, but I don't have a local Android build environment to verify it compiles and passes CI.

Manual testing

Reproduced with react-native-onesignal 5.4.2 (Android SDK 5.7.7) on a Pixel device (Android 14):

  1. Install app → grant notification permission → confirm getOptedInAsync() returns true
  2. Clear app data via Settings → reopen app (permission still granted)
  3. Without fix: getOptedInAsync() returns false indefinitely
  4. With fix: getOptedInAsync() returns true within a few seconds

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
  • I have reviewed this PR myself, ensuring it meets each checklist item

After reinstall or app data clear, the push subscription is created fresh
with status = NO_PERMISSION. However, if the system notification permission
was already granted, no permission-change event fires (oldPermission ==
newPermission == true), and onModelReplaced(HYDRATE) only fires when the
config cache is invalid.

As a result, retrievePushTokenAndUpdateSubscription() is never called and
the subscription stays stuck at NO_PERMISSION indefinitely.

Fix: call retrievePushTokenAndUpdateSubscription() eagerly in start() when
permission is already granted, so the FCM token is retrieved and the
subscription status is updated to SUBSCRIBED regardless of whether a
permission-change or config-hydration event fires.

Fixes: OneSignal#2621
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

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.

Subscription stuck at NO_PERMISSION after reinstall when notification permission already granted

3 participants