fix: retrieve push token on startup when notification permission already granted#2622
Open
tp26610 wants to merge 1 commit intoOneSignal:mainfrom
Open
Conversation
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
a0979470582
approved these changes
Apr 23, 2026
melody0000tw
approved these changes
Apr 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
One Line Summary
Fix push subscription stuck at
NO_PERMISSIONafter 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 — becauseNotificationsManager.permissionis initialized to the correct value oftrue, sooldPermission == newPermissionandsetPermissionStatusAndFire()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 atNO_PERMISSIONindefinitely → user cannot receive push notifications even though system permission is granted.Fixes #2621
Scope
Only affects
DeviceRegistrationListener.start(). The change adds one conditional call toretrievePushTokenAndUpdateSubscription()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
DeviceRegistrationListenercoversonNotificationPermissionChangeandonModelReplaced. A new test case for thestart()path whenpermission = truewould 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):
getOptedInAsync()returnstruegetOptedInAsync()returnsfalseindefinitelygetOptedInAsync()returnstruewithin a few secondsAffected code checklist
Checklist
Overview
Testing
Final pass