Closed maybe-sybr closed 3 years ago
Here's what it should look like, with a0e1d4c reverted:
DEBUG:adb_shell.adb_device:bulk_read(24): b'CNXN\x01\x00\x00\x01\x00\x00\x10\x00\xde\x00\x00\x00^T\x00\x00\xbc\xb1\xa7\xb1'
DEBUG:adb_shell.adb_device:bulk_read(222): b'device::ro.product.name=x1sxx;ro.product.model=SM-G980F;ro.product.device=x1s;features=sendrecv_v2_brotli,remount_shell,sendrecv_v2,abb_exec,fixed_push_mkdir,fixed_push_symlink_timestamp,abb,shell_v2,cmd,ls_v2,apex,stat_v2'
DEBUG:adb_shell.adb_device:bulk_write(24): b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\x17\x00\x00\x00m\x08\x00\x00\xb0\xaf\xba\xb1'
DEBUG:adb_shell.adb_device:bulk_write(23): b'shell:echo hello world\x00'
DEBUG:adb_shell.adb_device:bulk_read(24): b'OKAY\n\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
DEBUG:adb_shell.adb_device:bulk_read(24): b'WRTE\n\x00\x00\x00\x01\x00\x00\x00\x0c\x00\x00\x00f\x04\x00\x00\xa8\xad\xab\xba'
DEBUG:adb_shell.adb_device:bulk_read(12): b'hello world\n'
DEBUG:adb_shell.adb_device:bulk_write(24): b'OKAY\x01\x00\x00\x00\n\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
DEBUG:adb_shell.adb_device:bulk_read(24): b'CLSE\n\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
DEBUG:adb_shell.adb_device:bulk_write(24): b'CLSE\x01\x00\x00\x00\n\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
DEBUG:adb_shell.adb_device:bulk_write(24): b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\xf7\x01\x00\x00\xb0\xaf\xba\xb1'
DEBUG:adb_shell.adb_device:bulk_write(6): b'sync:\x00'
DEBUG:adb_shell.adb_device:bulk_read(24): b'CLSE\n\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
DEBUG:adb_shell.adb_device:bulk_read(24): b'OKAY\x0b\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
DEBUG:adb_shell.adb_device:bulk_write(24): b'WRTE\x01\x00\x00\x00\x0b\x00\x00\x00\t\x00\x00\x00l\x01\x00\x00\xa8\xad\xab\xba'
DEBUG:adb_shell.adb_device:bulk_write(9): bytearray(b'STAT\x01\x00\x00\x00/')
DEBUG:adb_shell.adb_device:bulk_read(24): b'OKAY\x0b\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
DEBUG:adb_shell.adb_device:bulk_read(24): b'WRTE\x0b\x00\x00\x00\x01\x00\x00\x00\x10\x00\x00\x00\x96\x04\x00\x00\xa8\xad\xab\xba'
DEBUG:adb_shell.adb_device:bulk_read(16): b'STAT\xedA\x00\x00\x00\x10\x00\x00\xf0\x88[I'
DEBUG:adb_shell.adb_device:bulk_write(24): b'OKAY\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
DEBUG:adb_shell.adb_device:bulk_write(24): b'CLSE\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
DEBUG:adb_shell.adb_device:bulk_read(24): b'CLSE\x0b\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
Edit: On master, interestingly the timeout does not occur if you stat a path which does not exist. It doesn't seem to want anything after getting the STAT
back and is happy to move on after sending OKAY
and then closing the connection. I've amended the issue description accordingly.
Thanks for the detailed info! I think this will fix it: https://github.com/JeffLIrion/adb_shell/pull/156
Could you please let me know.
I think that'd fix it (will confirm in a moment) but I reckon we should also fix the following assumption:
The size field being the last element of the received message format is only valid for messages carrying DENT
s, DATA
, or one of the status types like OKAY
/FAIL
. I'm referring to the definition for union syncmsg
at [0]. STAT
results are thus being interpreted as the size for a subsequent read which is what's blocking. Here's output with some extra logging:
DEBUG:adb_shell.adb_device:bulk_write(6): b'sync:\x00'
DEBUG:adb_shell.adb_device:Waiting to see [b'OKAY']
DEBUG:adb_shell.adb_device:bulk_read(24): b"OKAY'\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6"
DEBUG:adb_shell.adb_device:Finished _read_length -> bytearray(b'')
DEBUG:adb_shell.adb_device:bulk_write(24): b"WRTE\x01\x00\x00\x00'\x00\x00\x00\x12\x00\x00\x00\xd8\x04\x00\x00\xa8\xad\xab\xba"
DEBUG:adb_shell.adb_device:bulk_write(18): bytearray(b'STAT\n\x00\x00\x00/data/data')
DEBUG:adb_shell.adb_device:Waiting to see [b'OKAY']
DEBUG:adb_shell.adb_device:bulk_read(24): b"OKAY'\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6"
DEBUG:adb_shell.adb_device:Finished _read_length -> bytearray(b'')
DEBUG:adb_shell.adb_device:Need 16 bytes, have 0
DEBUG:adb_shell.adb_device:Waiting to see [b'WRTE']
DEBUG:adb_shell.adb_device:bulk_read(24): b"WRTE'\x00\x00\x00\x01\x00\x00\x00\x10\x00\x00\x00\xcb\x05\x00\x00\xa8\xad\xab\xba"
DEBUG:adb_shell.adb_device:Awaiting 16 more bytes
DEBUG:adb_shell.adb_device:bulk_read(16): b'STAT\xf9A\x00\x00\x00\xd0\x00\x00\xe8\xa1\x9c`'
DEBUG:adb_shell.adb_device:Finished _read_length -> bytearray(b'STAT\xf9A\x00\x00\x00\xd0\x00\x00\xe8\xa1\x9c`')
DEBUG:adb_shell.adb_device:bulk_write(24): b"OKAY\x01\x00\x00\x00'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6"
DEBUG:adb_shell.adb_device:About to read 1620877800 (command_id: b'STAT')
DEBUG:adb_shell.adb_device:Need 1620877800 bytes, have 0
DEBUG:adb_shell.adb_device:Waiting to see [b'WRTE']
Traceback (most recent call last):
...
I think what we should do in addition to what you already have in #156 would be to only set the size
var (L1106) and call self._filesync_read_buffered()
again for the sync reply messages which need that done. That'll make sure that regardless of what value read_data
has, we'll always handle messages properly.
In fact, that change might even remove the need for read_data
entirely since it only seems to be used as a shortcut for STAT
s :) If it were meaningful to do a PUSH/PULL/LIST
and then not read_data
, we could make that available to users in the public methods, but since the sync service on the device will send data regardless, it'll need to be drained by something on the client side...
Edit: That PR does fix the issue - viable fix :) Thanks for pushing it up so quickly!
[0] https://android.googlesource.com/platform/system/adb/+/refs/heads/master/file_sync_service.h
I pushed some changes to my pull request. I removed the read_data
parameter from _filesync_read()
and instead defined that variable inside the method as simply
read_data = command_id != constants.STAT
If there are other commands for which we shouldn't read data, they can easily be added to that check, but for now it looks like that's the only one.
I'll tag you as a reviewer on the pull request, please take a look when you get a chance.
Edit: it looks like I can't tag you as a reviewer... but please look it over.
Description
Run
device.stat("/any/path/which/exists")
with a USB transport device and observe that it now times out. It seems like something in the new code merged to fix #152 must be wrong.Log
Test code, with a USB ADB device plugged in:
Output: