[PR #2200] [MERGED] Set push token state values to be user-specific #9567

Closed
opened 2026-04-11 02:23:53 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/bitwarden/android/pull/2200
Author: @trmartin4
Created: 11/19/2022
Status: Merged
Merged: 12/14/2022
Merged by: @trmartin4

Base: masterHead: SG-823-push-registrations-by-user


📝 Commits (10+)

  • 73f2800 Changed the current push token and last registration time to be user-based
  • b46dd1f Fixed compile error.
  • bfff633 Fixed interface implementation.
  • 63248e1 Fixed compile error for Android.
  • 5dadffc Merge branch 'master' into SG-823-push-registrations-by-user
  • e3040e9 Refactored to handle getting active user ID within state service
  • 8f68486 Refactored methods allow existing logic to handle getting the active user.
  • beb00ef Merge branch 'master' into SG-823-push-registrations-by-user
  • c444ed4 Updated to reconcile options.
  • f68dcbc Merge branch 'SG-823-push-registrations-by-user' of https://github.com/bitwarden/mobile into SG-823-push-registrations-by-user

📊 Changes

4 files changed (+22 additions, -24 deletions)

View changed files

📝 src/App/Services/MobileStorageService.cs (+0 -2)
📝 src/Core/Abstractions/IStateService.cs (+4 -4)
📝 src/Core/Constants.cs (+2 -2)
📝 src/Core/Services/StateService.cs (+16 -16)

📄 Description

Type of change

  • Bug fix
  • New feature development
  • Tech debt (refactoring, code cleanup, dependency upgrades, etc)
  • Build/deploy pipeline (DevOps)
  • Other

Objective

Currently, we run into problems with push notifications with multiple accounts on a mobile device. Namely, the second and subsequent accounts are not associated with a push token in Azure Notification Hub. This means they won't get push notifications.

To solve this, my approach was to change two of the state values concerning push notifications to be stored at the user level.

  • The first one is PushLastRegistrationDateKey. Setting this for each user ensures that each user will request a token at application startup if it has been more than a day since the last push registration, instead of only doing it for the first user to open the app.
  • The second one is PushCurrentToken. The "current" token represents the token that has been sent (or will be sent) to the back-end API to tie to the current user. Storing this at the user level allows us to update push tokens at the user level.

Code changes

src/Android/Services/AndroidPushNotificationService.cs: Updated methods to use the current active user to retrieve the token and set the registration time.
src/App/Pages/Settings/SettingsPage/SettingsPageViewModel.cs: Updated the settings menu used in DEBUG to show the user-specific last push registration date.
src/App/Pages/Vault/GroupingsPage/GroupingsPage.xaml.cs: Changed the code that runs on application launch to use the last push registration time for the current user. This will allow each individual user to send their own individual token when they run the application.
src/App/Services/MobileStorageService.cs: Removed the constant values for the constants that are now user-level.
src/App/Services/PushNotificationListenerService.cs: In OnRegisteredAsync(), which fires after the registration for push notifications, the method change to only set the last push registration date for the current user, since the update to /devices/{identifier}/token is only updating the token for that user.
src/Core/Abstractions/IStateService.cs: Updated the interface to reflect the fact that the two state values are now user-level.
src/Core/Constants.cs
src/Core/Services/StateService.cs: Updated the state definition to reflect the fact that the two state values are now user-level.

Before you submit

  • Please check for formatting errors (dotnet format --verify-no-changes) (required)
  • Please add unit tests where it makes sense to do so (encouraged but not required)
  • If this change requires a documentation update - notify the documentation team
  • If this change has particular deployment requirements - notify the DevOps team

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/bitwarden/android/pull/2200 **Author:** [@trmartin4](https://github.com/trmartin4) **Created:** 11/19/2022 **Status:** ✅ Merged **Merged:** 12/14/2022 **Merged by:** [@trmartin4](https://github.com/trmartin4) **Base:** `master` ← **Head:** `SG-823-push-registrations-by-user` --- ### 📝 Commits (10+) - [`73f2800`](https://github.com/bitwarden/android/commit/73f28001a6728722127262aa9f5257516130ed24) Changed the current push token and last registration time to be user-based - [`b46dd1f`](https://github.com/bitwarden/android/commit/b46dd1f4fb70bd7a0dde59f1167fc612cc91096d) Fixed compile error. - [`bfff633`](https://github.com/bitwarden/android/commit/bfff633a95aec5f1e49eeeac7e1d7cbff2af3a6c) Fixed interface implementation. - [`63248e1`](https://github.com/bitwarden/android/commit/63248e113d7b2e968ca2f8a2921d9ba7b3b187fa) Fixed compile error for Android. - [`5dadffc`](https://github.com/bitwarden/android/commit/5dadffcdf416ff05df1ab2f3dd02de7d9c7fe411) Merge branch 'master' into SG-823-push-registrations-by-user - [`e3040e9`](https://github.com/bitwarden/android/commit/e3040e9e1f18f54876b2a7962095f66f54374adb) Refactored to handle getting active user ID within state service - [`8f68486`](https://github.com/bitwarden/android/commit/8f6848600c0b2a8d4711f748324ad3c0f52aa6ee) Refactored methods allow existing logic to handle getting the active user. - [`beb00ef`](https://github.com/bitwarden/android/commit/beb00ef596b8dfa693beb22f6b4576ac9fc9ac61) Merge branch 'master' into SG-823-push-registrations-by-user - [`c444ed4`](https://github.com/bitwarden/android/commit/c444ed45c5949fbf334a05726eb5765cfc3a29dd) Updated to reconcile options. - [`f68dcbc`](https://github.com/bitwarden/android/commit/f68dcbc8edbceb482dc496f9a4d579d0f4a57fdc) Merge branch 'SG-823-push-registrations-by-user' of https://github.com/bitwarden/mobile into SG-823-push-registrations-by-user ### 📊 Changes **4 files changed** (+22 additions, -24 deletions) <details> <summary>View changed files</summary> 📝 `src/App/Services/MobileStorageService.cs` (+0 -2) 📝 `src/Core/Abstractions/IStateService.cs` (+4 -4) 📝 `src/Core/Constants.cs` (+2 -2) 📝 `src/Core/Services/StateService.cs` (+16 -16) </details> ### 📄 Description ## Type of change - [X] Bug fix - [ ] New feature development - [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc) - [ ] Build/deploy pipeline (DevOps) - [ ] Other ## Objective Currently, we run into problems with push notifications with multiple accounts on a mobile device. Namely, the second and subsequent accounts are not associated with a push token in Azure Notification Hub. This means they won't get push notifications. To solve this, my approach was to change two of the state values concerning push notifications to be stored at the user level. - The first one is `PushLastRegistrationDateKey`. Setting this for each user ensures that each user will request a token at application startup if it has been more than a day since the last push registration, instead of only doing it for the first user to open the app. - The second one is `PushCurrentToken`. The "current" token represents the token that has been sent (or will be sent) to the back-end API to tie to the current user. Storing this at the user level allows us to update push tokens at the user level. ## Code changes <!--Explain the changes you've made to each file or major component. This should help the reviewer understand your changes--> <!--Also refer to any related changes or PRs in other repositories--> [src/Android/Services/AndroidPushNotificationService.cs](https://github.com/bitwarden/mobile/compare/SG-823-push-registrations-by-user?expand=1#diff-5b4c20a27ab74adb487b94798fc08bc8b3167af2f716b99035f8a9c7731dbab6): Updated methods to use the current active user to retrieve the token and set the registration time. [src/App/Pages/Settings/SettingsPage/SettingsPageViewModel.cs](https://github.com/bitwarden/mobile/compare/SG-823-push-registrations-by-user?expand=1#diff-bce7881e23e99baec99687aac256ad3693130709ab596dfa2e4ff75550aca8e0): Updated the settings menu used in `DEBUG` to show the user-specific last push registration date. [src/App/Pages/Vault/GroupingsPage/GroupingsPage.xaml.cs](https://github.com/bitwarden/mobile/compare/SG-823-push-registrations-by-user?expand=1#diff-5405b2eb635ec5f08e97f08bc37a02138037a37c5bcb2f14805968d0c93176ba): Changed the code that runs on application launch to use the last push registration time for the current user. This will allow each individual user to send their own individual token when they run the application. [src/App/Services/MobileStorageService.cs](https://github.com/bitwarden/mobile/compare/SG-823-push-registrations-by-user?expand=1#diff-2251882deae3df7c0dc316404d76f08b562f3e20f990579e1dd8e8b63f9391b2): Removed the constant values for the constants that are now user-level. [src/App/Services/PushNotificationListenerService.cs](https://github.com/bitwarden/mobile/compare/SG-823-push-registrations-by-user?expand=1#diff-f341b17c68e50eb5721c6ede71f0b15be72ffa3a6deca14cf9f4c3e6d5c43efc): In `OnRegisteredAsync()`, which fires after the registration for push notifications, the method change to only set the last push registration date for the current user, since the update to `/devices/{identifier}/token` is only updating the token for that user. [src/Core/Abstractions/IStateService.cs](https://github.com/bitwarden/mobile/compare/SG-823-push-registrations-by-user?expand=1#diff-40fa428b50a59435a4892cd559f8fba6e5cfd6798a3239c853ff67107e142773): Updated the interface to reflect the fact that the two state values are now user-level. [src/Core/Constants.cs](https://github.com/bitwarden/mobile/compare/SG-823-push-registrations-by-user?expand=1#diff-94998af117f486ce85a16234b1bf36dd8c918651ff4d5c851927d203f5120e4e) [src/Core/Services/StateService.cs](https://github.com/bitwarden/mobile/compare/SG-823-push-registrations-by-user?expand=1#diff-c97a70998c406bbdf1908944e4a13377f0ec8180fecefbf2fdb88f58cbc54377): Updated the state definition to reflect the fact that the two state values are now user-level. ## Before you submit - Please check for formatting errors (`dotnet format --verify-no-changes`) (required) - Please add **unit tests** where it makes sense to do so (encouraged but not required) - If this change requires a **documentation update** - notify the documentation team - If this change has particular **deployment requirements** - notify the DevOps team --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-11 02:23:53 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/android#9567