

@classmethod
def Connect(cls, usb, banner='notadb', rsa_keys=None, auth_timeout_ms=100):
    "Establish a new connection to the device.\n\n    Args:\n      usb: A USBHandle with BulkRead and BulkWrite methods.\n      banner: A string to send as a host identifier.\n      rsa_keys: List of AuthSigner subclass instances to be used for\n          authentication. The device can either accept one of these via the Sign\n          method, or we will send the result of GetPublicKey from the first one\n          if the device doesn't accept any of them.\n      auth_timeout_ms: Timeout to wait for when sending a new public key. This\n          is only relevant when we send a new public key. The device shows a\n          dialog and this timeout is how long to wait for that dialog. If used\n          in automation, this should be low to catch such a case as a failure\n          quickly; while in interactive settings it should be high to allow\n          users to accept the dialog. We default to automation here, so it's low\n          by default.\n\n    Returns:\n      The device's reported banner. Always starts with the state (device,\n          recovery, or sideload), sometimes includes information after a : with\n          various product information.\n\n    Raises:\n      usb_exceptions.DeviceAuthError: When the device expects authentication,\n          but we weren't given any valid keys.\n      InvalidResponseError: When the device does authentication in an\n          unexpected way.\n    "
    msg = cls(command='CNXN', arg0=VERSION, arg1=MAX_ADB_DATA, data=('host::%s\x00' % banner))
    msg.Send(usb)
    (cmd, arg0, arg1, banner) = cls.Read(usb, ['CNXN', 'AUTH'])
    if (cmd == 'AUTH'):
        if (not rsa_keys):
            raise usb_exceptions.DeviceAuthError('Device authentication required, no keys available.')
        for rsa_key in rsa_keys:
            if (arg0 != AUTH_TOKEN):
                raise InvalidResponseError(('Unknown AUTH response: %s %s %s' % (arg0, arg1, banner)))
            signed_token = rsa_key.Sign(banner)
            msg = cls(command='AUTH', arg0=AUTH_SIGNATURE, arg1=0, data=signed_token)
            msg.Send(usb)
            (cmd, arg0, unused_arg1, banner) = cls.Read(usb, ['CNXN', 'AUTH'])
            if (cmd == 'CNXN'):
                return banner
        msg = cls(command='AUTH', arg0=AUTH_RSAPUBLICKEY, arg1=0, data=(rsa_keys[0].GetPublicKey() + '\x00'))
        msg.Send(usb)
        try:
            (cmd, arg0, unused_arg1, banner) = cls.Read(usb, ['CNXN'], timeout_ms=auth_timeout_ms)
        except usb_exceptions.BulkReadFailedError as e:
            if (e.usb_error.value == (- 7)):
                raise usb_exceptions.DeviceAuthError('Accept auth key on device, then retry.')
            raise
        return banner
    return banner

dataset/ETHPy150Open google/python-adb/adb/adb_protocol.py AdbMessage.Connect/original