+
+ private class ConnectThread extends Thread {
+
+ public void run() {
+ if (D) Log.d(TAG, "ConnectThread: BEGIN");
+ setName("ConnectThread");
+
+ // Always cancel discovery because it will slow down a connection
+ try {
+ adapter.cancelDiscovery();
+ } catch (Exception e) {
+ if (D) Log.d(TAG, String.format("cancelDiscovery exception %s", e.toString()));
+ }
+
+ BluetoothSocket local_socket = null;
+
+ synchronized (AltosBluetooth.this) {
+ if (!closed())
+ local_socket = socket;
+ }
+
+ if (local_socket != null) {
+ try {
+ // Make a connection to the BluetoothSocket
+ // This is a blocking call and will only return on a
+ // successful connection or an exception
+ local_socket.connect();
+ } catch (IOException e) {
+ if (D) Log.d(TAG, String.format("Connect exception %s", e.toString()));
+ local_socket = null;
+ }