altosdroid: Move pause before reopening bluetooth into connec thread
[fw/altos] / altosdroid / src / org / altusmetrum / AltosDroid / TelemetryService.java
index e7f958b9e4c08f173a3116b59019ec1720099203..ed7b75a1ef1ab470ad4ecc39ed5cdeb25aa635f9 100644 (file)
@@ -46,7 +46,7 @@ import android.location.LocationManager;
 import android.location.LocationListener;
 import android.location.Criteria;
 
-import org.altusmetrum.altoslib_6.*;
+import org.altusmetrum.altoslib_7.*;
 
 
 public class TelemetryService extends Service implements LocationListener {
@@ -341,12 +341,6 @@ public class TelemetryService extends Service implements LocationListener {
                BluetoothDevice device = bluetooth_adapter.getRemoteDevice(address.address);
 
                disconnect(false);
-               if (pause) {
-                       try {
-                               Thread.sleep(4000);
-                       } catch (InterruptedException e) {
-                       }
-               }
                this.address = address;
                if (D) Log.d(TAG, String.format("start_altos_bluetooth(): Connecting to %s (%s)", device.getName(), device.getAddress()));
                altos_link = new AltosBluetooth(device, handler);
@@ -450,12 +444,14 @@ public class TelemetryService extends Service implements LocationListener {
                // Move us into the foreground.
                startForeground(NOTIFICATION, notification);
 
-               String  action = intent.getAction();
+               if (intent != null) {
+                       String  action = intent.getAction();
 
-               if (action.equals(AltosDroid.ACTION_BLUETOOTH)) {
-                       DeviceAddress address = AltosDroidPreferences.active_device();
-                       if (address != null && !address.address.startsWith("USB"))
-                               start_altos_bluetooth(address, false);
+                       if (action.equals(AltosDroid.ACTION_BLUETOOTH)) {
+                               DeviceAddress address = AltosDroidPreferences.active_device();
+                               if (address != null && !address.address.startsWith("USB"))
+                                       start_altos_bluetooth(address, false);
+                       }
                }
 
                // We want this service to continue running until it is explicitly