Repository navigation
fix(android): Replace deprecated SharedPreferences API - #23693
Conversation
Android.Preferences.PreferenceManager.GetDefaultSharedPreferences is deprecated since API 29. Replace it with the explicit Context.GetSharedPreferences(<package>_preferences, MODE_PRIVATE), which is byte-for-byte the store the deprecated API resolves to internally, so existing users' persisted LocalSettings/RoamingSettings are preserved on upgrade. Adds no new dependency. fixes #1833 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23693/wasm-skia-net9/index.html |
|
Tick the box to add this pull request to the merge queue (same as
|
|
@Xiaoy312 For existing apps, will preserving already existing preferences require a migration? If yes, we should some common approach, as I have a very similar change for iOS as well - #23705 . Currently that PR migrates automatically on start, but I think we might want to have some helper API users can use when they know they are going to migrate existing pre-7 apps |
|
Nope, there is nothing to do/change on the consumer side. We just shuffled the api used, but they are still pointing to the same physical file. |
GitHub Issue: closes #1833
PR Type:
🐞 Bugfix
What changed? 🚀
On Android,
ApplicationDataContainerbacksApplicationData.Current.LocalSettings/RoamingSettingswith AndroidSharedPreferences. It obtained the store viaAndroid.Preferences.PreferenceManager.GetDefaultSharedPreferences(context), which has been deprecated since API 29 (Android 10) — issue #1833.This replaces that call with the explicit, non-deprecated equivalent:
This is byte-for-byte the store the deprecated API resolves to internally — Android's
getDefaultSharedPreferences(context)is implemented ascontext.getSharedPreferences(context.getPackageName() + "_preferences", MODE_PRIVATE). Consequences:<package>_preferences.xml) and all keys are unchanged, so existing users' persisted settings survive an app upgrade — no silent orphaning.LocalSettingsandRoamingSettingsare covered, since both resolve to the sameSharedPreferencesPropertySet.AndroidX.Preferencealternative was intentionally avoided; the explicit call needs nothing beyondAndroid.Content(already imported).The now-unused
using Android.Preferences;was removed.Validation:
Uno.UWPnet10.0-androidtarget builds clean — 0 warnings, 0 errors.Given_ApplicationDataContainerruntime-test suite exercises set/get/remove/enumerate through the changedSharedPreferencesPropertySeton native Android. No new test was added — the swap is a framework-contract equivalence, so continuity does not require a dedicated test.PR Checklist ✅
Given_ApplicationDataContainer; no new test needed for a like-for-like API swap.Screenshots Compare Test Runresults. — n/a, no visual change.CreatePreferences()is a private implementation detail; no public API surface changes.