[PR #3029] [PM-6428] Changed Android LegacySecureStorage from Task.FromResult to Task.Run to mimic the Microsoft.Maui.Storage.SecureStorage implementation which ensures there's always a Task #3974

Closed
opened 2025-11-26 23:39:08 -06:00 by GiteaMirror · 0 comments
Owner

Original Pull Request: https://github.com/bitwarden/android/pull/3029

State: closed
Merged: Yes


Type of change

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

Objective

Execution flow seems different between LegacySecureStorage and Microsoft.Maui.Storage.SecureStorage
The obvious difference between these two is that for Android LegacySecureStorage uses Task.FromResult and Microsoft.Maui.Storage.SecureStorage uses Task.Run.
If I recall correctly Task.Run ensures we have an Async Task and Task.FromResult doesn't. Taking into account that AndroidKeyStore is synchronous I suspect everything will be synchronous with Task.FromResult which could result in the behavior we have.
The downside is that Task.Run is likely less performant but it is also what MAUI Team decided to use so I would hope it's fine.

What do you think @fedemkr ?
Do you think there could be scenarios where the "order" of execution is not respected even with Task.Run? (although so far it has worked)

Code changes

Changed Android LegacySecureStorage from Task.FromResult to Task.Run to mimic the Microsoft.Maui.Storage.SecureStorage implementation which ensures there's always a Task.
This change was only done for Set and Get operations on Android. Other operations and iOS likely don't need this.

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
**Original Pull Request:** https://github.com/bitwarden/android/pull/3029 **State:** closed **Merged:** Yes --- ## Type of change - [x] Bug fix - [ ] New feature development - [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc) - [ ] Build/deploy pipeline (DevOps) - [ ] Other ## Objective Execution flow seems different between `LegacySecureStorage` and `Microsoft.Maui.Storage.SecureStorage` The obvious difference between these two is that for Android `LegacySecureStorage` uses `Task.FromResult` and `Microsoft.Maui.Storage.SecureStorage` uses `Task.Run`. If I recall correctly `Task.Run` ensures we have an Async Task and `Task.FromResult` doesn't. Taking into account that AndroidKeyStore is synchronous I suspect everything will be synchronous with `Task.FromResult` which could result in the behavior we have. The downside is that `Task.Run` is likely less performant but it is also what MAUI Team decided to use so I would hope it's fine. What do you think @fedemkr ? Do you think there could be scenarios where the "order" of execution is not respected even with Task.Run? (although so far it has worked) ## Code changes Changed Android `LegacySecureStorage` from `Task.FromResult` to `Task.Run` to mimic the `Microsoft.Maui.Storage.SecureStorage` implementation which ensures there's always a Task. This change was only done for Set and Get operations on Android. Other operations and iOS likely don't need this. ## 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
GiteaMirror added the pull-request label 2025-11-26 23:39:08 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/android#3974