@classmethod
  def Open(cls, usb, destination, timeout_ms=None):
    """Opens a new connection to the device via an OPEN message.

    Not the same as the posix 'open' or any other google3 Open methods.

    Args:
      usb: USB device handle with BulkRead and BulkWrite methods.
      destination: The service:command string.
      timeout_ms: Timeout in milliseconds for USB packets.

    Raises:
      InvalidResponseError: Wrong local_id sent to us.
      InvalidCommandError: Didn't get a ready response.

    Returns:
      The local connection id.
    """
    local_id = 1
    msg = cls(
        command='OPEN', arg0=local_id, arg1=0,
        data=destination + '\0')
    msg.Send(usb, timeout_ms)
    cmd, remote_id, their_local_id, _ = cls.Read(usb, ['CLSE', 'OKAY'],
                                                 timeout_ms=timeout_ms)
    if local_id != their_local_id:
      raise InvalidResponseError(
          'Expected the local_id to be %s, got %s' % (local_id, their_local_id))
    if cmd == 'CLSE':
      # Device doesn't support this service.
      return None
    if cmd != 'OKAY':
      raise InvalidCommandError('Expected a ready response, got %s' % cmd,
                                cmd, (remote_id, their_local_id))
    return _AdbConnection(usb, local_id, remote_id, timeout_ms)
dataset/ETHPy150Open google/python-adb/adb/adb_protocol.py/AdbMessage.Open/original