]> git.gag.com Git - fw/altos/blobdiff - altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java
altosdroid: whitespace
[fw/altos] / altosdroid / src / org / altusmetrum / AltosDroid / TelemetryService.java
index 10c2e26fdd26f87d5111cda99c0d2e986468b33b..cd47c6f9587b0e833b9d7a455327a7860f819603 100644 (file)
@@ -66,8 +66,8 @@ public class TelemetryService extends Service {
        final Messenger mMessenger = new Messenger(mHandler); // Target we publish for clients to send messages to IncomingHandler.
 
        // Name of the connected device
-       private BluetoothDevice device = null;
-       private AltosBluetooth mAltosBluetooth = null;
+       private BluetoothDevice device           = null;
+       private AltosBluetooth  mAltosBluetooth  = null;
        private TelemetryReader mTelemetryReader = null;
 
        // internally track state of bluetooth connection
@@ -161,8 +161,14 @@ public class TelemetryService extends Service {
                        mAltosBluetooth = new AltosBluetooth(device, mHandler);
                        setState(STATE_CONNECTING);
                } else {
+                       // This is a bit of a hack - if it appears we're still connected, we treat this as a restart.
+                       // So, to give a suitable delay to teardown/bringup, we just schedule a resend of a message
+                       // to ourselves in a few seconds time that will ultimately call this method again.
+                       // ... then we tear down the existing connection.
+                       // We do it this way around so that we don't lose a reference to the device when this method
+                       // is called on reception of MSG_CONNECT_FAILED in the handler above.
+                       mHandler.sendMessageDelayed(Message.obtain(null, MSG_CONNECT, device), 3000);
                        stopAltosBluetooth();
-                       mHandler.sendMessageDelayed(Message.obtain(null, MSG_CONNECT, device), 1000);
                }
        }