summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2015-05-26 23:02:43 -0700
committerKeith Packard <keithp@keithp.com>2015-05-26 23:02:43 -0700
commitbca342577740a9d04b8419ecadcff582e77f1e61 (patch)
treee25f31194c2d3e0c8ed99635e73a9841ac8bb41d
parent7975d088a4ac44c0943134fa41d0e3b88f50b98f (diff)
altosdroid: Move pause before reopening bluetooth into connec thread
This avoids stalling the UI while waiting for TBT to boot. Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r--altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java21
-rw-r--r--altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java18
2 files changed, 22 insertions, 17 deletions
diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java
index e68b1885..d506ff59 100644
--- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java
+++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java
@@ -41,19 +41,19 @@ public class AltosBluetooth extends AltosDroidLink {
private ConnectThread connect_thread = null;
- private BluetoothAdapter adapter;
+ private BluetoothDevice device;
private BluetoothSocket socket;
private InputStream input;
private OutputStream output;
+ private boolean pause;
// Constructor
- public AltosBluetooth(BluetoothDevice device, Handler handler) {
+ public AltosBluetooth(BluetoothDevice device, Handler handler, boolean pause) {
super(handler);
-// set_debug(D);
- adapter = BluetoothAdapter.getDefaultAdapter();
+ this.device = device;
this.handler = handler;
+ this.pause = pause;
- create_socket(device);
connect_thread = new ConnectThread();
connect_thread.start();
}
@@ -64,6 +64,7 @@ public class AltosBluetooth extends AltosDroidLink {
return;
}
+ AltosDebug.check_ui("connected\n");
try {
synchronized(this) {
if (socket != null) {
@@ -141,9 +142,17 @@ public class AltosBluetooth extends AltosDroidLink {
if (D) Log.d(TAG, "ConnectThread: BEGIN");
setName("ConnectThread");
+ if (pause) {
+ try {
+ Thread.sleep(4000);
+ } catch (InterruptedException e) {
+ }
+ }
+
+ create_socket(device);
// Always cancel discovery because it will slow down a connection
try {
- adapter.cancelDiscovery();
+ BluetoothAdapter.getDefaultAdapter().cancelDiscovery();
} catch (Exception e) {
if (D) Log.d(TAG, String.format("cancelDiscovery exception %s", e.toString()));
}
diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java
index 82c546c5..ed7b75a1 100644
--- a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java
+++ b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java
@@ -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