Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android SecureStorage: Stop caching shared preferences instance to fix RemoveAll #20445

Merged
merged 1 commit into from
Feb 9, 2024

Conversation

Redth
Copy link
Member

@Redth Redth commented Feb 8, 2024

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

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.
@Redth Redth requested a review from a team as a code owner February 8, 2024 14:38
@mattleibow mattleibow enabled auto-merge (squash) February 8, 2024 15:00
@jsuarezruiz jsuarezruiz added platform/android 🤖 area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info labels Feb 9, 2024
@Redth Redth disabled auto-merge February 9, 2024 15:15
@rmarinho rmarinho merged commit bbbbfe7 into main Feb 9, 2024
42 of 47 checks passed
@rmarinho rmarinho deleted the dev/redth/android-secure-storage-remove-fix branch February 9, 2024 15:17
@github-actions github-actions bot locked and limited conversation to collaborators Mar 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Android: SecureStorage Adding a value after calling RemoveAll() will not persist the value
5 participants