Bump java lib versions in preparation for 1.9.2
[fw/altos] / altosdroid / app / src / main / java / org / altusmetrum / AltosDroid / TelemetryService.java
index 5dba24ba071897316143d6a2ab21cf0addf10fef..31616c825371d5e4f2f411343edf4c2464b622b0 100644 (file)
@@ -31,8 +31,9 @@ import android.content.Intent;
 import android.content.Context;
 import android.os.*;
 import android.widget.Toast;
+import androidx.core.app.NotificationCompat;
 
-import org.altusmetrum.altoslib_13.*;
+import org.altusmetrum.altoslib_14.*;
 
 public class TelemetryService extends Service implements AltosIdleMonitorListener {
 
@@ -132,7 +133,9 @@ public class TelemetryService extends Service implements AltosIdleMonitorListene
                        case MSG_SETFREQUENCY:
                                AltosDebug.debug("MSG_SETFREQUENCY");
                                s.telemetry_state.frequency = (Double) msg.obj;
-                               if (s.telemetry_state.connect == TelemetryState.CONNECT_CONNECTED) {
+                               if (s.idle_monitor != null) {
+                                       s.idle_monitor.set_frequency(s.telemetry_state.frequency);
+                               } else if (s.telemetry_state.connect == TelemetryState.CONNECT_CONNECTED) {
                                        try {
                                                s.altos_link.set_radio_frequency(s.telemetry_state.frequency);
                                                s.altos_link.save_frequency();
@@ -250,12 +253,11 @@ public class TelemetryService extends Service implements AltosIdleMonitorListene
        private void telemetry(AltosTelemetry telem) {
                AltosState      state;
 
-               if (telemetry_state.states.containsKey(telem.serial()))
-                       state = telemetry_state.states.get(telem.serial());
-               else
+               state = telemetry_state.get(telem.serial());
+               if (state == null)
                        state = new AltosState(new AltosCalData());
                telem.provide_data(state);
-               telemetry_state.states.put(telem.serial(), state);
+               telemetry_state.put(telem.serial(), state);
                telemetry_state.quiet = false;
                if (state != null) {
                        AltosPreferences.set_state(state,telem.serial());
@@ -268,8 +270,6 @@ public class TelemetryService extends Service implements AltosIdleMonitorListene
        private Message message() {
                if (telemetry_state == null)
                        AltosDebug.debug("telemetry_state null!");
-               if (telemetry_state.states == null)
-                       AltosDebug.debug("telemetry_state.states null!");
                return Message.obtain(null, AltosDroid.MSG_STATE, telemetry_state);
        }
 
@@ -410,7 +410,7 @@ public class TelemetryService extends Service implements AltosIdleMonitorListene
        }
 
        private void delete_serial(int serial) {
-               telemetry_state.states.remove((Integer) serial);
+               telemetry_state.remove(serial);
                AltosPreferences.remove_state(serial);
                send_to_clients();
        }
@@ -437,6 +437,8 @@ public class TelemetryService extends Service implements AltosIdleMonitorListene
                        telemetry_stop();
                        idle_monitor = new AltosIdleMonitor(this, altos_link, true, false);
                        idle_monitor.set_callsign(AltosPreferences.callsign());
+                       idle_monitor.set_frequency(telemetry_state.frequency);
+                       telemetry_state.idle_mode = true;
                        idle_monitor.start();
                        send_idle_mode_to_clients();
                }
@@ -449,6 +451,7 @@ public class TelemetryService extends Service implements AltosIdleMonitorListene
                        } catch (InterruptedException ie) {
                        }
                        idle_monitor = null;
+                       telemetry_state.idle_mode = false;
                        telemetry_start();
                        send_idle_mode_to_clients();
                }
@@ -614,9 +617,6 @@ public class TelemetryService extends Service implements AltosIdleMonitorListene
                for (int serial : serials) {
                        AltosState saved_state = AltosPreferences.state(serial);
                        if (saved_state != null) {
-                               if (telemetry_state.latest_serial == 0)
-                                       telemetry_state.latest_serial = serial;
-
                                AltosDebug.debug("recovered old state serial %d flight %d",
                                                 serial,
                                                 saved_state.cal_data().flight);
@@ -624,7 +624,7 @@ public class TelemetryService extends Service implements AltosIdleMonitorListene
                                        AltosDebug.debug("\tposition %f,%f",
                                                         saved_state.gps.lat,
                                                         saved_state.gps.lon);
-                               telemetry_state.states.put(serial, saved_state);
+                               telemetry_state.put(serial, saved_state);
                        } else {
                                AltosDebug.debug("Failed to recover state for %d", serial);
                                AltosPreferences.remove_state(serial);
@@ -657,7 +657,7 @@ public class TelemetryService extends Service implements AltosIdleMonitorListene
                                                : "";
 
                // Create notification to be displayed while the service runs
-               Notification notification = new Notification.Builder(this, channelId)
+               Notification notification = new NotificationCompat.Builder(this, channelId)
                                .setContentTitle(getText(R.string.telemetry_service_label))
                                .setContentText(getText(R.string.telemetry_service_started))
                                .setContentIntent(contentIntent)
@@ -709,7 +709,9 @@ public class TelemetryService extends Service implements AltosIdleMonitorListene
 
        /* AltosIdleMonitorListener */
        public void update(AltosState state, AltosListenerState listener_state) {
-               telemetry_state.states.put(state.cal_data().serial, state);
+               if (state != null)
+                       AltosDebug.debug("update call %s freq %7.3f", state.cal_data().callsign, state.frequency);
+               telemetry_state.put(state.cal_data().serial, state);
                telemetry_state.receiver_battery = listener_state.battery;
                send_to_clients();
        }