Android SecureStorage: Stop caching shared preferences instance to fix RemoveAll #20445
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.
It appears that reusing the shared preferences instance sometimes causes changes to not be properly committed to disk as the instance is not disposed in some cases before the app is torn down (eg: force close).
Caching isn't really necessary here anyways as the underlying android preference manager does its own layer of caching (so we are just paying the interop tax to get a 'new' instance here).
The simplest fix is to stop caching which is the real content of this change. We don't cache in the regular preferences API where we use shared preferences and the issue does not seem to exist there.
This is an alternate PR to #20293 which in a round about way also achieves the same result, but I think we should be more concise with disposing of the instance, and doing it in not just the case where we clear all keys.
Issues Fixed
Fixes #19983