+ 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();
+ }
+ }
+ } catch (IOException io) {
+ connect_failed();
+ }
+ }
+
+ private void connect_failed() {
+ if (closed()) {
+ if (D) Log.d(TAG, "connect_failed after closed");
+ return;
+ }
+
+ close_socket();
+ input = null;
+ output = null;
+ handler.obtainMessage(TelemetryService.MSG_CONNECT_FAILED, this).sendToTarget();
+ if (D) Log.e(TAG, "ConnectThread: Failed to establish connection");
+ }
+
+ private void disconnected() {
+ if (closed()) {
+ if (D) Log.d(TAG, "disconnected after closed");
+ return;
+ }