Fix preference loss when backup archives share a restore store - #519
Merged
Merged
Conversation
Collect the two main preference archives before restoring. When the default context is device-protected, or on pre-N devices, replace selected categories once and retain main preference values over legacy protected values. Parse before committing removals and surface failed preference restores. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8d01a009-639e-403d-8608-f127da2a4ddc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Restore treats
preferences.jsonandprotected_preferences.jsonas different stores and clears selected categories before applying each. With a device-protected default context (or before Android N),prefs()andprotectedPrefs()address the same store. A backup containing current main settings or text-expander entries and an empty or stale protected-preference snapshot can therefore lose restored data when the second snapshot clears that store.Fix
Collect both entries before applying them. Restore a shared store once, with main preferences taking precedence over legacy protected values regardless of ZIP order. Preserve separate-store behavior and selected-category filtering. Stage removals and puts in one editor, and check parsing and commit results so malformed preferences fail without first clearing existing values.
No archive-format, setting-category, UI, dependency, or unrelated feature changes.
Reproduction and verification
The regression uses real device-protected
SharedPreferencesand text-expander data, then restores main and empty protected snapshots. Removing alias handling makes the restored shortcuts disappear.RunTests; production build configuration is unchanged.The original reporter's exact archive was not inspected. This confirms a data-loss mechanism, not that all text-expander backups fail.