android.net.LocalSocket Java Examples

The following examples show how to use android.net.LocalSocket. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RecoverySystemService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private LocalSocket connectService() {
    LocalSocket socket = new LocalSocket();
    boolean done = false;
    // The uncrypt socket will be created by init upon receiving the
    // service request. It may not be ready by this point. So we will
    // keep retrying until success or reaching timeout.
    for (int retry = 0; retry < SOCKET_CONNECTION_MAX_RETRY; retry++) {
        try {
            socket.connect(new LocalSocketAddress(UNCRYPT_SOCKET,
                    LocalSocketAddress.Namespace.RESERVED));
            done = true;
            break;
        } catch (IOException ignored) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                Slog.w(TAG, "Interrupted:", e);
            }
        }
    }
    if (!done) {
        Slog.e(TAG, "Timed out connecting to uncrypt socket");
        return null;
    }
    return socket;
}
 
Example #2
Source File: SecureSocketHandler.java    From Dream-Catcher with MIT License 6 votes vote down vote up
private static void enforcePermission(Context context, LocalSocket peer)
    throws IOException, PeerAuthorizationException {
  Credentials credentials = peer.getPeerCredentials();

  int uid = credentials.getUid();
  int pid = credentials.getPid();

  if (LogUtil.isLoggable(Log.VERBOSE)) {
    LogUtil.v("Got request from uid=%d, pid=%d", uid, pid);
  }

  String requiredPermission = Manifest.permission.DUMP;
  int checkResult = context.checkPermission(requiredPermission, pid, uid);
  if (checkResult != PackageManager.PERMISSION_GRANTED) {
    throw new PeerAuthorizationException(
        "Peer pid=" + pid + ", uid=" + uid + " does not have " + requiredPermission);
  }
}
 
Example #3
Source File: ProtocolDetectingSocketHandler.java    From weex with Apache License 2.0 6 votes vote down vote up
@Override
protected void onSecured(LocalSocket socket) throws IOException {
  LeakyBufferedInputStream leakyIn = new LeakyBufferedInputStream(
      socket.getInputStream(),
      SENSING_BUFFER_SIZE);

  if (mHandlers.isEmpty()) {
    throw new IllegalStateException("No handlers added");
  }

  for (int i = 0, N = mHandlers.size(); i < N; i++) {
    HandlerInfo handlerInfo = mHandlers.get(i);
    leakyIn.mark(SENSING_BUFFER_SIZE);
    boolean matches = handlerInfo.magicMatcher.matches(leakyIn);
    leakyIn.reset();
    if (matches) {
      SocketLike socketLike = new SocketLike(socket, leakyIn);
      handlerInfo.handler.onAccepted(socketLike);
      return;
    }
  }

  throw new IOException("No matching handler, firstByte=" + leakyIn.read());
}
 
Example #4
Source File: ProtocolDetectingSocketHandler.java    From Dream-Catcher with MIT License 6 votes vote down vote up
@Override
protected void onSecured(LocalSocket socket) throws IOException {
  LeakyBufferedInputStream leakyIn = new LeakyBufferedInputStream(
      socket.getInputStream(),
      SENSING_BUFFER_SIZE);

  if (mHandlers.isEmpty()) {
    throw new IllegalStateException("No handlers added");
  }

  for (int i = 0, N = mHandlers.size(); i < N; i++) {
    HandlerInfo handlerInfo = mHandlers.get(i);
    leakyIn.mark(SENSING_BUFFER_SIZE);
    boolean matches = handlerInfo.magicMatcher.matches(leakyIn);
    leakyIn.reset();
    if (matches) {
      LogUtil.d("Matches!" + handlerInfo.handler.getClass().getSimpleName());
      SocketLike socketLike = new SocketLike(socket, leakyIn);
      handlerInfo.handler.onAccepted(socketLike);
      return;
    }
  }

  throw new IOException("No matching handler, firstByte=" + leakyIn.read());
}
 
Example #5
Source File: SecureSocketHandler.java    From weex with Apache License 2.0 6 votes vote down vote up
private static void enforcePermission(Context context, LocalSocket peer)
    throws IOException, PeerAuthorizationException {
  Credentials credentials = peer.getPeerCredentials();

  int uid = credentials.getUid();
  int pid = credentials.getPid();

  if (LogUtil.isLoggable(Log.VERBOSE)) {
    LogUtil.v("Got request from uid=%d, pid=%d", uid, pid);
  }

  String requiredPermission = Manifest.permission.DUMP;
  int checkResult = context.checkPermission(requiredPermission, pid, uid);
  if (checkResult != PackageManager.PERMISSION_GRANTED) {
    throw new PeerAuthorizationException(
        "Peer pid=" + pid + ", uid=" + uid + " does not have " + requiredPermission);
  }
}
 
Example #6
Source File: CameraConnector.java    From faceswap with Apache License 2.0 6 votes vote down vote up
public void init() {
      try {
          localLoop = new LocalServerSocket("videoserver");
          localReceiver = new LocalSocket();
          localReceiver.connect(localLoop.getLocalSocketAddress());
          localReceiver.setReceiveBufferSize(LOCAL_BUFF_SIZE);
          localReceiver.setSendBufferSize(LOCAL_BUFF_SIZE);
	
	localSender = localLoop.accept();
          localSender.setReceiveBufferSize(LOCAL_BUFF_SIZE);
          localSender.setSendBufferSize(LOCAL_BUFF_SIZE);
	
          Log.d(LOG_TAG, "Done: init()");
}catch(IOException e) {
    Log.e(LOG_TAG, "Error in initializing local socket: " + e);
}
  }
 
Example #7
Source File: ProtocolDetectingSocketHandler.java    From stetho with MIT License 6 votes vote down vote up
@Override
protected void onSecured(LocalSocket socket) throws IOException {
  LeakyBufferedInputStream leakyIn = new LeakyBufferedInputStream(
      socket.getInputStream(),
      SENSING_BUFFER_SIZE);

  if (mHandlers.isEmpty()) {
    throw new IllegalStateException("No handlers added");
  }

  for (int i = 0, N = mHandlers.size(); i < N; i++) {
    HandlerInfo handlerInfo = mHandlers.get(i);
    leakyIn.mark(SENSING_BUFFER_SIZE);
    boolean matches = handlerInfo.magicMatcher.matches(leakyIn);
    leakyIn.reset();
    if (matches) {
      SocketLike socketLike = new SocketLike(socket, leakyIn);
      handlerInfo.handler.onAccepted(socketLike);
      return;
    }
  }

  throw new IOException("No matching handler, firstByte=" + leakyIn.read());
}
 
Example #8
Source File: ShadowsocksVpnThread.java    From Maying with Apache License 2.0 6 votes vote down vote up
/**
 * init server socket
 *
 * @return init failed return false.
 */
private boolean initServerSocket() {
    // if not running, do not init
    if (!isRunning) {
        return false;
    }

    try {
        LocalSocket localSocket = new LocalSocket();
        localSocket.bind(new LocalSocketAddress(PATH, LocalSocketAddress.Namespace.FILESYSTEM));
        serverSocket = new LocalServerSocket(localSocket.getFileDescriptor());
        return true;
    } catch (IOException e) {
        VayLog.e(TAG, "unable to bind", e);
        ShadowsocksApplication.app.track(e);
        return false;
    }
}
 
Example #9
Source File: ShadowsocksVpnThread.java    From Maying with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    boolean deleteFlag = new File(PATH).delete();
    VayLog.d(TAG, "run() delete file = " + deleteFlag);

    if (!initServerSocket()) {
        return;
    }

    while (isRunning) {
        try {
            final LocalSocket socket = serverSocket.accept();
            // handle local socket
            handleLocalSocket(socket);
        } catch (IOException e) {
            VayLog.e(TAG, "Error when accept socket", e);
            ShadowsocksApplication.app.track(e);

            initServerSocket();
        }
    }
}
 
Example #10
Source File: TrafficMonitorThread.java    From Maying with Apache License 2.0 6 votes vote down vote up
/**
 * init server socket
 *
 * @return init failed return false.
 */
private boolean initServerSocket() {
    // if not running, do not init
    if (!isRunning) {
        return false;
    }

    try {
        LocalSocket localSocket = new LocalSocket();
        localSocket.bind(new LocalSocketAddress(PATH, LocalSocketAddress.Namespace.FILESYSTEM));
        serverSocket = new LocalServerSocket(localSocket.getFileDescriptor());
        return true;
    } catch (IOException e) {
        VayLog.e(TAG, "unable to bind", e);
        return false;
    }
}
 
Example #11
Source File: TrafficMonitorThread.java    From Maying with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    boolean deleteResult = new File(PATH).delete();
    VayLog.d(TAG, "run() delete file = " + deleteResult);

    if (!initServerSocket()) {
        return;
    }

    while (isRunning) {
        try {
            final LocalSocket socket = serverSocket.accept();
            // handle socket
            handleLocalSocket(socket);
        } catch (Exception e) {
            VayLog.e(TAG, "Error when accept socket", e);
            ShadowsocksApplication.app.track(e);

            initServerSocket();
        }
    }
}
 
Example #12
Source File: ShadowsocksVpnThread.java    From ShadowsocksRR with Apache License 2.0 6 votes vote down vote up
/**
 * init server socket
 *
 * @return init failed return false.
 */
private boolean initServerSocket() {
    // if not running, do not init
    if (!isRunning) {
        return false;
    }

    try {
        LocalSocket localSocket = new LocalSocket();
        localSocket.bind(new LocalSocketAddress(PATH, LocalSocketAddress.Namespace.FILESYSTEM));
        serverSocket = new LocalServerSocket(localSocket.getFileDescriptor());
        return true;
    } catch (IOException e) {
        VayLog.e(TAG, "unable to bind", e);
        app.track(e);
        return false;
    }
}
 
Example #13
Source File: ShadowsocksVpnThread.java    From ShadowsocksRR with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    boolean deleteFlag = new File(PATH).delete();
    VayLog.d(TAG, "run() delete file = " + deleteFlag);

    if (!initServerSocket()) {
        return;
    }

    while (isRunning) {
        try {
            final LocalSocket socket = serverSocket.accept();
            // handle local socket
            handleLocalSocket(socket);
        } catch (IOException e) {
            VayLog.e(TAG, "Error when accept socket", e);
            app.track(e);

            initServerSocket();
        }
    }
}
 
Example #14
Source File: TrafficMonitorThread.java    From ShadowsocksRR with Apache License 2.0 6 votes vote down vote up
/**
 * init server socket
 *
 * @return init failed return false.
 */
private boolean initServerSocket() {
    // if not running, do not init
    if (!isRunning) {
        return false;
    }

    try {
        LocalSocket localSocket = new LocalSocket();
        localSocket.bind(new LocalSocketAddress(PATH, LocalSocketAddress.Namespace.FILESYSTEM));
        serverSocket = new LocalServerSocket(localSocket.getFileDescriptor());
        return true;
    } catch (IOException e) {
        VayLog.e(TAG, "unable to bind", e);
        return false;
    }
}
 
Example #15
Source File: TrafficMonitorThread.java    From ShadowsocksRR with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    boolean deleteResult = new File(PATH).delete();
    VayLog.d(TAG, "run() delete file = " + deleteResult);

    if (!initServerSocket()) {
        return;
    }

    while (isRunning) {
        try {
            final LocalSocket socket = serverSocket.accept();
            // handle socket
            handleLocalSocket(socket);
        } catch (Exception e) {
            VayLog.e(TAG, "Error when accept socket", e);
            app.track(e);

            initServerSocket();
        }
    }
}
 
Example #16
Source File: BluetoothSocket.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private BluetoothSocket acceptSocket(String remoteAddr) throws IOException {
    BluetoothSocket as = new BluetoothSocket(this);
    as.mSocketState = SocketState.CONNECTED;
    FileDescriptor[] fds = mSocket.getAncillaryFileDescriptors();
    if (DBG) Log.d(TAG, "socket fd passed by stack fds: " + Arrays.toString(fds));
    if (fds == null || fds.length != 1) {
        Log.e(TAG, "socket fd passed from stack failed, fds: " + Arrays.toString(fds));
        as.close();
        throw new IOException("bt socket acept failed");
    }

    as.mPfd = new ParcelFileDescriptor(fds[0]);
    as.mSocket = LocalSocket.createConnectedLocalSocket(fds[0]);
    as.mSocketIS = as.mSocket.getInputStream();
    as.mSocketOS = as.mSocket.getOutputStream();
    as.mAddress = remoteAddr;
    as.mDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(remoteAddr);
    return as;
}
 
Example #17
Source File: SecureSocketHandler.java    From stetho with MIT License 6 votes vote down vote up
private static void enforcePermission(Context context, LocalSocket peer)
    throws IOException, PeerAuthorizationException {
  Credentials credentials = peer.getPeerCredentials();

  int uid = credentials.getUid();
  int pid = credentials.getPid();

  if (LogUtil.isLoggable(Log.VERBOSE)) {
    LogUtil.v("Got request from uid=%d, pid=%d", uid, pid);
  }

  String requiredPermission = Manifest.permission.DUMP;
  int checkResult = context.checkPermission(requiredPermission, pid, uid);
  if (checkResult != PackageManager.PERMISSION_GRANTED) {
    throw new PeerAuthorizationException(
        "Peer pid=" + pid + ", uid=" + uid + " does not have " + requiredPermission);
  }
}
 
Example #18
Source File: MediaStream.java    From spydroid-ipcamera with GNU General Public License v3.0 6 votes vote down vote up
protected void createSockets() throws IOException {

		final String LOCAL_ADDR = "net.majorkernelpanic.streaming-";

		for (int i=0;i<10;i++) {
			try {
				mSocketId = new Random().nextInt();
				mLss = new LocalServerSocket(LOCAL_ADDR+mSocketId);
				break;
			} catch (IOException e1) {}
		}

		mReceiver = new LocalSocket();
		mReceiver.connect( new LocalSocketAddress(LOCAL_ADDR+mSocketId));
		mReceiver.setReceiveBufferSize(500000);
		mReceiver.setSoTimeout(3000);
		mSender = mLss.accept();
		mSender.setSendBufferSize(500000);
	}
 
Example #19
Source File: ZygoteConnection.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs instance from connected socket.
 *
 * @param socket non-null; connected socket
 * @param abiList non-null; a list of ABIs this zygote supports.
 * @throws IOException
 */
ZygoteConnection(LocalSocket socket, String abiList) throws IOException {
    mSocket = socket;
    this.abiList = abiList;

    mSocketOutStream
            = new DataOutputStream(socket.getOutputStream());

    mSocketReader = new BufferedReader(
            new InputStreamReader(socket.getInputStream()), 256);

    mSocket.setSoTimeout(CONNECTION_TIMEOUT_MILLIS);

    try {
        peer = mSocket.getPeerCredentials();
    } catch (IOException ex) {
        Log.e(TAG, "Cannot read peer credentials", ex);
        throw ex;
    }

    isEof = false;
}
 
Example #20
Source File: SecureSocketHandler.java    From stetho with MIT License 5 votes vote down vote up
@Override
public final void onAccepted(LocalSocket socket) throws IOException {
  try {
    enforcePermission(mContext, socket);
    onSecured(socket);
  } catch (PeerAuthorizationException e) {
    LogUtil.e("Unauthorized request: " + e.getMessage());
  }
}
 
Example #21
Source File: LocalSocketServer.java    From stetho with MIT License 5 votes vote down vote up
private void listenOnAddress(String address) throws IOException {
  mServerSocket = bindToSocket(address);
  LogUtil.i("Listening on @" + address);

  while (!Thread.interrupted()) {
    try {
      // Use previously accepted socket the first time around, otherwise wait to
      // accept another.
      LocalSocket socket = mServerSocket.accept();

      // Start worker thread
      Thread t = new WorkerThread(socket, mSocketHandler);
      t.setName(
          WORKER_THREAD_NAME_PREFIX +
          "-" + mFriendlyName +
          "-" + mThreadId.incrementAndGet());
      t.setDaemon(true);
      t.start();
    } catch (SocketException se) {
      // ignore exception if interrupting the thread
      if (Thread.interrupted()) {
        break;
      }
      LogUtil.w(se, "I/O error");
    } catch (InterruptedIOException ex) {
      break;
    } catch (IOException e) {
      LogUtil.w(e, "I/O error initialising connection thread");
      break;
    }
  }

  LogUtil.i("Server shutdown on @" + address);
}
 
Example #22
Source File: SecureSocketHandler.java    From weex with Apache License 2.0 5 votes vote down vote up
@Override
public final void onAccepted(LocalSocket socket) throws IOException {
  try {
    enforcePermission(mContext, socket);
    onSecured(socket);
  } catch (PeerAuthorizationException e) {
    LogUtil.e("Unauthorized request: " + e.getMessage());
  }
}
 
Example #23
Source File: LocalSocketServer.java    From weex with Apache License 2.0 5 votes vote down vote up
private void listenOnAddress(String address) throws IOException {
  mServerSocket = bindToSocket(address);
  LogUtil.i("Listening on @" + address);

  while (!Thread.interrupted()) {
    try {
      // Use previously accepted socket the first time around, otherwise wait to
      // accept another.
      LocalSocket socket = mServerSocket.accept();

      // Start worker thread
      Thread t = new WorkerThread(socket, mSocketHandler);
      t.setName(
          WORKER_THREAD_NAME_PREFIX +
          "-" + mFriendlyName +
          "-" + mThreadId.incrementAndGet());
      t.setDaemon(true);
      t.start();
    } catch (SocketException se) {
      // ignore exception if interrupting the thread
      if (Thread.interrupted()) {
        break;
      }
      LogUtil.w(se, "I/O error");
    } catch (InterruptedIOException ex) {
      break;
    } catch (IOException e) {
      LogUtil.w(e, "I/O error initialising connection thread");
      break;
    }
  }

  LogUtil.i("Server shutdown on @" + address);
}
 
Example #24
Source File: MediaStream.java    From libstreaming with Apache License 2.0 5 votes vote down vote up
protected void createSockets() throws IOException {

		if (sPipeApi == PIPE_API_LS) {
			
			final String LOCAL_ADDR = "net.majorkernelpanic.streaming-";
	
			for (int i=0;i<10;i++) {
				try {
					mSocketId = new Random().nextInt();
					mLss = new LocalServerSocket(LOCAL_ADDR+mSocketId);
					break;
				} catch (IOException e1) {}
			}
	
			mReceiver = new LocalSocket();
			mReceiver.connect( new LocalSocketAddress(LOCAL_ADDR+mSocketId));
			mReceiver.setReceiveBufferSize(500000);
			mReceiver.setSoTimeout(3000);
			mSender = mLss.accept();
			mSender.setSendBufferSize(500000);
			
		} else {
			Log.e(TAG, "parcelFileDescriptors createPipe version = Lollipop");
			mParcelFileDescriptors = ParcelFileDescriptor.createPipe();
			mParcelRead = new ParcelFileDescriptor(mParcelFileDescriptors[0]);
			mParcelWrite = new ParcelFileDescriptor(mParcelFileDescriptors[1]);
		}
	}
 
Example #25
Source File: Vpn.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public LegacyVpnRunner(VpnConfig config, String[] racoon, String[] mtpd) {
    super(TAG);
    mConfig = config;
    mDaemons = new String[] {"racoon", "mtpd"};
    // TODO: clear arguments from memory once launched
    mArguments = new String[][] {racoon, mtpd};
    mSockets = new LocalSocket[mDaemons.length];

    // This is the interface which VPN is running on,
    // mConfig.interfaze will change to point to OUR
    // internal interface soon. TODO - add inner/outer to mconfig
    // TODO - we have a race - if the outer iface goes away/disconnects before we hit this
    // we will leave the VPN up.  We should check that it's still there/connected after
    // registering
    mOuterInterface = mConfig.interfaze;

    if (!TextUtils.isEmpty(mOuterInterface)) {
        final ConnectivityManager cm = ConnectivityManager.from(mContext);
        for (Network network : cm.getAllNetworks()) {
            final LinkProperties lp = cm.getLinkProperties(network);
            if (lp != null && lp.getAllInterfaceNames().contains(mOuterInterface)) {
                final NetworkInfo networkInfo = cm.getNetworkInfo(network);
                if (networkInfo != null) mOuterConnection.set(networkInfo.getType());
            }
        }
    }

    IntentFilter filter = new IntentFilter();
    filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    mContext.registerReceiver(mBroadcastReceiver, filter);
}
 
Example #26
Source File: SecureSocketHandler.java    From Dream-Catcher with MIT License 5 votes vote down vote up
@Override
public final void onAccepted(LocalSocket socket) throws IOException {
  try {
    enforcePermission(mContext, socket);
    onSecured(socket);
  } catch (PeerAuthorizationException e) {
    LogUtil.e("Unauthorized request: " + e.getMessage());
  }
}
 
Example #27
Source File: ProcessList.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static boolean openLmkdSocket() {
    try {
        sLmkdSocket = new LocalSocket(LocalSocket.SOCKET_SEQPACKET);
        sLmkdSocket.connect(
            new LocalSocketAddress("lmkd",
                    LocalSocketAddress.Namespace.RESERVED));
        sLmkdOutputStream = sLmkdSocket.getOutputStream();
    } catch (IOException ex) {
        Slog.w(TAG, "lowmemorykiller daemon socket open failed");
        sLmkdSocket = null;
        return false;
    }

    return true;
}
 
Example #28
Source File: SocketLike.java    From Dream-Catcher with MIT License 5 votes vote down vote up
public SocketLike(LocalSocket socket, LeakyBufferedInputStream leakyInput) {
    OutputStream temp = null;
    try {
        temp = socket.getOutputStream();
    } catch (IOException e) {
        e.printStackTrace();
    }
    outputStream = temp;
    mLeakyInput = leakyInput;
}
 
Example #29
Source File: ZygoteProcess.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private ZygoteState(LocalSocket socket, DataInputStream inputStream,
        BufferedWriter writer, List<String> abiList) {
    this.socket = socket;
    this.inputStream = inputStream;
    this.writer = writer;
    this.abiList = abiList;
}
 
Example #30
Source File: BluetoothSocket.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Attempt to connect to a remote device.
 * <p>This method will block until a connection is made or the connection
 * fails. If this method returns without an exception then this socket
 * is now connected.
 * <p>Creating new connections to
 * remote Bluetooth devices should not be attempted while device discovery
 * is in progress. Device discovery is a heavyweight procedure on the
 * Bluetooth adapter and will significantly slow a device connection.
 * Use {@link BluetoothAdapter#cancelDiscovery()} to cancel an ongoing
 * discovery. Discovery is not managed by the Activity,
 * but is run as a system service, so an application should always call
 * {@link BluetoothAdapter#cancelDiscovery()} even if it
 * did not directly request a discovery, just to be sure.
 * <p>{@link #close} can be used to abort this call from another thread.
 *
 * @throws IOException on error, for example connection failure
 */
public void connect() throws IOException {
    if (mDevice == null) throw new IOException("Connect is called on null device");

    try {
        if (mSocketState == SocketState.CLOSED) throw new IOException("socket closed");
        IBluetooth bluetoothProxy =
                BluetoothAdapter.getDefaultAdapter().getBluetoothService(null);
        if (bluetoothProxy == null) throw new IOException("Bluetooth is off");
        mPfd = bluetoothProxy.getSocketManager().connectSocket(mDevice, mType,
                mUuid, mPort, getSecurityFlags());
        synchronized (this) {
            if (DBG) Log.d(TAG, "connect(), SocketState: " + mSocketState + ", mPfd: " + mPfd);
            if (mSocketState == SocketState.CLOSED) throw new IOException("socket closed");
            if (mPfd == null) throw new IOException("bt socket connect failed");
            FileDescriptor fd = mPfd.getFileDescriptor();
            mSocket = LocalSocket.createConnectedLocalSocket(fd);
            mSocketIS = mSocket.getInputStream();
            mSocketOS = mSocket.getOutputStream();
        }
        int channel = readInt(mSocketIS);
        if (channel <= 0) {
            throw new IOException("bt socket connect failed");
        }
        mPort = channel;
        waitSocketSignal(mSocketIS);
        synchronized (this) {
            if (mSocketState == SocketState.CLOSED) {
                throw new IOException("bt socket closed");
            }
            mSocketState = SocketState.CONNECTED;
        }
    } catch (RemoteException e) {
        Log.e(TAG, Log.getStackTraceString(new Throwable()));
        throw new IOException("unable to send RPC: " + e.getMessage());
    }
}