- // Get a BluetoothSocket for a connection with the
- // given BluetoothDevice
- try {
- if (secure) {
- Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
- tmp_socket = (BluetoothSocket) m.invoke(device, 2);
- // tmp = device.createRfcommSocket(2);
- } else {
- Method m = device.getClass().getMethod("createInsecureRfcommSocket", new Class[] {int.class});
- tmp_socket = (BluetoothSocket) m.invoke(device, 2);
- // tmp = device.createInsecureRfcommSocket(2);
+ create_socket(device);
+ connect_thread = new ConnectThread();
+ connect_thread.start();
+ }
+
+ private Object closed_lock = new Object();
+ private boolean closed = false;
+
+ private boolean closed() {
+ synchronized(closed_lock) {
+ return closed;
+ }
+ }
+
+ private void connected() {
+ if (closed()) {
+ if (D) Log.d(TAG, "connected after closed");
+ return;
+ }
+
+ try {
+ synchronized(this) {
+ if (socket != null) {
+ input = socket.getInputStream();
+ output = socket.getOutputStream();
+
+ input_thread = new Thread(this);
+ input_thread.start();
+
+ // Configure the newly connected device for telemetry
+ print("~\nE 0\n");
+ set_monitor(false);
+ if (D) Log.d(TAG, "ConnectThread: connected");
+
+ /* Let TelemetryService know we're connected
+ */
+ handler.obtainMessage(TelemetryService.MSG_CONNECTED, this).sendToTarget();
+
+ /* Notify other waiting threads that we're connected now
+ */
+ notifyAll();