]> git.gag.com Git - fw/altos/commitdiff
altosdroid: fix a connection retry having a null pointer
authorMike Beattie <mike@ethernal.org>
Tue, 28 Aug 2012 09:55:40 +0000 (21:55 +1200)
committerMike Beattie <mike@ethernal.org>
Tue, 28 Aug 2012 09:55:40 +0000 (21:55 +1200)
Signed-off-by: Mike Beattie <mike@ethernal.org>
altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java

index 10c2e26fdd26f87d5111cda99c0d2e986468b33b..1fa62d870f7944395c2d3ef4847869222b08cb4a 100644 (file)
@@ -161,8 +161,14 @@ public class TelemetryService extends Service {
                        mAltosBluetooth = new AltosBluetooth(device, mHandler);
                        setState(STATE_CONNECTING);
                } else {
                        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();
                        stopAltosBluetooth();
-                       mHandler.sendMessageDelayed(Message.obtain(null, MSG_CONNECT, device), 1000);
                }
        }
 
                }
        }