Skip to content

Conversation

@JorgeMucientes
Copy link
Contributor

@JorgeMucientes JorgeMucientes commented Jan 22, 2026

Closes WOOMOB-2042

Description

This PR adds a fallback mechanism to the WP.com push notification registration system when the Woo Core push notification registration fails. It also refactors the push notification registration status logic to track both registration systems simultaneously.

Changes

Push Notification Registration Status Refactoring:

  • Updated PushNotificationRegistrationStatus to return a more granular status instead of a simple binary state:
    • WOO_REGISTERED - Only registered in Woo Core system
    • WPCOM_REGISTERED - Only registered in WP.com system
    • REGISTERED_IN_BOTH - Registered in both systems
    • UNREGISTERED - Not registered in either system
  • Removed dependency on FeatureFlag.WOO_PUSH_NOTIFICATIONS_SYSTEM for status checks, now evaluating both systems independently

Fallback Mechanism:

  • When Woo Core push token registration fails, the app now automatically falls back to the legacy WP.com registration system
  • Added logging to track registration failures and fallback behavior

Test Steps

Case 1: Register into WP.com as usual

  1. Clean install of the app with WOO_PUSH_NOTIFICATIONS_SYSTEM -> false
  2. Log in using WP.com credentials .
  3. Check use is registered as normal in WP.com system.
  4. Check PN works as expected in WP.com sytem
  5. Expected logs:
Current PN registration status: UNREGISTERED
Updated push notification registration status: UNREGISTERED
Current PN registration status: UNREGISTERED
Registering FCM token in WPCOM instance: cvhs71fwRy-X7FPK_KZRq_:APA91bE...
Updated push notification registration status: WPCOM_REGISTERED

Case 2:

  1. Enable WOO_PUSH_NOTIFICATIONS_SYSTEM feature flag in the code
  2. Build and launch the app. See the following logs attempting to register in Woo Core but failing to do so because the Woo Core version of the plugin doesn't support it. After failing to register in Woo core system, we don't fallback to WP.com as the user is already registered there.
Current PN registration status: WPCOM_REGISTERED
Registering FCM token in Woo Core instance: cvhs71fwRy-X7FPK_KZRq_:APA91bE-YQUAAh8FZ-jwofbVJPOM
Woo Core push token registration failed:No route was found matching the URL and request method.
Updated push notification registration status: WPCOM_REGISTERED
  1. Send the app to the background and restart it. You'll see that every time we do this we re-attempt to register the user in Woo Core, which will fail, and because of that re-attempt to register them in WP.com despite being registered already. We are discussion different options to mitigate this over Slack. Whatever solution we come up with for this will be addressed in a different PR.

Case 3:

  1. Reusing the same log in session from Case 2, switch to a site that has Woo Core plugin version supporting new PN
  2. See how the site is successfully registered in the new Woo Core system. Expected logs:
Current PN registration status: WPCOM_REGISTERED
Registering FCM token in Woo Core instance: 
WPCom notifications disabled for site 251754054
Updated push notification registration status: REGISTERED_IN_BOTH

Missing tasks to address

  • Mitigate attempting to register in Woo PN system every time the app is resumed from background. Solution TBD

  • I have considered if this change warrants release notes and have added them to RELEASE-NOTES.txt if necessary. Use the "[Internal]" label for non-user-facing changes.

When the Woo Core push token registration fails, the app will now fall back to the legacy WPCom registration system. This ensures that users can still receive push notifications even if the new registration method encounters an error.
This commit refactors the push notification registration status logic to account for both WPCom and Woo Core systems simultaneously.

The `PushNotificationRegistrationStatus` class is updated to return a more detailed status: `WOO_REGISTERED`, `WPCOM_REGISTERED`, `REGISTERED_IN_BOTH`, or `UNREGISTERED`.

The `RegisterDevice` use case is enhanced to use this new detailed status. It now triggers registration with the Woo Core system if the device is only registered with WPCom and the feature flag is enabled, ensuring a smoother transition between notification systems. Additional logging has also been added to improve traceability.
@JorgeMucientes JorgeMucientes added the feature: notifications Related to notifications or notifs. label Jan 22, 2026
@JorgeMucientes JorgeMucientes added this to the 24.1 milestone Jan 22, 2026
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Jan 22, 2026

📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
App NameWooCommerce-Wear Android
Platform⌚️ Wear OS
FlavorJalapeno
Build TypeDebug
Commite51ef67
Direct Downloadwoocommerce-wear-prototype-build-pr15238-e51ef67.apk

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Jan 22, 2026

📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.

App NameWooCommerce Android
Platform📱 Mobile
FlavorJalapeno
Build TypeDebug
Commite51ef67
Direct Downloadwoocommerce-prototype-build-pr15238-e51ef67.apk

@codecov-commenter
Copy link

codecov-commenter commented Jan 22, 2026

Codecov Report

❌ Patch coverage is 89.47368% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 38.70%. Comparing base (8702a68) to head (e51ef67).
⚠️ Report is 25 commits behind head on trunk.

Files with missing lines Patch % Lines
...merce/android/notifications/push/RegisterDevice.kt 81.81% 1 Missing and 1 partial ⚠️
...d/notifications/push/PushNotificationRepository.kt 90.00% 0 Missing and 1 partial ⚠️
...merce/android/ui/sitepicker/SitePickerViewModel.kt 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              trunk   #15238      +/-   ##
============================================
+ Coverage     38.69%   38.70%   +0.01%     
- Complexity    10550    10563      +13     
============================================
  Files          2194     2194              
  Lines        124969   124984      +15     
  Branches      17299    17305       +6     
============================================
+ Hits          48353    48379      +26     
+ Misses        71720    71708      -12     
- Partials       4896     4897       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

The `PushNotificationRegistrationStatus` class no longer directly depends on `SelectedSite` to get the current site ID. Instead, the `siteId` is now passed as an argument to its `invoke` method.

This change simplifies the `PushNotificationRegistrationStatus` class and makes its dependencies more explicit. Classes that use it, such as `RegisterDevice` and `DashboardViewModel`, are updated to provide the `siteId` when checking the push notification registration status.
When Woo Core push notification registration fails, the system attempts to fall back to the WPCom registration system. This change prevents the fallback from occurring if the device is already registered with the WPCom system.
Comment on lines +73 to +75
if (!isWpComPushRegistered()) {
registerPushTokenInWpComSystem(token)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is something I forgot in my prior PR. If user is already WP.com registered avoid registering again.


trackLoginEvent(currentStep = UnifiedLoginTracker.Step.SUCCESS)
appPrefsWrapper.removeLoginSiteAddress()
registerDevice(RegisterDevice.Mode.FORCEFULLY)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This fixes several issues:

  • Not registering automatically in Woo Core system when first time loggin in, because the site was not selected yet.
  • Automatically trigger PN token registration when switching sites.

@JorgeMucientes JorgeMucientes marked this pull request as ready for review January 23, 2026 10:33
@JorgeMucientes JorgeMucientes requested a review from irfano January 23, 2026 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature: notifications Related to notifications or notifs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants