This avoids stalling the UI while waiting for TBT to boot.
Signed-off-by: Keith Packard <keithp@keithp.com>
private ConnectThread connect_thread = null;
private ConnectThread connect_thread = null;
- private BluetoothAdapter adapter;
+ private BluetoothDevice device;
private BluetoothSocket socket;
private InputStream input;
private OutputStream output;
private BluetoothSocket socket;
private InputStream input;
private OutputStream output;
- public AltosBluetooth(BluetoothDevice device, Handler handler) {
+ public AltosBluetooth(BluetoothDevice device, Handler handler, boolean pause) {
-// set_debug(D);
- adapter = BluetoothAdapter.getDefaultAdapter();
connect_thread = new ConnectThread();
connect_thread.start();
}
connect_thread = new ConnectThread();
connect_thread.start();
}
+ AltosDebug.check_ui("connected\n");
try {
synchronized(this) {
if (socket != null) {
try {
synchronized(this) {
if (socket != null) {
if (D) Log.d(TAG, "ConnectThread: BEGIN");
setName("ConnectThread");
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 {
// 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()));
}
} catch (Exception e) {
if (D) Log.d(TAG, String.format("cancelDiscovery exception %s", e.toString()));
}
BluetoothDevice device = bluetooth_adapter.getRemoteDevice(address.address);
disconnect(false);
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);
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);
// Move us into the foreground.
startForeground(NOTIFICATION, notification);
// 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
}
// We want this service to continue running until it is explicitly