diff options
author | Keith Packard <keithp@keithp.com> | 2016-05-12 19:13:05 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2016-05-12 19:13:05 -0700 |
commit | b13037fad0905c5933d1ff579122ba1357b02eea (patch) | |
tree | 083d1950a161b05e29ee59da2b1a7de16f148bb5 /altoslib/AltosPreferences.java | |
parent | 2f4903f903223312d0a3a03dfd413059f24a07f5 (diff) |
altoslib: Store common frequencies in library version-independent form
Serializable Objects in java are very specific to the class being
serialized. As we bump the name of the library on a regular basis to
note API/ABI issues, this mean a saved a Serializable object in
the preferences database will fail to load across library version
upgrades.
The saved tracker state and saved common frequencies were the only
objects saved in this form; this patch adds infrastructure for writing
objects in a version-independent form, and then adds support for
saving frequencies in that form.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altoslib/AltosPreferences.java')
-rw-r--r-- | altoslib/AltosPreferences.java | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/altoslib/AltosPreferences.java b/altoslib/AltosPreferences.java index b853e944..f8101ce6 100644 --- a/altoslib/AltosPreferences.java +++ b/altoslib/AltosPreferences.java @@ -116,7 +116,7 @@ public class AltosPreferences { public final static String frequency_count = "COUNT"; public final static String frequency_format = "FREQUENCY-%d"; public final static String description_format = "DESCRIPTION-%d"; - public final static String frequenciesPreference = "FREQUENCIES"; + public final static String frequenciesPreference = "FREQUENCIES-1"; /* Units preference */ @@ -136,7 +136,17 @@ public class AltosPreferences { AltosFrequency[] frequencies = null; - frequencies = (AltosFrequency[]) backend.getSerializable(frequenciesPreference, null); + try { + AltosHashSet[] sets = AltosHashSet.array(backend.getString(frequenciesPreference,null)); + if (sets != null) { + frequencies = new AltosFrequency[sets.length]; + for (int i = 0; i < frequencies.length; i++) + frequencies[i] = new AltosFrequency(sets[i]); + } + + } catch (IOException ie) { + frequencies = null; + } if (frequencies == null) { if (backend.nodeExists(common_frequencies_node_name)) { @@ -165,6 +175,17 @@ public class AltosPreferences { return frequencies; } + public static void save_common_frequencies() { + try { + AltosHashSet[] sets = new AltosHashSet[common_frequencies.length]; + for (int i = 0; i < sets.length; i++) + sets[i] = common_frequencies[i].hashSet(); + backend.putString(frequenciesPreference, AltosHashSet.toString(sets)); + } catch (IOException ie) { + } + flush_preferences(); + } + public static int launcher_serial; public static int launcher_channel; @@ -512,8 +533,8 @@ public class AltosPreferences { public static void set_common_frequencies(AltosFrequency[] frequencies) { synchronized(backend) { common_frequencies = frequencies; - backend.putSerializable(frequenciesPreference, frequencies); - flush_preferences(); + + save_common_frequencies(); } } |