From 92efab6fb72d6c7d1d9225cf88bba1852d69b1a9 Mon Sep 17 00:00:00 2001 From: Mohammad Abu-Garbeyyeh Date: Fri, 26 Jan 2018 18:41:32 +0200 Subject: [PATCH] Fix double CLSEs causing a crash on some devices --- adb/adb_protocol.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/adb/adb_protocol.py b/adb/adb_protocol.py index 3dc92d6..8047f48 100644 --- a/adb/adb_protocol.py +++ b/adb/adb_protocol.py @@ -351,8 +351,12 @@ def Open(cls, usb, destination, timeout_ms=None): raise InvalidResponseError( 'Expected the local_id to be %s, got %s' % (local_id, their_local_id)) if cmd == b'CLSE': + # Some devices seem to be sending CLSE once more after a request, this *should* handle it + cmd, remote_id, their_local_id, _ = cls.Read(usb, [b'CLSE', b'OKAY'], + timeout_ms=timeout_ms) # Device doesn't support this service. - return None + if cmd == b'CLSE': + return None if cmd != b'OKAY': raise InvalidCommandError('Expected a ready response, got %s' % cmd, cmd, (remote_id, their_local_id))