altosui: Remove the dregs of AltosDroid load-old-telem code
[fw/altos] / altoslib / AltosPreferences.java
index 0e91e4f475d5673bd4a21ef667d5147d7a84ddda..5fe810d7e8160c6300765fa9390f5e7b155a59cb 100644 (file)
@@ -41,6 +41,9 @@ public class AltosPreferences {
        /* log file format preference name */
        public final static String logfilePreferenceFormat = "LOGFILE-%d";
 
+       /* state preference name */
+       public final static String statePreferenceFormat = "STATE-%d";
+
        /* voice preference name */
        public final static String voicePreference = "VOICE";
 
@@ -157,6 +160,10 @@ public class AltosPreferences {
        public static int launcher_channel;
 
        public static void init(AltosPreferencesBackend in_backend) {
+
+               if (backend != null)
+                       return;
+
                backend = in_backend;
 
                /* Initialize logdir from preferences */
@@ -178,6 +185,8 @@ public class AltosPreferences {
 
                telemetry_rates = new Hashtable<Integer,Integer>();
 
+               logfiles = new Hashtable<Integer,File>();
+
                voice = backend.getBoolean(voicePreference, true);
 
                callsign = backend.getString(callsignPreference,"N0CALL");
@@ -327,6 +336,48 @@ public class AltosPreferences {
                }
        }
 
+       public static void set_state(int serial, AltosState state, AltosListenerState listener_state) {
+
+               ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+               try {
+                       ObjectOutputStream oos = new ObjectOutputStream(baos);
+
+                       AltosSavedState saved_state = new AltosSavedState(state, listener_state);
+                       oos.writeObject(saved_state);
+
+                       byte[] bytes = baos.toByteArray();
+
+                       synchronized(backend) {
+                               backend.putBytes(String.format(statePreferenceFormat, serial), bytes);
+                               flush_preferences();
+                       }
+               } catch (IOException ie) {
+               }
+       }
+
+       public static AltosSavedState state(int serial) {
+               byte[] bytes = null;
+
+               synchronized(backend) {
+                       bytes = backend.getBytes(String.format(statePreferenceFormat, serial), null);
+               }
+
+               if (bytes == null)
+                       return null;
+
+               ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+
+               try {
+                       ObjectInputStream ois = new ObjectInputStream(bais);
+                       AltosSavedState saved_state = (AltosSavedState) ois.readObject();
+                       return saved_state;
+               } catch (IOException ie) {
+               } catch (ClassNotFoundException ce) {
+               }
+               return null;
+       }
+
        public static void set_scanning_telemetry(int new_scanning_telemetry) {
                synchronized (backend) {
                        scanning_telemetry = new_scanning_telemetry;