protected ConnectedThread(BluetoothSocket socket) {
    mSocket = socket;
    InputStream inStream = null;
    OutputStream outStream = null;

    try {
      inStream = socket.getInputStream();
      outStream = socket.getOutputStream();
    } catch (IOException e) {
    }

    mInStream = new DataInputStream(inStream);
    mOutStream = new DataOutputStream(outStream);
    mLock = new ReentrantReadWriteLock();
  }
  public final void cancel() {
    mLock.readLock().lock();

    try {
      if (mClosed) {
        return;
      }
    } finally {
      mLock.readLock().unlock();
    }

    mLock.writeLock().lock();

    try {
      mClosed = true;
    } finally {
      mLock.writeLock().unlock();
    }

    try {
      mSocket.close();
    } catch (IOException e) {
    }
  }