Skip to content

Commit

Permalink
Keep track of whether a CLSE packet has been received
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffLIrion committed Jun 13, 2021
1 parent e9524ac commit 673ee5c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
18 changes: 9 additions & 9 deletions adb_shell/adb_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,15 +918,15 @@ def _read_until(self, expected_cmds, adb_info):
while True:
cmd, remote_id2, local_id2, data = self._read(expected_cmds, adb_info)

# Streaming shell fix
if cmd == constants.CLSE:
adb_info.local_id = None
# adb_info.remote_id = None
else:
if adb_info.local_id is None:
adb_info.local_id = local_id2
# if adb_info.remote_id is None:
adb_info.remote_id = remote_id2
# Enable streaming commands
if not adb_info.clse_received and cmd == constants.CLSE:
if adb_info.local_id == local_id2 and adb_info.remote_id == remote_id2:
# Make note that a `CLSE` packet has been received for this local ID + remote ID transaction
adb_info.clse_received = True
elif adb_info.clse_received and cmd != constants.CLSE:
# This is the start of a new transaction --> update the local ID and remote ID
adb_info.local_id = local_id2
adb_info.remote_id = remote_id2

if adb_info.local_id is not None and local_id2 not in (0, adb_info.local_id):
raise exceptions.InterleavedDataError("We don't support multiple streams...")
Expand Down
3 changes: 3 additions & 0 deletions adb_shell/hidden_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ class _AdbTransactionInfo(object): # pylint: disable=too-few-public-methods
Attributes
----------
clse_received : False
Whether a ``CLSE`` packet has been received
local_id : int
The ID for the sender (i.e., the device running this code)
read_timeout_s : float
Expand All @@ -137,6 +139,7 @@ def __init__(self, local_id, remote_id, transport_timeout_s=None, read_timeout_s
self.timeout_s = timeout_s
self.read_timeout_s = read_timeout_s if self.timeout_s is None else min(read_timeout_s, self.timeout_s)
self.transport_timeout_s = self.read_timeout_s if transport_timeout_s is None else min(transport_timeout_s, self.read_timeout_s)
self.clse_received = False


class _FileSyncTransactionInfo(object): # pylint: disable=too-few-public-methods
Expand Down

0 comments on commit 673ee5c

Please sign in to comment.