Giter Site home page Giter Site logo

adb_shell's People

Contributors

atti92 avatar fnzr avatar halastra avatar hyperb1iss avatar jefflirion avatar kolanich avatar matthieuxyz avatar maybe-sybr avatar meator avatar tugayabdulla avatar zeibou avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adb_shell's Issues

Add support for pulling directories

Description

Was trying to automate a command where i pull a complete directory from the device.
Just like adb pull /sdcard/someDirectory

Log

Traceback (most recent call last):
  File "C:\Artland_script\Artland_logscript.py", line 52, in <module>
    device.pull("/sdcard/someDirectory",os.getcwd()+"\someDirectory")
  File "C:\Users\Wim.Matthijs\AppData\Local\Programs\Python\Python310\lib\site-packages\adb_shell\adb_device.py", line 944, in pull
    self._pull(device_path, stream, progress_callback, adb_info, filesync_info)
  File "C:\Users\Wim.Matthijs\AppData\Local\Programs\Python\Python310\lib\site-packages\adb_shell\adb_device.py", line 969, in _pull
    for cmd_id, _, data in self._filesync_read_until([constants.DATA], [constants.DONE], adb_info, filesync_info):
  File "C:\Users\Wim.Matthijs\AppData\Local\Programs\Python\Python310\lib\site-packages\adb_shell\adb_device.py", line 1433, in _filesync_read_until
    cmd_id, header, data = self._filesync_read(expected_ids + finish_ids, adb_info, filesync_info)
  File "C:\Users\Wim.Matthijs\AppData\Local\Programs\Python\Python310\lib\site-packages\adb_shell\adb_device.py", line 1372, in _filesync_read
    raise exceptions.AdbCommandFailureException('Command failed: {}'.format(reason))
adb_shell.exceptions.AdbCommandFailureException: Command failed: read failed: Is a directory

Support wireless debugging (STLS)

https://cs.android.com/android/platform/superproject/+/master:packages/modules/adb/protocol.txt;l=82-88

--- STLS(type, version, "") --------------------------------------------

Command constant: A_STLS

The TLS message informs the recipient that the connection will be encrypted
and will need to perform a TLS handshake. version is the current version of
the protocol.

If you see an error message of the form

adb_shell.exceptions.InvalidCommandError: Unknown command: 1397511251 = 'b'STLS'' (arg0 = 16777216, arg1 = 0, msg = 'b'STLS\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xac\xab\xb3\xac'')

It's because this is not supported by this package.

ADB Push fails: "Unable to unpack ADB command"

Hi there,

I was trying to push some files to the newest Android Emulator (stable v.30.2.5 x86_64) but the push command fails after sending '983040' bytes with a "Unable to unpack ADB command" (see Log 1). In another attempt I tried to send a file which is smaller than the '983040' bytes but the same error occurs (see Log 2) and from the progress log it seems like too many bytes were sent.

From the exception I can see that the error is raised in adb_message.py on Line 122 in the unpack method. Could it be that there is some new adb message which is not yet supported or something like that? Or has anyone an idea what's causing this error?

Thx for any help

Tom

Log 1

worker-low           | 2020-11-16 07:06:51 DEBUG    bulk_write: b'CNXN\x00\x00\x00\x01\x00\x00\x10\x00\x13\x00\x00\x00a\x05\x00\x00\xbc\xb1\xa7\xb1'
worker-low           | 2020-11-16 07:06:51 DEBUG    bulk_write: b'host::eb22059493bd\x00'
worker-low           | 2020-11-16 07:06:51 DEBUG    bulk_read(24): b'CNXN\x01\x00\x00\x01\x00\x00\x10\x00\x10\x01\x00\x00\xa1f\x00\x00\xbc\xb1\xa7\xb1'
worker-low           | 2020-11-16 07:06:51 DEBUG    bulk_read(272): b'device::ro.product.name=sdk_gphone_x86_64_arm64;ro.product.model=sdk_gphone_x86_64_arm64;ro.product.device=generic_x86_64_arm64;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'
worker-low           | 2020-11-16 07:06:51 INFO     ADB device xxx:5555 is connected: True
worker-low           | 2020-11-16 07:06:51 DEBUG    bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\xfe\x01\x00\x00\xb0\xaf\xba\xb1'
worker-low           | 2020-11-16 07:06:51 DEBUG    bulk_write: b'root:\x00'
worker-low           | 2020-11-16 07:06:51 DEBUG    bulk_read(24): b'OKAYj\x06\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
worker-low           | 2020-11-16 07:06:51 DEBUG    bulk_read(24): b'WRTEj\x06\x00\x00\x01\x00\x00\x00 \x00\x00\x00\x8c\x0b\x00\x00\xa8\xad\xab\xba'
worker-low           | 2020-11-16 07:06:51 DEBUG    bulk_read(32): b'adbd is already running as root\n'
worker-low           | 2020-11-16 07:06:51 DEBUG    bulk_write: b'OKAY\x01\x00\x00\x00j\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
worker-low           | 2020-11-16 07:06:51 DEBUG    bulk_read(24): b'CLSEj\x06\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
worker-low           | 2020-11-16 07:06:51 DEBUG    bulk_write: b'CLSE\x01\x00\x00\x00j\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
worker-low           | 2020-11-16 07:06:51 INFO     local_path: ./file_store/00_file_storage/libs/frida-server-14.0.8-android-x86_64
worker-low           | 2020-11-16 07:06:51 INFO     device_path: /data/local/tmp/frida-server-14.0.8-android-x86_64
worker-low           | 2020-11-16 07:06:51 DEBUG    bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\xf7\x01\x00\x00\xb0\xaf\xba\xb1'
worker-low           | 2020-11-16 07:06:51 DEBUG    bulk_write: b'sync:\x00'
worker-low           | 2020-11-16 07:06:51 DEBUG    bulk_read(24): b'CLSEj\x06\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
worker-low           | 2020-11-16 07:06:51 DEBUG    bulk_read(24): b'OKAYk\x06\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
worker-low           | 2020-11-16 07:06:51 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-x86_64 bytes_written:65536 total_bytes:29902472
worker-low           | 2020-11-16 07:06:51 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-x86_64 bytes_written:131072 total_bytes:29902472
worker-low           | 2020-11-16 07:06:51 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-x86_64 bytes_written:196608 total_bytes:29902472
worker-low           | 2020-11-16 07:06:51 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-x86_64 bytes_written:262144 total_bytes:29902472
worker-low           | 2020-11-16 07:06:51 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-x86_64 bytes_written:327680 total_bytes:29902472
worker-low           | 2020-11-16 07:06:51 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-x86_64 bytes_written:393216 total_bytes:29902472
worker-low           | 2020-11-16 07:06:51 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-x86_64 bytes_written:458752 total_bytes:29902472
worker-low           | 2020-11-16 07:06:51 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-x86_64 bytes_written:524288 total_bytes:29902472
worker-low           | 2020-11-16 07:06:51 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-x86_64 bytes_written:589824 total_bytes:29902472
worker-low           | 2020-11-16 07:06:51 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-x86_64 bytes_written:655360 total_bytes:29902472
worker-low           | 2020-11-16 07:06:51 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-x86_64 bytes_written:720896 total_bytes:29902472
worker-low           | 2020-11-16 07:06:51 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-x86_64 bytes_written:786432 total_bytes:29902472
worker-low           | 2020-11-16 07:06:51 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-x86_64 bytes_written:851968 total_bytes:29902472
worker-low           | 2020-11-16 07:06:51 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-x86_64 bytes_written:917504 total_bytes:29902472
worker-low           | 2020-11-16 07:06:51 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-x86_64 bytes_written:983040 total_bytes:29902472
worker-low           | 2020-11-16 07:06:51 DEBUG    bulk_write: b'WRTE\x01\x00\x00\x00k\x06\x00\x00\xb8\x00\x0f\x00\xba\xa5x\x05\xa8\xad\xab\xba'
worker-low           | 2020-11-16 07:06:51 DEBUG    bulk_write: bytearray(b'SEND8\x00\x00\x00/data/local/tmp/frida-server-14.0.8-android-x86_64,33272DAT...<ENDLESS NUMBER OF HEX BYTES>...\x00\x00\x00\x89t$0PW\xe8\xf1\xef\xff\xff\x83\xc4\x0c\x8b|$\x08W\xb8$\x00\x00\x00PP\xe8\xdd\xef\xff')

And then after some time this error occurres:

worker-low           | 2020-11-16 07:11:54 DEBUG    bulk_read(24): b''
worker-low           | 07:11:54 Traceback (most recent call last):
worker-low           |   File "/usr/local/lib/python3.7/site-packages/adb_shell/adb_message.py", line 120, in unpack
worker-low           |     cmd, arg0, arg1, data_length, data_checksum, _ = struct.unpack(constants.MESSAGE_FORMAT, message)
worker-low           | struct.error: unpack requires a buffer of 24 bytes
worker-low           | 
worker-low           | During handling of the above exception, another exception occurred:
worker-low           | 
worker-low           | Traceback (most recent call last):
worker-low           |   File "/usr/local/lib/python3.7/site-packages/rq/worker.py", line 936, in perform_job
worker-low           |     rv = job.perform()
worker-low           |   File "/usr/local/lib/python3.7/site-packages/rq/job.py", line 684, in perform
worker-low           |     self._result = self._execute()
worker-low           |   File "/usr/local/lib/python3.7/site-packages/rq/job.py", line 690, in _execute
worker-low           |     return self.func(*self.args, **self.kwargs)
worker-low           |   File "./scripts/dynamic_analysis/emulator_control/emulator_runner.py", line 21, in start_dynamic_analysis
worker-low           |     install_frida_server(adb_device)
worker-low           |   File "./scripts/dynamic_analysis/frida/frida_server_installer.py", line 17, in install_frida_server
worker-low           |     push_file(adb_device, local_path, device_path)
worker-low           |   File "./scripts/dynamic_analysis/emulator_control/adb/adb_wrapper.py", line 64, in push_file
worker-low           |     read_timeout_s=600)
worker-low           |   File "/usr/local/lib/python3.7/site-packages/adb_shell/adb_device.py", line 551, in push
worker-low           |     self._push(stream, _device_path, st_mode, mtime, progress_callback, adb_info, filesync_info)
worker-low           |   File "/usr/local/lib/python3.7/site-packages/adb_shell/adb_device.py", line 591, in _push
worker-low           |     self._filesync_send(constants.DATA, adb_info, filesync_info, data=data)
worker-low           |   File "/usr/local/lib/python3.7/site-packages/adb_shell/adb_device.py", line 1111, in _filesync_send
worker-low           |     self._filesync_flush(adb_info, filesync_info)
worker-low           |   File "/usr/local/lib/python3.7/site-packages/adb_shell/adb_device.py", line 963, in _filesync_flush
worker-low           |     self._write(filesync_info.send_buffer[:filesync_info.send_idx], adb_info)
worker-low           |   File "/usr/local/lib/python3.7/site-packages/adb_shell/adb_device.py", line 945, in _write
worker-low           |     self._read_until([constants.OKAY], adb_info)
worker-low           |   File "/usr/local/lib/python3.7/site-packages/adb_shell/adb_device.py", line 819, in _read_until
worker-low           |     cmd, remote_id2, local_id2, data = self._read(expected_cmds, adb_info)
worker-low           |   File "/usr/local/lib/python3.7/site-packages/adb_shell/adb_device.py", line 754, in _read
worker-low           |     cmd, arg0, arg1, data_length, data_checksum = unpack(msg)
worker-low           |   File "/usr/local/lib/python3.7/site-packages/adb_shell/adb_message.py", line 122, in unpack
worker-low           |     raise ValueError('Unable to unpack ADB command. (length={})'.format(len(message)), constants.MESSAGE_FORMAT, message, e)
worker-low           | ValueError: ('Unable to unpack ADB command. (length=0)', b'<6I', b'', error('unpack requires a buffer of 24 bytes'))
worker-low           | Traceback (most recent call last):
worker-low           |   File "/usr/local/lib/python3.7/site-packages/adb_shell/adb_message.py", line 120, in unpack
worker-low           |     cmd, arg0, arg1, data_length, data_checksum, _ = struct.unpack(constants.MESSAGE_FORMAT, message)
worker-low           | struct.error: unpack requires a buffer of 24 bytes

worker-low           | Traceback (most recent call last):
worker-low           |   File "/usr/local/lib/python3.7/site-packages/rq/worker.py", line 936, in perform_job
worker-low           |     rv = job.perform()
worker-low           |   File "/usr/local/lib/python3.7/site-packages/rq/job.py", line 684, in perform
worker-low           |     self._result = self._execute()
worker-low           |   File "/usr/local/lib/python3.7/site-packages/rq/job.py", line 690, in _execute
worker-low           |     return self.func(*self.args, **self.kwargs)
worker-low           |   File "./scripts/dynamic_analysis/emulator_control/emulator_runner.py", line 21, in start_dynamic_analysis
worker-low           |     install_frida_server(adb_device)
worker-low           |   File "./scripts/dynamic_analysis/frida/frida_server_installer.py", line 17, in install_frida_server
worker-low           |     push_file(adb_device, local_path, device_path)
worker-low           |   File "./scripts/dynamic_analysis/emulator_control/adb/adb_wrapper.py", line 64, in push_file
worker-low           |     read_timeout_s=600)
worker-low           |   File "/usr/local/lib/python3.7/site-packages/adb_shell/adb_device.py", line 551, in push
worker-low           |     self._push(stream, _device_path, st_mode, mtime, progress_callback, adb_info, filesync_info)
worker-low           |   File "/usr/local/lib/python3.7/site-packages/adb_shell/adb_device.py", line 591, in _push
worker-low           |     self._filesync_send(constants.DATA, adb_info, filesync_info, data=data)
worker-low           |   File "/usr/local/lib/python3.7/site-packages/adb_shell/adb_device.py", line 1111, in _filesync_send
worker-low           |     self._filesync_flush(adb_info, filesync_info)
worker-low           |   File "/usr/local/lib/python3.7/site-packages/adb_shell/adb_device.py", line 963, in _filesync_flush
worker-low           |     self._write(filesync_info.send_buffer[:filesync_info.send_idx], adb_info)
worker-low           |   File "/usr/local/lib/python3.7/site-packages/adb_shell/adb_device.py", line 945, in _write
worker-low           |     self._read_until([constants.OKAY], adb_info)
worker-low           |   File "/usr/local/lib/python3.7/site-packages/adb_shell/adb_device.py", line 819, in _read_until
worker-low           |     cmd, remote_id2, local_id2, data = self._read(expected_cmds, adb_info)
worker-low           |   File "/usr/local/lib/python3.7/site-packages/adb_shell/adb_device.py", line 754, in _read
worker-low           |     cmd, arg0, arg1, data_length, data_checksum = unpack(msg)
worker-low           |   File "/usr/local/lib/python3.7/site-packages/adb_shell/adb_message.py", line 122, in unpack
worker-low           |     raise ValueError('Unable to unpack ADB command. (length={})'.format(len(message)), constants.MESSAGE_FORMAT, message, e)
worker-low           | ValueError: ('Unable to unpack ADB command. (length=0)', b'<6I', b'', error('unpack requires a buffer of 24 bytes'))

Log 2

worker-low           | 2020-11-16 07:19:44 DEBUG    bulk_write: b'CNXN\x00\x00\x00\x01\x00\x00\x10\x00\x13\x00\x00\x00l\x05\x00\x00\xbc\xb1\xa7\xb1'
worker-low           | 2020-11-16 07:19:44 DEBUG    bulk_write: b'host::ff918e63b615\x00'
worker-low           | 2020-11-16 07:19:44 DEBUG    bulk_read(24): b'CNXN\x01\x00\x00\x01\x00\x00\x10\x00\x10\x01\x00\x00\xa1f\x00\x00\xbc\xb1\xa7\xb1'
worker-low           | 2020-11-16 07:19:44 DEBUG    bulk_read(272): b'device::ro.product.name=sdk_gphone_x86_64_arm64;ro.product.model=sdk_gphone_x86_64_arm64;ro.product.device=generic_x86_64_arm64;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'
worker-low           | 2020-11-16 07:19:44 INFO     ADB device xxxx:5555 is connected: True
worker-low           | 2020-11-16 07:19:44 DEBUG    bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\xfe\x01\x00\x00\xb0\xaf\xba\xb1'
worker-low           | 2020-11-16 07:19:44 DEBUG    bulk_write: b'root:\x00'
worker-low           | 2020-11-16 07:19:44 DEBUG    bulk_read(24): b'OKAY\x86\x06\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
worker-low           | 2020-11-16 07:19:44 DEBUG    bulk_read(24): b'WRTE\x86\x06\x00\x00\x01\x00\x00\x00 \x00\x00\x00\x8c\x0b\x00\x00\xa8\xad\xab\xba'
worker-low           | 2020-11-16 07:19:44 DEBUG    bulk_read(32): b'adbd is already running as root\n'
worker-low           | 2020-11-16 07:19:44 DEBUG    bulk_write: b'OKAY\x01\x00\x00\x00\x86\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
worker-low           | 2020-11-16 07:19:44 DEBUG    bulk_read(24): b'CLSE\x86\x06\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
worker-low           | 2020-11-16 07:19:44 DEBUG    bulk_write: b'CLSE\x01\x00\x00\x00\x86\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
worker-low           | 2020-11-16 07:19:44 INFO     local_path: ./file_store/00_file_storage/libs/frida-server-14.0.8-android-arm
worker-low           | 2020-11-16 07:19:44 INFO     device_path: /data/local/tmp/frida-server-14.0.8-android-arm
worker-low           | 2020-11-16 07:19:44 DEBUG    bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\xf7\x01\x00\x00\xb0\xaf\xba\xb1'
worker-low           | 2020-11-16 07:19:44 DEBUG    bulk_write: b'sync:\x00'
worker-low           | 2020-11-16 07:19:44 DEBUG    bulk_read(24): b'CLSE\x86\x06\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
worker-low           | 2020-11-16 07:19:44 DEBUG    bulk_read(24): b'OKAY\x87\x06\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
worker-low           | 2020-11-16 07:19:44 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-arm bytes_written:65536 total_bytes:8814864
worker-low           | 2020-11-16 07:19:44 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-arm bytes_written:131072 total_bytes:8814864
worker-low           | 2020-11-16 07:19:44 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-arm bytes_written:196608 total_bytes:8814864
worker-low           | 2020-11-16 07:19:44 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-arm bytes_written:262144 total_bytes:8814864
worker-low           | 2020-11-16 07:19:44 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-arm bytes_written:327680 total_bytes:8814864
worker-low           | 2020-11-16 07:19:44 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-arm bytes_written:393216 total_bytes:8814864
worker-low           | 2020-11-16 07:19:44 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-arm bytes_written:458752 total_bytes:8814864
worker-low           | 2020-11-16 07:19:44 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-arm bytes_written:524288 total_bytes:8814864
worker-low           | 2020-11-16 07:19:44 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-arm bytes_written:589824 total_bytes:8814864
worker-low           | 2020-11-16 07:19:44 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-arm bytes_written:655360 total_bytes:8814864
worker-low           | 2020-11-16 07:19:44 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-arm bytes_written:720896 total_bytes:8814864
worker-low           | 2020-11-16 07:19:44 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-arm bytes_written:786432 total_bytes:8814864
worker-low           | 2020-11-16 07:19:44 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-arm bytes_written:851968 total_bytes:8814864
worker-low           | 2020-11-16 07:19:44 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-arm bytes_written:917504 total_bytes:8814864
worker-low           | 2020-11-16 07:19:44 INFO     ADB Push-Progress: /data/local/tmp/frida-server-14.0.8-android-arm bytes_written:983040 total_bytes:8814864
worker-low           | 2020-11-16 07:19:44 DEBUG    bulk_write: b'WRTE\x01\x00\x00\x00\x87\x06\x00\x00\xb5\x00\x0f\x00\xdd\x15l\x05\xa8\xad\xab\xba'

How to connect more than two devices at the same time?

Creating two AdbDeviceUsb objects with different SNs will report an error๏ผš

from adb_shell.adb_device import AdbDeviceTcp, AdbDeviceUsb
from adb_shell.auth.sign_pythonrsa import PythonRSASigner

# Load the public and private keys
adbkey = 'adbkey'
with open(adbkey) as f:
    priv = f.read()
with open(adbkey + '.pub') as f:
     pub = f.read()
signer = PythonRSASigner(pub, priv)

# Connect via USB (package must be installed via `pip install adb-shell[usb])`
device2 = AdbDeviceUsb(serial="230YV16C83002B")
device2.connect(rsa_keys=[signer], auth_timeout_s=0.1)

device3 = AdbDeviceUsb(serial="230YT16C83002G")
device3.connect(rsa_keys=[signer], auth_timeout_s=0.1)
Traceback (most recent call last):
  File "testDUTS.py", line 16, in <module>
    device3 = AdbDeviceUsb(serial="230YT16C83002G")
  File "C:\python37\lib\site-packages\adb_shell\adb_device.py", line 1552, in __init__
    transport = UsbTransport.find_adb(serial, port_path, default_transport_timeout_s)
  File "C:\python37\lib\site-packages\adb_shell\transport\usb_transport.py", line 628, in find_adb
    default_transport_timeout_s=default_transport_timeout_s
  File "C:\python37\lib\site-packages\adb_shell\transport\usb_transport.py", line 512, in _find
    return cls._find_first(setting_matcher, device_matcher, usb_info=usb_info, default_transport_timeout_s=default_transport_timeout_s)
  File "C:\python37\lib\site-packages\adb_shell\transport\usb_transport.py", line 601, in _find_first
    return next(cls._find_devices(setting_matcher, device_matcher=device_matcher, usb_info=usb_info, default_transport_timeout_s=default_transport_timeout_s))
  File "C:\python37\lib\site-packages\adb_shell\transport\usb_transport.py", line 569, in _find_devices
    if device_matcher is None or device_matcher(transport):
  File "C:\python37\lib\site-packages\adb_shell\transport\usb_transport.py", line 475, in <lambda>
    return lambda device: device.serial_number == serial
  File "C:\python37\lib\site-packages\adb_shell\transport\usb_transport.py", line 415, in serial_number
    return self._device.getSerialNumber()
  File "C:\python37\lib\site-packages\usb1\__init__.py", line 2019, in getSerialNumber
    return self.open().getSerialNumber()
  File "C:\python37\lib\site-packages\usb1\__init__.py", line 2055, in open
    mayRaiseUSBError(libusb1.libusb_open(self.device_p, byref(handle)))
  File "C:\python37\lib\site-packages\usb1\__init__.py", line 127, in mayRaiseUSBError
    __raiseUSBError(value)
  File "C:\python37\lib\site-packages\usb1\__init__.py", line 119, in raiseUSBError
    raise __STATUS_TO_EXCEPTION_DICT.get(value, __USBError)(value)
usb1.USBErrorAccess: LIBUSB_ERROR_ACCESS [-3]

Old adb server version (31) is not supported using AdbDeviceTcp

The following snippet crashes when trying to connect to the adb using tcp

from adb_shell.adb_device import AdbDeviceTcp
from adb_shell.auth.sign_pythonrsa import PythonRSASigner

adbkey = r'path/to/adbkey'

with open(adbkey) as f:
    priv = f.read()
with open(adbkey + '.pub') as f:
     pub = f.read()
signer = PythonRSASigner(pub, priv)

device1 = AdbDeviceTcp('127.0.0.1', 5553, default_transport_timeout_s=9.)
device1.connect(rsa_keys=[signer], auth_timeout_s=0.1)

And this is the traceback that I'm getting:

Traceback (most recent call last):
  File "c:\temp\adbtest.py", line 15, in <module>
    device1.connect(auth_timeout_s=0.1)
  File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\adb_shell\adb_device.py", line 219, in connect
    cmd, arg0, arg1, banner = self._read([constants.AUTH, constants.CNXN], adb_info)
  File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\adb_shell\adb_device.py", line 754, in _read
    cmd, arg0, arg1, data_length, data_checksum = unpack(msg)
  File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\adb_shell\adb_message.py", line 122, in unpack
    raise ValueError('Unable to unpack ADB command. (length={})'.format(len(message)), constants.MESSAGE_FORMAT, message, e)
ValueError: ('Unable to unpack ADB command. (length=0)', b'<6I', b'', error('unpack requires a buffer of 24 bytes'))

After analyzing the protocol and the data that is sent over the ADB protocol, I noticed that the adb library tries to send one type of data (CNXN message) and does not receive any response, while the adb.exe binary sends a different type of message, and receives a response.

Here is how the adb-shell library sends the data (note it does not receive any response)
image

This is the adb.exe message (with a response)
image

"Empty" messages incorrectly send empty bulk_writes, which breaks the USB transport

Description

Calling _send() on a message with an empty data field sends a spurious USB write that confuses ADB. This may actually have exposed a bug in adb, but it's trivial enough to workaround here.

It's somewhat surprising that this wasn't already caught, because this breaks any multi-packet operations over USB on affected versions of adb.

Log

DEBUG:adb_shell.adb_device:bulk_write: b'OKAY\x01\x00\x00\x00\r\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
DEBUG:adb_shell.adb_device:bulk_write: b''
<REDACTED>
Traceback (most recent call last):
File "/home/<redacted>/.local/lib/python3.8/site-packages/adb_shell/transport/usb_transport.py", line 278, in bulk_read
return bytes(self._transport.bulkRead(self._read_endpoint, numbytes, timeout=self._timeout_ms(transport_timeout_s)))                                                                                             File "/home/<redacted>/.local/lib/python3.8/site-packages/usb1/__init__.py", line 1569, in bulkRead
transferred = self._bulkTransfer(endpoint, data, length, timeout)
File "/home/<redacted>/.local/lib/python3.8/site-packages/usb1/__init__.py", line 1517, in _bulkTransfer
mayRaiseUSBError(libusb1.libusb_bulk_transfer(
File "/home/<redacted>/.local/lib/python3.8/site-packages/usb1/__init__.py", line 133, in mayRaiseUSBError
__raiseUSBError(value) 
File "/home/<redacted>/.local/lib/python3.8/site-packages/usb1/__init__.py", line 125, in raiseUSBError
raise __STATUS_TO_EXCEPTION_DICT.get(value, __USBError)(value)
usb1.USBErrorTimeout: LIBUSB_ERROR_TIMEOUT [-7]

Solution/Workaround:
add an if len(msg.data) > 0: check to _send so it doesn't "send" the data component if there's no data (too lazy to fork and PR for one line)

Background a task

Is their a way to run a task in the following way:

device.shell('su -c "nohup ./bla &"')

and have it go into the background without adb_shell timing out with:

adb_shell.exceptions.TcpTimeoutException: Reading from <IO>:5555 timed out (10.0 seconds)

Thanks

Root access

First of all thanks for this awesome library - it was really nice to work with it so far!

I was wondering how can I "enter" to a root "mode", the equivalent of this simple shell command -
adb root

Is it possible to do it with this library? If not, could you please add this functionality?

Many thanks!

A few lines to add "adb exec-out" support.

from adb_shell.adb_device import AdbDeviceTcp as _AdbDeviceTcp, constants, exceptions


class AdbDeviceTcp(_AdbDeviceTcp):
    def exec(
        self,
        command,
        transport_timeout_s=None,
        read_timeout_s=constants.DEFAULT_READ_TIMEOUT_S,
        timeout_s=None,
        decode=True,
    ):
        if not self.available:
            raise exceptions.AdbConnectionError(
                "ADB command not sent because a connection to the device has not been established.  (Did you call `AdbDevice.connect()`?)"
            )

        return self._service(
            b"exec",  # send exec instead of shell
            command.encode("utf8"),
            transport_timeout_s,
            read_timeout_s,
            timeout_s,
            decode,
        )

I'd like to see this feature soon. XD. Sorry for not able to submit a PR myself.

No UsbTransport detected.

Hi!
I want to try the USB experimental mode, but I have some issues when installing the optional module. I have a script that uses this amazing ๐Ÿ˜Ž library, and I want to upgrade it by implementing the USB mode. As it is written, before any attempt, I ran the command install adb-shell[usb]. Then, just copy-pasted the test code:

from adb_shell.adb_device import AdbDeviceUsb
from adb_shell.auth.sign_pythonrsa import PythonRSASigner

with open('path/to/the/adbkey') as f:
    priv = f.read()
signer = PythonRSASigner('', priv)
device = AdbDeviceUsb('ab78c6ef')
print(device.connect(rsa_keys=[signer], auth_timeout_s=0.1))

But the following error raises:

adb_shell.exceptions.InvalidTransportError: To enable USB support you must install this package via `pip install adb-shell[usb]`

So I tried again uninstalling the module (completely) and installing it again. Note that I invalidated the cache before reinstalling, so no residual files should be stored. But this error raised again. If I run install adb-shell[usb] again, I get:

Requirement already satisfied: adb-shell[usb] in path\site-packages (0.2.0)
Requirement already satisfied: cryptography in path\site-packages (from adb-shell[usb]) (3.0)
Requirement already satisfied: pyasn1 in path\site-packages (from adb-shell[usb]) (0.4.8)
Requirement already satisfied: rsa in path\site-packages (from adb-shell[usb]) (4.6)
Requirement already satisfied: libusb1>=1.0.16; extra == "usb" in path\site-packages (from adb-shell[usb]) (1.8)
Requirement already satisfied: cffi!=1.11.3,>=1.8 in path\site-packages (from cryptography->adb-shell[usb]) (1.14.1)
Requirement already satisfied: six>=1.4.1 in path\site-packages (from cryptography->adb-shell[usb]) (1.15.0)
Requirement already satisfied: pycparser in path\site-packages (from cffi!=1.11.3,>=1.8->cryptography->adb-shell[usb]) (2.20)

I don't understand what causes the error to be raised, especially after searching what the brackets in adb-shell[usb] means and getting this already satisfied requirements.
Sorry if it's a stupid question, but I don't know what is wrong.
Thanks!

How can I determine which devices are available to connect to?

In the example code in the readme, we find the line

device1 = AdbDevice(serial='192.168.0.111:5555', default_timeout_s=9.)

This seems to suggest that in order to use this library to talk to a device, I need to know its IP and port already. Is there a facility in this library to obtain this information? If not, I'd suggest there should be.

Issue in connecting adb over usb

Traceback (most recent call last):
File "/home//main.py", line 16, in
device.connect(rsa_keys=[signer], auth_timeout_s=10)
File "/home/
//venv/lib/python3.8/site-packages/adb_shell/adb_device.py", line 649, in connect
self._available, self._maxdata = self._io_manager.connect(self._banner, rsa_keys, auth_timeout_s, auth_callback, adb_info)
File "/home///venv/lib/python3.8/site-packages/adb_shell/adb_device.py", line 195, in connect
self._transport.connect(adb_info.transport_timeout_s)
File "/home/
//venv/lib/python3.8/site-packages/adb_shell/transport/usb_transport.py", line 230, in connect
assert read_endpoint is not None
AssertionError

USB support?

Is there currently any way to connect to a device over USB?
It seems like this is not implemented yet, but I thought I'd ask.. just in case I'm missing something.

ADB key

Hello,

in the example in your readme you use an adb key, but how does one generate such a key? What format is required? DER? OpenSSH? PEM?

device.shell() command raising utf-8 decode issues

Description

I am using adb_shell in a project of mine in order to automate file downloads as well as extracting diagnostic information from the device. I encountered an issue with retrieving output from logcat, which raises the following exception.

Log

Traceback (most recent call last):
  File "/home/user/projects/mvt/mvt/mvt/common/module.py", line 143, in run_module
    module.run()
  File "/home/user/projects/mvt/mvt/mvt/android/modules/adb/logcat.py", line 27, in run
    output = self._adb_command("logcat -d")
  File "/home/user/projects/mvt/mvt/mvt/android/modules/adb/base.py", line 109, in _adb_command
    return self.device.shell(command)
  File "/home/user/.local/lib/python3.9/site-packages/adb_shell/adb_device.py", line 792, in shell
    return self._service(b'shell', command.encode('utf8'), transport_timeout_s, read_timeout_s, timeout_s, decode)
  File "/home/user/.local/lib/python3.9/site-packages/adb_shell/adb_device.py", line 681, in _service
    return b''.join(self._streaming_command(service, command, transport_timeout_s, read_timeout_s, timeout_s)).decode('utf8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe0 in position 1666311: invalid continuation byte  

Add license file

Description

Please add the LICENSE file to the source tarball. Thanks.

Unpack requieres a buffer of 24 bytes

I have a Rpi running Home Assistant OS 6.2

In my configuration.yaml

media_player:
  - platform: androidtv
    name: Fire_Stick
    host: 192.168.1.73

It works fine with my Fire TV stick 4K, but only at first. He disconnects very often and, after a while, he disconnects permanently.

It doesn't seem like my problem is the one that is fixed using Wakelock.

This is my log:

2021-08-11 19:20:12 DEBUG (MainThread) [adb_shell.adb_device_async] bulk_write(24): b'CNXN\x00\x00\x00\x01\x00\x00\x10\x00\x14\x00\x00\x00\xb5\x07\x00\x00\xbc\xb1\xa7\xb1'
2021-08-11 19:20:12 DEBUG (MainThread) [adb_shell.adb_device_async] bulk_write(20): b'host::homeassistant\x00'
2021-08-11 19:20:12 DEBUG (MainThread) [adb_shell.adb_device_async] bulk_read(24): b''
2021-08-11 19:20:12 WARNING (MainThread) [androidtv.adb_manager.adb_manager_async] Couldn't connect to 192.168.1.73:5555.  ValueError: ('Unable to unpack ADB command. (length=0)', b'<6I', b'', error('unpack requires a buffer of 24 bytes'))
2021-08-11 19:20:12 WARNING (MainThread) [homeassistant.components.androidtv.media_player] Could not connect to Fire_Stick at 192.168.1.73:5555 using Python ADB implementation with adbkey='/config/.storage/androidtv_adbkey'

It is very strange, because obviously it comes to accept the adbkey at the beginning, but it stops doing it even without the wifi communication being interrupted, or any device rebooting ...

Any idea to solve it?

[Feature Request] FileSync Protocol

Hello,

Python-abd, implements the FileSync protocol in addition to the shell. (Push in particullar) Is it planned to include FileSync in the adb_shell project?

Also, the python-abd, has a hard-coded limit of 2ko per message, do you know why? Is it possible to increase this limit?

`device.stat()` times out over USB transport in 0.3.2

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:

import logging
import pathlib

import adb_shell.adb_device
import adb_shell.auth.sign_pythonrsa
import adb_shell.transport.usb_transport

logging.basicConfig(level=logging.DEBUG)

adbkey_path = pathlib.Path("~/.android/adbkey").expanduser()
signer = adb_shell.auth.sign_pythonrsa.PythonRSASigner.FromRSAKeyPath(str(adbkey_path))

handle = adb_shell.transport.usb_transport.UsbTransport.find_adb()
device = adb_shell.adb_device.AdbDeviceUsb(port_path=handle.port_path)

device.connect([signer])
try:
    device.shell("echo hello world")
    device.stat("/")
finally:
    device.close()

Output:

DEBUG:adb_shell.adb_device:bulk_write(24): b'CNXN\x00\x00\x00\x01\x00\x00\x10\x00\x0c\x00\x00\x00>\x04\x00\x00\xbc\xb1\xa7\xb1'
DEBUG:adb_shell.adb_device:bulk_write(12): b'host::karma\x00'
DEBUG:adb_shell.adb_device:bulk_read(24): b'CLSE\xbb\x01\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'AUTH\x01\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00D\x08\x00\x00\xbe\xaa\xab\xb7'
DEBUG:adb_shell.adb_device:bulk_read(20): b'\x12\xfb\xa0\x02\xc9JZ\xfe)E\xec|\x00\x1b0w\x18\xe8^4'
DEBUG:adb_shell.adb_device:bulk_write(24): b'AUTH\x02\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00M\x80\x00\x00\xbe\xaa\xab\xb7'
DEBUG:adb_shell.adb_device:bulk_write(256): b'0\x05\x97\x16\xe2\x81F\xb2\x9d\xa5U\xbc\xffP\xf0\nH\r\x95\x054\x86\xe3eX\x06\xbb\x08\xb8\x9fV\xe0d\xb9t\x13\x87R\x8a\xda\xe2\xe6\xfa\xdb.\n\xa1\xe0\x04\x1f\xab&%/\xf5\x1e\'\xf4\x1a\xffx\xb0\x15\xcd\xbb\xa7\xb7\xf9\xc5\xca\xc2\xa9T\x01\xc2\x14\xaf\xf79\x1a\xed\xa4\xe4\xb9\xb0\xa9\'\x0b.P\x95\xb4UK?\xbeF\x88\xf1\xe9\x0fr"\xe8\x14\xa5t\xd2\xac\xbc\xac\xca\xa6\xe17Bt\xb8\xcbd\xc7\xaeO\x10\x1a=v\xf2N\\\xdf\x8d\xaa\xd5\x14\xf3Ei\xb4\xcb\x13\x7f\x1e3\xc1\x9cG\x1fI\xeeM\xc4\x94w\xe3\x1c\x8d\xa5\x03\x81d\x1bM\xfeYn\xb3n\xd65\x9b\x94\x02\xdese\xd8\xe9\xfa\x8b\xe6G\xa7\x04\x05\xf1\x8b\x0fK\xd5i\xb8B\xb7\x81\xaft@\xa3\xf1L,\xaddR\x9f\x9dB\t\x9f\x00\xc2t\x19azlN\xe0\x93A\xc6\xf2(\x9f\x00E9\xb8p\x1b\xcd\x82\xcb\xe3j\x7f\x85\x84\xa2\xa4\xb2\xc1q=\x98\x07u\xe1\xb0\xcc\xafy\xddMM'
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\xbc\x01\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\xbc\x01\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\xbc\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
DEBUG:adb_shell.adb_device:bulk_read(24): b'CLSE\xbc\x01\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\xbc\x01\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\xbc\x01\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\xbd\x01\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\xbd\x01\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\xbd\x01\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\xbd\x01\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\xbd\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
Traceback (most recent call last):
  File "/work/.venv/lib64/python3.8/site-packages/adb_shell/transport/usb_transport.py", line 278, in bulk_read
    return bytes(self._transport.bulkRead(self._read_endpoint, numbytes, timeout=self._timeout_ms(transport_timeout_s)))
  File "/work/.venv/lib64/python3.8/site-packages/usb1/__init__.py", line 1429, in bulkRead
    transferred = self._bulkTransfer(endpoint, data, length, timeout)
  File "/work/.venv/lib64/python3.8/site-packages/usb1/__init__.py", line 1377, in _bulkTransfer
    mayRaiseUSBError(libusb1.libusb_bulk_transfer(
  File "/work/.venv/lib64/python3.8/site-packages/usb1/__init__.py", line 127, in mayRaiseUSBError
    __raiseUSBError(value)
  File "/work/.venv/lib64/python3.8/site-packages/usb1/__init__.py", line 119, in raiseUSBError
    raise __STATUS_TO_EXCEPTION_DICT.get(value, __USBError)(value)
usb1.USBErrorTimeout: LIBUSB_ERROR_TIMEOUT [-7]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "stat.py", line 19, in <module>
    device.stat("/")
  File "/work/.venv/lib64/python3.8/site-packages/adb_shell/adb_device.py", line 711, in stat
    _, (mode, size, mtime), _ = self._filesync_read([constants.STAT], adb_info, filesync_info, read_data=False)
  File "/work/.venv/lib64/python3.8/site-packages/adb_shell/adb_device.py", line 1107, in _filesync_read
    data = self._filesync_read_buffered(size, adb_info, filesync_info)
  File "/work/.venv/lib64/python3.8/site-packages/adb_shell/adb_device.py", line 1142, in _filesync_read_buffered
    _, data = self._read_until([constants.WRTE], adb_info)
  File "/work/.venv/lib64/python3.8/site-packages/adb_shell/adb_device.py", line 918, in _read_until
    cmd, remote_id2, local_id2, data = self._read(expected_cmds, adb_info)
  File "/work/.venv/lib64/python3.8/site-packages/adb_shell/adb_device.py", line 866, in _read
    msg = self._transport.bulk_read(constants.MESSAGE_SIZE, adb_info.transport_timeout_s)
  File "/work/.venv/lib64/python3.8/site-packages/adb_shell/transport/usb_transport.py", line 280, in bulk_read
    raise exceptions.UsbReadFailedError('Could not receive data from %s (timeout %sms)' % (self.usb_info, self._timeout_ms(transport_timeout_s)), e)
adb_shell.exceptions.UsbReadFailedError: Could not receive data from [3, 8, 4, 2, 3] RF8N20P1Y4B (timeout 10000ms): LIBUSB_ERROR_TIMEOUT [-7]

Not working on windows

Description

Trying to connect to a local simulator (Nox Simulator) on windows, get TypeError while connecting to socket

from adb_shell.adb_device import AdbDeviceTcp
device1 = AdbDeviceTcp('127.0.0.1', 62001)
device1.shell("adb shell input tap 10 10")

Traceback

Traceback (most recent call last):
  File "D:/Work/Projects/PCRHelper/__main__.py", line 3, in <module>
    device1.shell("adb shell input tap 10 10")
  File "D:\Work\env\PCRHelper\lib\site-packages\adb_shell\adb_device.py", line 460, in shell
    return self._service(b'shell', command.encode('utf8'), timeout_s, total_timeout_s, decode)
  File "D:\Work\env\PCRHelper\lib\site-packages\adb_shell\adb_device.py", line 404, in _service
    return b''.join(self._streaming_command(service, command, adb_info)).decode('utf8')
  File "D:\Work\env\PCRHelper\lib\site-packages\adb_shell\adb_device.py", line 1011, in _streaming_command
    self._open(b'%s:%s' % (service, command), adb_info)
  File "D:\Work\env\PCRHelper\lib\site-packages\adb_shell\adb_device.py", line 795, in _open
    self._send(msg, adb_info)
  File "D:\Work\env\PCRHelper\lib\site-packages\adb_shell\adb_device.py", line 980, in _send
    self._handle.bulk_write(msg.pack(), adb_info.timeout_s)
  File "D:\Work\env\PCRHelper\lib\site-packages\adb_shell\handle\tcp_handle.py", line 151, in bulk_write
    _, writeable, _ = select.select([], [self._connection], [], timeout)
TypeError: argument must be an int, or have a fileno() method.

Found a Question on StackOverflow that might be helpful (select doesn't work with non-socket objects on windows)

default_transport_timeout_s is ignored

Description

If you set default transport timeout to 60 seconds, and run a binary that sleeps for 15 seconds, it will throw a tcp timeout error

device = AdbDeviceTcp(ip, int(port), default_transport_timeout_s=60)

Log

  File "/usr/local/lib/python3.8/site-packages/adb_shell/adb_device.py", line 842, in shell
    return self._service(b'shell', command.encode('utf8'), transport_timeout_s, read_timeout_s, timeout_s, decode)
  File "/usr/local/lib/python3.8/site-packages/adb_shell/adb_device.py", line 710, in _service
    return b''.join(self._streaming_command(service, command, transport_timeout_s, read_timeout_s, timeout_s)).decode('utf8', _DECODE_ERRORS)
  File "/usr/local/lib/python3.8/site-packages/adb_shell/adb_device.py", line 1290, in _streaming_command
    for data in self._read_until_close(adb_info):
  File "/usr/local/lib/python3.8/site-packages/adb_shell/adb_device.py", line 1243, in _read_until_close
    cmd, data = self._read_until([constants.CLSE, constants.WRTE], adb_info)
  File "/usr/local/lib/python3.8/site-packages/adb_shell/adb_device.py", line 1213, in _read_until
    cmd, _, _, data = self._io_manager.read(expected_cmds, adb_info, allow_zeros=True)
  File "/usr/local/lib/python3.8/site-packages/adb_shell/adb_device.py", line 339, in read
    cmd, arg0, arg1, data = self._read_packet_from_device(adb_info)
  File "/usr/local/lib/python3.8/site-packages/adb_shell/adb_device.py", line 486, in _read_packet_from_device
    msg = self._read_bytes_from_device(constants.MESSAGE_SIZE, adb_info)
  File "/usr/local/lib/python3.8/site-packages/adb_shell/adb_device.py", line 442, in _read_bytes_from_device
    temp = self._transport.bulk_read(length, adb_info.transport_timeout_s)
  File "/usr/local/lib/python3.8/site-packages/adb_shell/transport/tcp_transport.py", line 120, in bulk_read
    raise TcpTimeoutException(msg)
adb_shell.exceptions.TcpTimeoutException: Reading from 1.2.3.4:1234 timed out (10.0 seconds)

Pushing large files always timeouts

I am trying to push 30Mo+ file to my Nvidia Shield device.

It works with small text files but not with bigger ones.

import logging
from os import getcwd
from os.path import abspath, basename, dirname, exists, join

from adb_shell.adb_device import AdbDeviceTcp
from adb_shell.auth.keygen import keygen
from adb_shell.auth.sign_pythonrsa import PythonRSASigner

logging.basicConfig(level=logging.INFO)


def main():
    pvt_key = join(dirname(abspath(__file__)), "adbkey")
    pub_key = pvt_key + ".pub"
    if not exists(pvt_key):
        keygen(pvt_key)
    with open(pub_key) as f:
        pub_bin = f.read()
    with open(pvt_key) as f:
        pvt_bin = f.read()
    manager = AdbDeviceTcp("192.168.1.62")
    manager.connect(rsa_keys=[PythonRSASigner(pub_bin, pvt_bin)], auth_timeout_s=0.1)
    package = join(getcwd(), "package.apk")
    deposit = join("/sdcard", basename(package))
    manager.push(package, deposit, progress_callback=callback)


def callback(device_path, bytes_written, total_bytes):
    logging.info(f"Progress: {device_path} written:{bytes_written} total:{total_bytes}")


main()

This is what I get from the logger, it seems to be blocked at 65536 bytes.

INFO:root:Progress: /sdcard/package.apk written:65536 total:83586453
INFO:root:Progress: /sdcard/package.apk written:65536 total:83586453
INFO:root:Progress: /sdcard/package.apk written:65536 total:83586453
INFO:root:Progress: /sdcard/package.apk written:65536 total:83586453
INFO:root:Progress: /sdcard/package.apk written:65536 total:83586453
INFO:root:Progress: /sdcard/package.apk written:65536 total:83586453
INFO:root:Progress: /sdcard/package.apk written:65536 total:83586453
INFO:root:Progress: /sdcard/package.apk written:65536 total:83586453
INFO:root:Progress: /sdcard/package.apk written:65536 total:83586453
INFO:root:Progress: /sdcard/package.apk written:65536 total:83586453
INFO:root:Progress: /sdcard/package.apk written:65536 total:83586453
INFO:root:Progress: /sdcard/package.apk written:65536 total:83586453
INFO:root:Progress: /sdcard/package.apk written:65536 total:83586453
INFO:root:Progress: /sdcard/package.apk written:65536 total:83586453
INFO:root:Progress: /sdcard/package.apk written:65536 total:83586453

And there is the traceback.

Traceback (most recent call last):
  File "/home/lan/Documents/demo/test.py", line 34, in <module>
    main()
  File "/home/lan/Documents/demo/test.py", line 27, in main
    manager.push(package, deposit, progress_callback=callback)
  File "/home/lan/.local/lib/python3.10/site-packages/adb_shell/adb_device.py", line 1017, in push
    self._push(stream, _device_path, st_mode, mtime, progress_callback, adb_info, filesync_info)
  File "/home/lan/.local/lib/python3.10/site-packages/adb_shell/adb_device.py", line 1055, in _push
    self._filesync_send(constants.DATA, adb_info, filesync_info, data=data)
  File "/home/lan/.local/lib/python3.10/site-packages/adb_shell/adb_device.py", line 1467, in _filesync_send
    self._filesync_flush(adb_info, filesync_info)
  File "/home/lan/.local/lib/python3.10/site-packages/adb_shell/adb_device.py", line 1314, in _filesync_flush
    self._read_until([constants.OKAY], adb_info)
  File "/home/lan/.local/lib/python3.10/site-packages/adb_shell/adb_device.py", line 1213, in _read_until
    cmd, _, _, data = self._io_manager.read(expected_cmds, adb_info, allow_zeros=True)
  File "/home/lan/.local/lib/python3.10/site-packages/adb_shell/adb_device.py", line 339, in read
    cmd, arg0, arg1, data = self._read_packet_from_device(adb_info)
  File "/home/lan/.local/lib/python3.10/site-packages/adb_shell/adb_device.py", line 486, in _read_packet_from_device
    msg = self._read_bytes_from_device(constants.MESSAGE_SIZE, adb_info)
  File "/home/lan/.local/lib/python3.10/site-packages/adb_shell/adb_device.py", line 442, in _read_bytes_from_device
    temp = self._transport.bulk_read(length, adb_info.transport_timeout_s)
  File "/home/lan/.local/lib/python3.10/site-packages/adb_shell/transport/tcp_transport.py", line 120, in bulk_read
    raise TcpTimeoutException(msg)
adb_shell.exceptions.TcpTimeoutException: Reading from 192.168.1.62:5555 timed out (10.0 seconds)

Adjusting the read_timeout_s or transport_timeout_s doesn't help.

pulling a non-existing file causes an error, which is not handled well.

Description

After trying to pull a file that doesn't exist, the next command SOMETIMES also fails, because it can't read the packets.
I found out there is a packet which tell the reason of the FAIL, but it's not always there when it reads it.

Log

Test code I run:

adb_device = AdbDeviceTcp(IP, PORT, 20)
adb_device.connect(rsa_keys=[signer], auth_timeout_s=30.0)
try:
    adb_device.pull("/data/local/tmp/23124124/", "asd")
except Exception as e:
    print(e)
    traceback.print_exc()
adb_device.push(r"to_upload.tar.gz", "/data/local/tmp/to_upload.tar.gz",
                progress_callback=push_progress_callback, transport_timeout_s=30, read_timeout_s=30)
Command failed: 
Traceback (most recent call last):
    adb_device.pull("/data/local/tmp/23124124/", "asd")
  File "C:\work\adb_shell\adb_shell\adb_device.py", line 548, in pull
    self._pull(device_path, stream, progress_callback, adb_info, filesync_info)
  File "C:\work\adb_shell\adb_shell\adb_device.py", line 575, in _pull
    for cmd_id, _, data in self._filesync_read_until([constants.DATA], [constants.DONE], adb_info, filesync_info):
  File "C:\work\adb_shell\adb_shell\adb_device.py", line 1159, in _filesync_read_until
    cmd_id, header, data = self._filesync_read(expected_ids + finish_ids, adb_info, filesync_info)
  File "C:\work\adb_shell\adb_shell\adb_device.py", line 1094, in _filesync_read
    raise exceptions.AdbCommandFailureException('Command failed: {}'.format(reason))
adb_shell.exceptions.AdbCommandFailureException: Command failed: 
Traceback (most recent call last):
    progress_callback=push_progress_callback, transport_timeout_s=30, read_timeout_s=30)
  File "C:\work\adb_shell\adb_shell\adb_device.py", line 619, in push
    self._open(b'sync:', adb_info)
  File "C:\work\adb_shell\adb_shell\adb_device.py", line 778, in _open
    _, adb_info.remote_id, their_local_id, _ = self._read([constants.OKAY], adb_info)
  File "C:\work\adb_shell\adb_shell\adb_device.py", line 829, in _read
    raise exceptions.InvalidCommandError("Unknown command: %d = '%s' (arg0 = %d, arg1 = %d, msg = '%s')" % (cmd, int_to_cmd(cmd), arg0, arg1, msg))
adb_shell.exceptions.InvalidCommandError: Unknown command: 1852141679 = 'b'open'' (arg0 = 1767990816, arg1 = 979658092, msg = 'b'open failed: No such fil'')

Process finished with exit code 1

Home Assistant Android TV error

From https://community.home-assistant.io/t/native-support-for-android-tv-android-devices/82792/356

2019-12-04 12:02:42 DEBUG (SyncWorker_7) [custom_components.androidtv.androidtv.adb_manager] Sending command to 192.168.1.38:5555 via adb-shell: (dumpsys power | grep 'Display Power' | grep -q 'state=ON' || dumpsys power | grep -q 'mScreenOn=true') && echo -e '1\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\c' && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo)
2019-12-04 12:02:42 DEBUG (SyncWorker_7) [custom_components.androidtv.androidtv.adb_shell.adb_device] bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\r\x02\x00\x00>\xa8\x00\x00\xb0\xaf\xba\xb1'
2019-12-04 12:02:42 DEBUG (SyncWorker_7) [custom_components.androidtv.androidtv.adb_shell.adb_device] bulk_write: b"shell:(dumpsys power | grep 'Display Power' | grep -q 'state=ON' || dumpsys power | grep -q 'mScreenOn=true') && echo -e '1\\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\\c' && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo)\x00"
2019-12-04 12:02:42 DEBUG (SyncWorker_7) [custom_components.androidtv.androidtv.adb_shell.adb_device] bulk_read(24): b'OKAYp\t\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-12-04 12:02:42 DEBUG (SyncWorker_7) [custom_components.androidtv.androidtv.adb_shell.adb_device] bulk_read(24): b'CLSEp\t\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-12-04 12:02:42 DEBUG (SyncWorker_7) [custom_components.androidtv.androidtv.adb_shell.adb_device] bulk_write: b'CLSE\x01\x00\x00\x00p\t\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-12-04 12:02:42 DEBUG (SyncWorker_7) [custom_components.androidtv.androidtv.adb_shell.adb_device] bulk_write: b''
2019-12-04 12:02:42 DEBUG (SyncWorker_7) [custom_components.androidtv.androidtv.firetv] Fire TV 192.168.1.38:5555 `get_properties` response: 
2019-12-04 12:02:53 DEBUG (SyncWorker_2) [custom_components.androidtv.androidtv.adb_manager] Sending command to 192.168.1.38:5555 via adb-shell: (dumpsys power | grep 'Display Power' | grep -q 'state=ON' || dumpsys power | grep -q 'mScreenOn=true') && echo -e '1\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\c' && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo)
2019-12-04 12:02:53 DEBUG (SyncWorker_2) [custom_components.androidtv.androidtv.adb_shell.adb_device] bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\r\x02\x00\x00>\xa8\x00\x00\xb0\xaf\xba\xb1'
2019-12-04 12:02:53 DEBUG (SyncWorker_2) [custom_components.androidtv.androidtv.adb_shell.adb_device] bulk_write: b"shell:(dumpsys power | grep 'Display Power' | grep -q 'state=ON' || dumpsys power | grep -q 'mScreenOn=true') && echo -e '1\\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\\c' && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo)\x00"
2019-12-04 12:02:53 DEBUG (SyncWorker_2) [custom_components.androidtv.androidtv.adb_shell.adb_device] bulk_read(24): b'OKAYq\t\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-12-04 12:02:53 DEBUG (SyncWorker_2) [custom_components.androidtv.androidtv.adb_shell.adb_device] bulk_read(24): b'CLSEq\t\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-12-04 12:02:53 DEBUG (SyncWorker_2) [custom_components.androidtv.androidtv.adb_shell.adb_device] bulk_write: b'CLSE\x01\x00\x00\x00q\t\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-12-04 12:02:53 DEBUG (SyncWorker_2) [custom_components.androidtv.androidtv.adb_shell.adb_device] bulk_write: b''
2019-12-04 12:02:53 DEBUG (SyncWorker_2) [custom_components.androidtv.androidtv.firetv] Fire TV 192.168.1.38:5555 `get_properties` response: 
2019-12-04 12:03:04 DEBUG (SyncWorker_0) [custom_components.androidtv.androidtv.adb_manager] Sending command to 192.168.1.38:5555 via adb-shell: (dumpsys power | grep 'Display Power' | grep -q 'state=ON' || dumpsys power | grep -q 'mScreenOn=true') && echo -e '1\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\c' && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo)
2019-12-04 12:03:04 DEBUG (SyncWorker_0) [custom_components.androidtv.androidtv.adb_shell.adb_device] bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\r\x02\x00\x00>\xa8\x00\x00\xb0\xaf\xba\xb1'
2019-12-04 12:03:04 DEBUG (SyncWorker_0) [custom_components.androidtv.androidtv.adb_shell.adb_device] bulk_write: b"shell:(dumpsys power | grep 'Display Power' | grep -q 'state=ON' || dumpsys power | grep -q 'mScreenOn=true') && echo -e '1\\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\\c' && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo)\x00"
2019-12-04 12:03:12 DEBUG (SyncWorker_0) [custom_components.androidtv.androidtv.adb_shell.adb_device] bulk_read(24): b''
2019-12-04 12:03:12 ERROR (SyncWorker_0) [custom_components.androidtv.media_player] Failed to execute an ADB command. ADB connection re-establishing attempt in the next update. Error: ('Unable to unpack ADB command. (length=0)', b'<6I', b'', error('unpack requires a buffer of 24 bytes'))
2019-12-04 12:03:15 DEBUG (SyncWorker_8) [custom_components.androidtv.androidtv.adb_shell.adb_device] bulk_write: b"CNXN\x00\x00\x00\x01\x00\x10\x00\x00\x0e\x00\x00\x00'\x05\x00\x00\xbc\xb1\xa7\xb1"
2019-12-04 12:03:15 DEBUG (SyncWorker_8) [custom_components.androidtv.androidtv.adb_shell.adb_device] bulk_write: b'host::hassnuc\x00'
2019-12-04 12:03:24 WARNING (SyncWorker_8) [custom_components.androidtv.androidtv.adb_manager] Couldn't connect to host 192.168.1.38:5555.  TcpTimeoutException: Reading from 192.168.1.38:5555 timed out (9.0 seconds)
2019-12-04 12:03:37 DEBUG (SyncWorker_0) [custom_components.androidtv.androidtv.adb_shell.adb_device] bulk_write: b"CNXN\x00\x00\x00\x01\x00\x10\x00\x00\x0e\x00\x00\x00'\x05\x00\x00\xbc\xb1\xa7\xb1"
2019-12-04 12:03:37 DEBUG (SyncWorker_0) [custom_components.androidtv.androidtv.adb_shell.adb_device] bulk_write: b'host::hassnuc\x00'
2019-12-04 12:03:37 ERROR (MainThread) [homeassistant.helpers.entity] Update for media_player.fire_tv fails
Traceback (most recent call last):
  File "/home/homeassistant/.homeassistant/custom_components/androidtv/androidtv/adb_manager.py", line 104, in connect
    self._adb.connect(rsa_keys=[signer], auth_timeout_s=auth_timeout_s)
  File "/home/homeassistant/.homeassistant/custom_components/androidtv/androidtv/adb_shell/adb_device.py", line 317, in connect
    cmd, arg0, arg1, banner = self._read([constants.AUTH, constants.CNXN], adb_info)
  File "/home/homeassistant/.homeassistant/custom_components/androidtv/androidtv/adb_shell/adb_device.py", line 739, in _read
    msg = self._handle.bulk_read(constants.MESSAGE_SIZE, adb_info.timeout_s)
  File "/home/homeassistant/.homeassistant/custom_components/androidtv/androidtv/adb_shell/tcp_handle.py", line 127, in bulk_read
    return self._connection.recv(numbytes)
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity.py", line 270, in async_update_ha_state
    await self.async_device_update()
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity.py", line 450, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/androidtv/media_player.py", line 271, in _adb_exception_catcher
    return func(self, *args, **kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/androidtv/media_player.py", line 536, in update
    self._available = self.aftv.adb_connect(always_log_errors=False)
  File "/home/homeassistant/.homeassistant/custom_components/androidtv/androidtv/basetv.py", line 172, in adb_connect
    return self._adb.connect(always_log_errors, auth_timeout_s)
  File "/home/homeassistant/.homeassistant/custom_components/androidtv/androidtv/adb_manager.py", line 122, in connect
    self.close()
  File "/home/homeassistant/.homeassistant/custom_components/androidtv/androidtv/adb_manager.py", line 66, in close
    self._adb.close()
  File "/home/homeassistant/.homeassistant/custom_components/androidtv/androidtv/adb_shell/adb_device.py", line 261, in close
    self._handle.close()
  File "/home/homeassistant/.homeassistant/custom_components/androidtv/androidtv/adb_shell/tcp_handle.py", line 83, in close
    self._connection.shutdown(socket.SHUT_RDWR)
OSError: [Errno 107] Transport endpoint is not connected
2019-12-04 12:03:48 ERROR (MainThread) [homeassistant.helpers.entity] Update for media_player.fire_tv fails
Traceback (most recent call last):
  File "/home/homeassistant/.homeassistant/custom_components/androidtv/androidtv/adb_manager.py", line 104, in connect
    self._adb.connect(rsa_keys=[signer], auth_timeout_s=auth_timeout_s)
  File "/home/homeassistant/.homeassistant/custom_components/androidtv/androidtv/adb_shell/adb_device.py", line 308, in connect
    self._handle.close()
  File "/home/homeassistant/.homeassistant/custom_components/androidtv/androidtv/adb_shell/tcp_handle.py", line 83, in close
    self._connection.shutdown(socket.SHUT_RDWR)
OSError: [Errno 107] Transport endpoint is not connected

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity.py", line 270, in async_update_ha_state
    await self.async_device_update()
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity.py", line 450, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/androidtv/media_player.py", line 271, in _adb_exception_catcher
    return func(self, *args, **kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/androidtv/media_player.py", line 536, in update
    self._available = self.aftv.adb_connect(always_log_errors=False)
  File "/home/homeassistant/.homeassistant/custom_components/androidtv/androidtv/basetv.py", line 172, in adb_connect
    return self._adb.connect(always_log_errors, auth_timeout_s)
  File "/home/homeassistant/.homeassistant/custom_components/androidtv/androidtv/adb_manager.py", line 122, in connect
    self.close()
  File "/home/homeassistant/.homeassistant/custom_components/androidtv/androidtv/adb_manager.py", line 66, in close
    self._adb.close()
  File "/home/homeassistant/.homeassistant/custom_components/androidtv/androidtv/adb_shell/adb_device.py", line 261, in close
    self._handle.close()
  File "/home/homeassistant/.homeassistant/custom_components/androidtv/androidtv/adb_shell/tcp_handle.py", line 83, in close
    self._connection.shutdown(socket.SHUT_RDWR)
OSError: [Errno 107] Transport endpoint is not connected

Some Features Implementation

Hello adb_shell developers,

  • 1. Interactive shell.

I would like to ask about adding interactive shell to adb_shell project. I think it will be good for people who does not want to send commands manually through device.shell().

device.interact()

result:

android@localhost # pwd
/sdcard
android@localhost #
  • 2. Ability to install/uninstall .apk files on devices.
device.install('/path/to/apk')
# device.uninstall('bundle identifier')
  • 3. Reboot device.
device.reboot()

Regards,
Ivan Nikolsky (@enty8080)

P.S. I am using your python package and it is very good :), so it will be good to see this features.

Handle object should be abstracted

Currently there is no way to pass an initialized or custom handle object to an AdbDevice. With python-adb, this could be done by calling ConnectDevice with handle set. This is useful for support custom handle implementations (in my case, I need to talk to a websocket via Twisted).

Happy to provide a patch. At this point I'm just investigating whether this library solves issues I'm having with python-adb.

[LOGS NEEDED!] Fix support for newer devices

Currently, this package won't work well for newer devices. In order to figure out what the problem is and fix it, I need logs. Here is how to collect them, depending on how you're using this package.

1. Standalone package

Set the log level to debug via

import logging

logging.getLogger("adb_shell").setLevel(logging.DEBUG)

2. Home Assistant

Custom Component

If you are using this androidtv custom component (HACS compatible), follow the Python ADB implementation instructions and enable debug logging via the logger.set_level service with the parameters:

JSON (HA version < 0.100)

{"custom_components.androidtv.androidtv.adb_shell": "debug"}

YAML (HA version 0.100 and above)

custom_components.androidtv.androidtv.adb_shell: debug

Built-in Android TV integration (HA 0.100 and above)

This is similar to the instructions above, except that you'll use the built-in Android TV integration and the logging.set_level service parameters are:

adb_shell: debug

Test failures with Python 3.10

Description

With Python 3.10 approx. 70 tests fails.

Log

ecuting pytestCheckPhase
============================= test session starts ==============================
platform linux -- Python 3.10.1, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /build/source
collected 176 items                                                            

tests/test_adb_device.py ............................................... [ 26%]
.............                                                            [ 34%]
tests/test_adb_device_async.py FFFFFFFFFFFFFFFFFFF.FFFFFFFFFFFFFFFFFFFFF [ 57%]
FFFFFFFFFFFFFFFFFFF                                                      [ 68%]
tests/test_adb_message.py .....                                          [ 71%]
tests/test_exceptions.py ................                                [ 80%]
tests/test_hidden_helpers.py .........                                   [ 85%]
tests/test_keygen.py .                                                   [ 85%]
tests/test_sign_cryptography.py ..                                       [ 86%]
tests/test_sign_pycryptodome.py ..                                       [ 88%]
tests/test_sign_pythonrsa.py ....                                        [ 90%]
tests/test_tcp_transport.py ....                                         [ 92%]
tests/test_tcp_transport_async.py FFFFFFFF                               [ 97%]
tests/test_usb_importerror.py ..                                         [ 98%]
tests/test_usb_transport.py ...                                          [100%]

=================================== FAILURES ===================================
_________________ TestAdbDeviceAsync.test_adb_connection_error _________________

args = (<tests.test_adb_device_async.TestAdbDeviceAsync testMethod=test_adb_connection_error>,)
kwargs = {}

    def sync_func(*args, **kwargs):
>       return _await(func(*args, **kwargs))

tests/async_wrapper.py:18: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

coro = <coroutine object TestAdbDeviceAsync.test_adb_connection_error at 0x7ffff4d06260>

    def _await(coro):
        with warnings.catch_warnings(record=True) as warns:
            ret = asyncio.get_event_loop().run_until_complete(coro)
    
            if warns:
>               raise RuntimeError
E               RuntimeError

tests/async_wrapper.py:11: RuntimeError
______________________ TestAdbDeviceAsync.test_available _______________________

args = (<tests.test_adb_device_async.TestAdbDeviceAsync testMethod=test_available>,)
kwargs = {}

    def sync_func(*args, **kwargs):
>       return _await(func(*args, **kwargs))

tests/async_wrapper.py:18: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

coro = <coroutine object TestAdbDeviceAsync.test_available at 0x7ffff4d068f0>

    def _await(coro):
        with warnings.catch_warnings(record=True) as warns:
            ret = asyncio.get_event_loop().run_until_complete(coro)
    
            if warns:
>               raise RuntimeError
E               RuntimeError

tests/async_wrapper.py:11: RuntimeError
________________________ TestAdbDeviceAsync.test_close _________________________

args = (<tests.test_adb_device_async.TestAdbDeviceAsync testMethod=test_close>,)
kwargs = {}

    def sync_func(*args, **kwargs):
>       return _await(func(*args, **kwargs))

tests/async_wrapper.py:18: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

coro = <coroutine object TestAdbDeviceAsync.test_close at 0x7ffff4d06dc0>

    def _await(coro):
        with warnings.catch_warnings(record=True) as warns:
            ret = asyncio.get_event_loop().run_until_complete(coro)
    
            if warns:
>               raise RuntimeError
E               RuntimeError

tests/async_wrapper.py:11: RuntimeError
_______________________ TestAdbDeviceAsync.test_connect ________________________

args = (<tests.test_adb_device_async.TestAdbDeviceAsync testMethod=test_connect>,)
kwargs = {}

    def sync_func(*args, **kwargs):
>       return _await(func(*args, **kwargs))

tests/async_wrapper.py:18: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

coro = <coroutine object TestAdbDeviceAsync.test_connect at 0x7ffff4d07290>

    def _await(coro):
        with warnings.catch_warnings(record=True) as warns:
            ret = asyncio.get_event_loop().run_until_complete(coro)
    
            if warns:
>               raise RuntimeError
E               RuntimeError

tests/async_wrapper.py:11: RuntimeError
----------------------------- Captured stdout call -----------------------------
bulk_write(24): b'CNXN\x00\x00\x00\x01\x00\x00\x10\x00\x10\x00\x00\x00\xfb\x05\x00\x00\xbc\xb1\xa7\xb1'
bulk_write(16): b'host::localhost\x00'
bulk_read(24): b'CNXN\x01\x00\x00\x00\x00\x10\x00\x00\x0e\x00\x00\x00B\x05\x00\x00\xbc\xb1\xa7\xb1'
bulk_read(14): b'host::unknown\x00'
------------------------------ Captured log call -------------------------------
DEBUG    adb_shell.adb_device_async:adb_device_async.py:484 bulk_write(24): b'CNXN\x00\x00\x00\x01\x00\x00\x10\x00\x10\x00\x00\x00\xfb\x05\x00\x00\xbc\xb1\xa7\xb1'
DEBUG    adb_shell.adb_device_async:adb_device_async.py:488 bulk_write(16): b'host::localhost\x00'
DEBUG    adb_shell.adb_device_async:adb_device_async.py:410 bulk_read(24): b'CNXN\x01\x00\x00\x00\x00\x10\x00\x00\x0e\x00\x00\x00B\x05\x00\x00\xbc\xb1\xa7\xb1'
DEBUG    adb_shell.adb_device_async:adb_device_async.py:410 bulk_read(14): b'host::unknown\x00'
___________________ TestAdbDeviceAsync.test_connect_no_keys ____________________
[...]
coro = <coroutine object TestTcpTransportAsync.test_connect_with_timeout at 0x7ffff4415460>

    def _await(coro):
        with warnings.catch_warnings(record=True) as warns:
            ret = asyncio.get_event_loop().run_until_complete(coro)
    
            if warns:
>               raise RuntimeError
E               RuntimeError

tests/async_wrapper.py:11: RuntimeError
=========================== short test summary info ============================
FAILED tests/test_adb_device_async.py::TestAdbDeviceAsync::test_adb_connection_error
FAILED tests/test_adb_device_async.py::TestAdbDeviceAsync::test_available - R...
FAILED tests/test_adb_device_async.py::TestAdbDeviceAsync::test_close - Runti...
FAILED tests/test_adb_device_async.py::TestAdbDeviceAsync::test_connect - Run...
FAILED tests/test_adb_device_async.py::TestAdbDeviceAsync::test_connect_no_keys
FAILED tests/test_adb_device_async.py::TestAdbDeviceAsync::test_connect_timeout
[...]
FAILED tests/test_tcp_transport_async.py::TestTcpTransportAsync::test_connect
FAILED tests/test_tcp_transport_async.py::TestTcpTransportAsync::test_connect_close
FAILED tests/test_tcp_transport_async.py::TestTcpTransportAsync::test_connect_close_catch_oserror
FAILED tests/test_tcp_transport_async.py::TestTcpTransportAsync::test_connect_with_timeout
======================== 67 failed, 109 passed in 6.74s ========================
```

At first glance I would say that this is related to the removal of [`loop`](https://docs.python.org/3/whatsnew/3.10.html) in Python 3.10.

AdbDeviceTcp.shell() ignores timeouts specfied in AdbDeviceTcp constructor

Description

Hi Jeff,

Great tool, thanks a ton for making it available!

I'm having trouble specifying custom timeouts. It seems that a call to AdbDeviceTcp.shell() uses/propagates the timeout values provided as arguments to AdbDeviceTcp.shell() even when these parameters are omitted. This results in timeout values provided to the AdbDeviceTcp constructor being overwritten. I'm not sure if this is intentional (I assume not), or if I am using the API wrong.

For example:

# Read ADB keys
pubkey_path = pathlib.Path(pubkey_path).expanduser()
privkey_path = pathlib.Path(privkey_path).expanduser()
with open(pubkey_path) as f:
    pubkey = f.read()
with open(privkey_path) as f:
    privkey = f.read()
adbkeypair = PythonRSASigner(pubkey, privkey)

# Connect to Fire TV, specifying custom timeout values
ftv = AdbDeviceTcp(firetv_ip, firetv_port, default_transport_timeout_s=60.0)
ftv.connect(rsa_keys=[adbkeypair], transport_timeout_s=60.0, auth_timeout_s=60.0, read_timeout_s=60.0)

# Perform a (long) sequence of ADB commands (calls to AdbDeviceTcp.shell()), e.g. let's uninstall all 3rd party apps (assuming you have A LOT installed):
pkgs_str = ftv.shell('pm list packages -3')
pkgs = [p.replace('package:', '', 1) for p in pkgs_str.split('\r\n') if p.startswith('package:')]
for pkgname in pkgs:
    print(f'Uninstalling {pkgname} ...')
    ftv.shell(f'pm uninstall {pkgname}')

Using code similar to the example above (multiple calls to AdbDeviceTcp.shell(), although not just uninstall commands), I occasionally get TcpTimeoutExceptions with a message indicating that the (read) timeout was 10 seconds (the default value) rather than the expected 60 seconds (the value I provided in the AdbDeviceTcp constructor and in AdbDeviceTcp.connect(), although the latter may be unrelated as that's a transport timeout):

adb_shell.exceptions.TcpTimeoutException: Reading from <device_ip>:<device_port> timed out (10.0 seconds)

Platform details (in case it matters)

I'm using adb_shell to control a Fire TV Stick with Alexa Voice Remote (i.e., Fire TV Stick 2nd generation that was reissued early 2019), that runs Fire OS 5 which is based on Android 5.1 (I'm on Fire OS 5.2.7.7 to be exact). This device is rather resource constrained and is in some instances rather slow at responding to ADB commands (including when using the ADB binary directly, not involving adb_shell), thus the default timeout is simply too strict for this particular device.

I'm using the latest adb_shell release:

$ pip show adb_shell
Name: adb-shell
Version: 0.2.3
Summary: A Python implementation of ADB with shell and FileSync functionality.
Home-page: https://github.com/JeffLIrion/adb_shell
Author: Jeff Irion
Author-email: [email protected]
License: UNKNOWN
Location: /home/username/python_venvs/some_venv/lib/python3.7/site-packages
Requires: rsa, pyasn1, cryptography
Required-by: 

Full stack trace

An example of the full stack trace (I replaced local paths and IP addresses with placeholders):

Traceback (most recent call last):
  File "main.py", line 93, in <module>
    firetv_port=args.firetv_port)
  File "main.py", line 56, in main
    ftv_controller.uninstall_app(p)
  File "/home/username/src/firetv_controller.py", line 214, in uninstall_app
    return self.firetv.shell(f'pm uninstall {pkgname}')
  File "/home/username/python_venvs/some_venv/lib/python3.7/site-packages/adb_shell/adb_device.py", line 397, in shell
    return self._service(b'shell', command.encode('utf8'), transport_timeout_s, read_timeout_s, timeout_s, decode)
  File "/home/username/python_venvs/some_venv/lib/python3.7/site-packages/adb_shell/adb_device.py", line 302, in _service
    return b''.join(self._streaming_command(service, command, adb_info)).decode('utf8')
  File "/home/username/python_venvs/some_venv/lib/python3.7/site-packages/adb_shell/adb_device.py", line 940, in _streaming_command
    for data in self._read_until_close(adb_info):
  File "/home/username/python_venvs/some_venv/lib/python3.7/site-packages/adb_shell/adb_device.py", line 876, in _read_until_close
    cmd, data = self._read_until([constants.CLSE, constants.WRTE], adb_info)
  File "/home/username/python_venvs/some_venv/lib/python3.7/site-packages/adb_shell/adb_device.py", line 832, in _read_until
    cmd, remote_id2, local_id2, data = self._read(expected_cmds, adb_info)
  File "/home/username/python_venvs/some_venv/lib/python3.7/site-packages/adb_shell/adb_device.py", line 765, in _read
    msg = self._transport.bulk_read(constants.MESSAGE_SIZE, adb_info.transport_timeout_s)
  File "/home/username/python_venvs/some_venv/lib/python3.7/site-packages/adb_shell/transport/tcp_transport.py", line 127, in bulk_read
    raise TcpTimeoutException(msg)
adb_shell.exceptions.TcpTimeoutException: Reading from <FIRE_TV_IP>:<FIRE_TV_PORT> timed out (10.0 seconds)

Workaround

I've found a hacky workaround that seems to solve the issue for me for now. I manually modified /home/username/python_venvs/some_venv/lib/python3.7/site-packages/adb_shell/adb_device.py, adding the highlighted block of code to AdbDevice.shell():

class AdbDevice(object):
    # ...
    def shell(self, command, transport_timeout_s=None, read_timeout_s=constants.DEFAULT_READ_TIMEOUT_S, timeout_s=None, decode=True):
        if not self.available:
            raise exceptions.AdbConnectionError("ADB command not sent because a connection to the device has not been established.  (Did you call `AdbDevice.connect()`?)")
         # --- NEW CODE ---
        if self._transport is not None and isinstance(self._transport, TcpTransport):
            if transport_timeout_s is None:
                # Use timeout specified in encapsulated TcpTransport if no overwriting transport timeout specified here.
                transport_timeout_s = self._transport._default_transport_timeout_s
            if read_timeout_s == constants.DEFAULT_READ_TIMEOUT_S and self._transport._default_transport_timeout_s is not None:
                # Use timeout specified in encapsulated TcpTransport if no overwriting transport timeout specified here.
                # Note: does not handle the case where the caller explicitly sets read_timeout_s to constants.DEFAULT_READ_TIMEOUT_S
                read_timeout_s = self._transport._default_transport_timeout_s
        # ----------------
        return self._service(b'shell', command.encode('utf8'), transport_timeout_s, read_timeout_s, timeout_s, decode)

This is probably not the right place for this change - I went with the most straightforward solution that seemed to fit my needs. I'm guessing it should probably go in the AdbDeviceTcp subclass s.t. you don't have to do type checks, but I don't understand the codebase well enough to be the judge of that. Also note that the hack seems to fail if the user modifies adb_shell.constants.DEFAULT_READ_TIMEOUT_S, e.g., something like this:

# Attempt to increase the read timeout globally
adb_shell.constants.DEFAULT_READ_TIMEOUT_S = 60.0
# Connect to Fire TV, specifying custom timeout values
ftv = AdbDeviceTcp(firetv_ip, firetv_port, default_transport_timeout_s=60.0)
ftv.connect(rsa_keys=[adbkeypair], transport_timeout_s=60.0, auth_timeout_s=60.0, read_timeout_s=60.0)
pkgname = 'com.my.app'
ftv.shell(f'pm uninstall {pkgname}')

If I recall correctly, AdbDeviceTcp.shell() still gets called with read_timeout_s=10 for this scenario, which makes the if read_timeout_s == constants.DEFAULT_READ_TIMEOUT_S and ... check in the hack above false as constants.DEFAULT_READ_TIMEOUT_S == 60.0.

Once again thanks for providing a great, well-documented tool.

Best,
Janus

State of media_player very often changes from "turned off" to "unavailable"

HA: 0.100.1
adb-shell: 0.0.4
Device: Xiaomi Mi Box TV 4K
Configuration:

- platform: androidtv
 host: !secret mibox_hostname
 adbkey: "~/.android/adbkey"
 name: "MiBox"

After turning off device (via remote) its media_player entity very often changes states from "turned off" to "unavailable". Wi-Fi connection is still active when device is off.

Debug log:

2019-10-12 10:48:27 WARNING (SyncWorker_1) [androidtv.adb_manager] Couldn't connect to host mibox.bieniu.lan:5555, error: Timed out trying to connect to ADB device.
2019-10-12 10:49:57 DEBUG (SyncWorker_4) [adb_shell.adb_device] bulk_write: b'CNXN\x00\x00\x00\x01\x00\x10\x00\x00\x10\x00\x00\x00\x0c\x06\x00\x00\xbc\xb1\xa7\xb1'
2019-10-12 10:49:57 DEBUG (SyncWorker_4) [adb_shell.adb_device] bulk_write: b'host::raspberry\x00'
2019-10-12 10:49:57 DEBUG (SyncWorker_4) [adb_shell.adb_device] bulk_read(24): b'AUTH\x01\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\xb3\n\x00\x00\xbe\xaa\xab\xb7'
2019-10-12 10:49:57 DEBUG (SyncWorker_4) [adb_shell.adb_device] bulk_read(20): b'\x88Lo\x8a\x13\xa7\xbb\xbd\xb4<2\xce\xfdy\xad\xd8}J\xc8:'
2019-10-12 10:49:57 DEBUG (SyncWorker_4) [adb_shell.adb_device] bulk_write: b'AUTH\x02\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\xed}\x00\x00\xbe\xaa\xab\xb7'
2019-10-12 10:49:57 DEBUG (SyncWorker_4) [adb_shell.adb_device] bulk_write: b'\x80H\x1d\xd18\x9c\x1c\xe4\n\xbb\xdf|N\x86f*\x8d4\xed\xca\x86b~\xf1l\x1f\xdc{H\xea\x94\xa5\xa4MUe\xeb\x9d\x90\r\xde\xee\xd5\x14\xd2AM\x0b\xf8-"\xbb\xb7\xca\x85\xf1J"\x83\xd09\x8b-$\xd1\x0b\xc9f9\xdc\xcf\xbeB4\\\x00\xb9q\xeb<H\xf6\xf3\x16\xfd\xf9MQ8\xab2\xa7qs\xbd\xa7h\xad\x14\xd1\x9c\x1bh~\xe6\x1e//\xda/\xe2\xdf\x88+\x9cp\x16\x1a\x15>\xff0\x170\xec\xb8\x92AT\x8b\xe2\x02\x05\x15\xcc\xbe\xfbE-u\x08\xbbC\'\xc0\x8d\xd5/\xd3\xdfF\xb4\xfe\\%c\xe1a3\xb3\xb6\x16z\xca8\xa8\xac\xea>\xa04\xd6w\xab\xb1Z\xfex\xec\xe3\xba\'\xaf\xe3\xb7y\xe1\x02\\K\x1c\xa0\x1b\x8c;\x90xA\xdd]AX\x9c\x92\xb8~\x1a\x03\x90c \x9a\xfc\xf7Z\x7fOF\x8dW\xa6]K\xd4a\xab\xc5\x16\x03\x7f&\xd97r\xbc\x14K\xb9G%\xee\xdaRz\x11\x0cql\xa2\xb0\xd4\xbc\xe6\xbdA\xe7'
2019-10-12 10:49:58 DEBUG (SyncWorker_4) [adb_shell.adb_device] bulk_read(24): b"CNXN\x00\x00\x00\x01\x00\x10\x00\x00i\x00\x00\x00.'\x00\x00\xbc\xb1\xa7\xb1"
2019-10-12 10:49:58 DEBUG (SyncWorker_4) [adb_shell.adb_device] bulk_read(105): b'device::ro.product.name=once;ro.product.model=MIBOX3;ro.product.device=once;features=stat_v2,cmd,shell_v2'
2019-10-12 10:50:08 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\xb4\x02\x00\x00\x11\xdb\x00\x00\xb0\xaf\xba\xb1'
2019-10-12 10:50:08 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b"shell:dumpsys power | grep 'Display Power' | grep -q 'state=ON' && echo -e '1\\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\\c' && (dumpsys audio | grep paused | grep -qv 'Buffer Queue' && echo -e '1\\c' || (dumpsys audio | grep started | grep -qv 'Buffer Queue' && echo '2\\c' || echo '0\\c')) && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo) && dumpsys audio | grep '\\- STREAM_MUSIC:' -A 12\x00"
2019-10-12 10:50:08 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_read(24): b'OKAY\x97\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:50:08 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_read(24): b'CLSE\x97\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:50:08 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b'CLSE\x01\x00\x00\x00\x97\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:50:08 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:50:19 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\xb4\x02\x00\x00\x11\xdb\x00\x00\xb0\xaf\xba\xb1'
2019-10-12 10:50:19 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b"shell:dumpsys power | grep 'Display Power' | grep -q 'state=ON' && echo -e '1\\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\\c' && (dumpsys audio | grep paused | grep -qv 'Buffer Queue' && echo -e '1\\c' || (dumpsys audio | grep started | grep -qv 'Buffer Queue' && echo '2\\c' || echo '0\\c')) && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo) && dumpsys audio | grep '\\- STREAM_MUSIC:' -A 12\x00"
2019-10-12 10:50:28 ERROR (SyncWorker_12) [homeassistant.components.androidtv.media_player] Failed to execute an ADB command. ADB connection re-establishing attempt in the next update. Error: Reading from mibox.bieniu.lan:5555 timed out (9.0 seconds)
2019-10-12 10:50:38 WARNING (SyncWorker_13) [androidtv.adb_manager] Couldn't connect to host mibox.bieniu.lan:5555, error: Timed out trying to connect to ADB device.
2019-10-12 10:51:21 DEBUG (SyncWorker_1) [adb_shell.adb_device] bulk_write: b'CNXN\x00\x00\x00\x01\x00\x10\x00\x00\x10\x00\x00\x00\x0c\x06\x00\x00\xbc\xb1\xa7\xb1'
2019-10-12 10:51:21 DEBUG (SyncWorker_1) [adb_shell.adb_device] bulk_write: b'host::raspberry\x00'
2019-10-12 10:51:21 DEBUG (SyncWorker_1) [adb_shell.adb_device] bulk_read(24): b'AUTH\x01\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\xc5\n\x00\x00\xbe\xaa\xab\xb7'
2019-10-12 10:51:21 DEBUG (SyncWorker_1) [adb_shell.adb_device] bulk_read(20): b"\x17\xbf\xbf\xff\xc7\xa2eo'Sh\xdf\x8e\xf5\xff\xe0\tJ6H"
2019-10-12 10:51:22 DEBUG (SyncWorker_1) [adb_shell.adb_device] bulk_write: b'AUTH\x02\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\xc9\x80\x00\x00\xbe\xaa\xab\xb7'
2019-10-12 10:51:22 DEBUG (SyncWorker_1) [adb_shell.adb_device] bulk_write: b'\xbe1\xf5\x80\xc5\xdbul\xce\xd0\xf5|:\x03~\x07d#\xdb\x8b.^\xc6\xba\xe0\x0b9p\xa7A\x04c\xe1\xb3\xd9\xffC\xbba\x96\x05w\xaf\x1a6\xfdN\x8f0\xb1\r\x84\xdc\xe0*e\xef\xcel\xeb%\xdcrI\xa8\xf4?\xec5\xa5l\x90&\xb6\xa3\\\xc9<C\xc7O^\xe8[~\xefD\x00\xdc+\x0frY\x98\xa9l\'\xb2\x08VJOz\xd3.\xb3\xfb\x1fx\x1a\xeb\xc2G)]\x019\xdd\xd2\xbcj\x8f\xad\xad\x9e=\x84\xf9D\xf0)\xe2\xfc+D*\x9a*\xbb\x10\xc4\x05;Y\xf3\x1b\xac\x94F\x8ek5a\xf5\xc8\xeb=a\xd0\xbaRn\x8bC3\xdd\xa7e\x7f\xf0h\xa6\x82\x90E\xe7\xc2\xa3\x1a\x0e\xbc\xd6~a\x9f\xba\xbeU\x8d\x03\xb9G}\x83"%s\x19\x85\xd1q|\xb3\x7f\xcf\xfbg*pg\x84s\xe4\xc3a\xc3\x05\xfe)$\xe7\xb7\x9a(\x9b\xae\x16\xcb\xbd\xa5>\xc4\xe0\xe6\xce\xda/\x0bcE \xd9:\xa8\x97d\x93\xea\xa8\x0ce\n5f\xf0\xed'
2019-10-12 10:51:22 DEBUG (SyncWorker_1) [adb_shell.adb_device] bulk_read(24): b"CNXN\x00\x00\x00\x01\x00\x10\x00\x00i\x00\x00\x00.'\x00\x00\xbc\xb1\xa7\xb1"
2019-10-12 10:51:22 DEBUG (SyncWorker_1) [adb_shell.adb_device] bulk_read(105): b'device::ro.product.name=once;ro.product.model=MIBOX3;ro.product.device=once;features=stat_v2,cmd,shell_v2'
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\xb4\x02\x00\x00\x11\xdb\x00\x00\xb0\xaf\xba\xb1'
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b"shell:dumpsys power | grep 'Display Power' | grep -q 'state=ON' && echo -e '1\\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\\c' && (dumpsys audio | grep paused | grep -qv 'Buffer Queue' && echo -e '1\\c' || (dumpsys audio | grep started | grep -qv 'Buffer Queue' && echo '2\\c' || echo '0\\c')) && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo) && dumpsys audio | grep '\\- STREAM_MUSIC:' -A 12\x00"
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_read(24): b'OKAY\x99\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_read(24): b'WRTE\x99\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x001\x00\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_read(1): b'1'
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x99\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_read(24): b'WRTE\x99\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x001\x00\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_read(1): b'1'
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x99\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_read(24): b'WRTE\x99\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x000\x00\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_read(1): b'0'
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x99\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_read(24): b'WRTE\x99\x00\x00\x00\x01\x00\x00\x00\x13\x00\x00\x000\x06\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_read(19): b'Wake Locks: size=0\n'
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x99\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_read(24): b'WRTE\x99\x00\x00\x00\x01\x00\x00\x00\x1e\x00\x00\x00V\x0b\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_read(30): b'com.google.android.youtube.tv\n'
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x99\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_read(24): b'WRTE\x99\x00\x00\x00\x01\x00\x00\x00\x98\x00\x00\x00\xa13\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_read(152): b'      state=PlaybackState {state=0, position=0, buffered position=0, speed=0.0, updated=0, actions=0, custom actions=[], active item id=-1, error=null}\n'
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x99\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_read(24): b'WRTE\x99\x00\x00\x00\x01\x00\x00\x00.\x01\x00\x00\xceP\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_read(302): b'- STREAM_MUSIC:\n   Muted: false\n   Min: 0\n   Max: 15\n   Current: 2 (speaker): 11, 4 (headset): 10, 8 (headphone): 10, 400 (hdmi): 6, 40000000 (default): 11\n   Devices: hdmi\n- STREAM_ALARM:\n   Muted: false\n   Min: 0\n   Max: 7\n   Current: 40000000 (default): 6\n   Devices: speaker\n- STREAM_NOTIFICATION:\n'
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x99\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_read(24): b'CLSE\x99\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b'CLSE\x01\x00\x00\x00\x99\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:51:24 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\xb4\x02\x00\x00\x11\xdb\x00\x00\xb0\xaf\xba\xb1'
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_write: b"shell:dumpsys power | grep 'Display Power' | grep -q 'state=ON' && echo -e '1\\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\\c' && (dumpsys audio | grep paused | grep -qv 'Buffer Queue' && echo -e '1\\c' || (dumpsys audio | grep started | grep -qv 'Buffer Queue' && echo '2\\c' || echo '0\\c')) && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo) && dumpsys audio | grep '\\- STREAM_MUSIC:' -A 12\x00"
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_read(24): b'CLSE\x99\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_read(24): b'OKAY\x9a\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9a\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x001\x00\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_read(1): b'1'
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9a\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x001\x00\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_read(1): b'1'
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9a\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x000\x00\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_read(1): b'0'
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9a\x00\x00\x00\x01\x00\x00\x00\x13\x00\x00\x000\x06\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_read(19): b'Wake Locks: size=0\n'
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9a\x00\x00\x00\x01\x00\x00\x00\x1e\x00\x00\x00V\x0b\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_read(30): b'com.google.android.youtube.tv\n'
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9a\x00\x00\x00\x01\x00\x00\x00\x98\x00\x00\x00\xa13\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_read(152): b'      state=PlaybackState {state=0, position=0, buffered position=0, speed=0.0, updated=0, actions=0, custom actions=[], active item id=-1, error=null}\n'
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9a\x00\x00\x00\x01\x00\x00\x00.\x01\x00\x00\xceP\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_read(302): b'- STREAM_MUSIC:\n   Muted: false\n   Min: 0\n   Max: 15\n   Current: 2 (speaker): 11, 4 (headset): 10, 8 (headphone): 10, 400 (hdmi): 6, 40000000 (default): 11\n   Devices: hdmi\n- STREAM_ALARM:\n   Muted: false\n   Min: 0\n   Max: 7\n   Current: 40000000 (default): 6\n   Devices: speaker\n- STREAM_NOTIFICATION:\n'
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_read(24): b'CLSE\x9a\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_write: b'CLSE\x01\x00\x00\x00\x9a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:51:35 DEBUG (SyncWorker_13) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\xb4\x02\x00\x00\x11\xdb\x00\x00\xb0\xaf\xba\xb1'
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b"shell:dumpsys power | grep 'Display Power' | grep -q 'state=ON' && echo -e '1\\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\\c' && (dumpsys audio | grep paused | grep -qv 'Buffer Queue' && echo -e '1\\c' || (dumpsys audio | grep started | grep -qv 'Buffer Queue' && echo '2\\c' || echo '0\\c')) && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo) && dumpsys audio | grep '\\- STREAM_MUSIC:' -A 12\x00"
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(24): b'CLSE\x9a\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(24): b'OKAY\x9b\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9b\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x001\x00\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(1): b'1'
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9b\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x001\x00\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(1): b'1'
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9b\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x000\x00\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(1): b'0'
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9b\x00\x00\x00\x01\x00\x00\x00\x13\x00\x00\x000\x06\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(19): b'Wake Locks: size=0\n'
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9b\x00\x00\x00\x01\x00\x00\x00\x1e\x00\x00\x00V\x0b\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(30): b'com.google.android.youtube.tv\n'
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9b\x00\x00\x00\x01\x00\x00\x00\x98\x00\x00\x00\xa13\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(152): b'      state=PlaybackState {state=0, position=0, buffered position=0, speed=0.0, updated=0, actions=0, custom actions=[], active item id=-1, error=null}\n'
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9b\x00\x00\x00\x01\x00\x00\x00.\x01\x00\x00\xceP\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(302): b'- STREAM_MUSIC:\n   Muted: false\n   Min: 0\n   Max: 15\n   Current: 2 (speaker): 11, 4 (headset): 10, 8 (headphone): 10, 400 (hdmi): 6, 40000000 (default): 11\n   Devices: hdmi\n- STREAM_ALARM:\n   Muted: false\n   Min: 0\n   Max: 7\n   Current: 40000000 (default): 6\n   Devices: speaker\n- STREAM_NOTIFICATION:\n'
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(24): b'CLSE\x9b\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b'CLSE\x01\x00\x00\x00\x9b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:51:46 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\xb4\x02\x00\x00\x11\xdb\x00\x00\xb0\xaf\xba\xb1'
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b"shell:dumpsys power | grep 'Display Power' | grep -q 'state=ON' && echo -e '1\\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\\c' && (dumpsys audio | grep paused | grep -qv 'Buffer Queue' && echo -e '1\\c' || (dumpsys audio | grep started | grep -qv 'Buffer Queue' && echo '2\\c' || echo '0\\c')) && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo) && dumpsys audio | grep '\\- STREAM_MUSIC:' -A 12\x00"
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_read(24): b'CLSE\x9b\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_read(24): b'OKAY\x9c\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9c\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x001\x00\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_read(1): b'1'
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9c\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x001\x00\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_read(1): b'1'
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9c\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x000\x00\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_read(1): b'0'
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9c\x00\x00\x00\x01\x00\x00\x00\x13\x00\x00\x000\x06\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_read(19): b'Wake Locks: size=0\n'
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9c\x00\x00\x00\x01\x00\x00\x00\x1e\x00\x00\x00V\x0b\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_read(30): b'com.google.android.youtube.tv\n'
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9c\x00\x00\x00\x01\x00\x00\x00\x98\x00\x00\x00\xa13\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_read(152): b'      state=PlaybackState {state=0, position=0, buffered position=0, speed=0.0, updated=0, actions=0, custom actions=[], active item id=-1, error=null}\n'
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9c\x00\x00\x00\x01\x00\x00\x00.\x01\x00\x00\xceP\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_read(302): b'- STREAM_MUSIC:\n   Muted: false\n   Min: 0\n   Max: 15\n   Current: 2 (speaker): 11, 4 (headset): 10, 8 (headphone): 10, 400 (hdmi): 6, 40000000 (default): 11\n   Devices: hdmi\n- STREAM_ALARM:\n   Muted: false\n   Min: 0\n   Max: 7\n   Current: 40000000 (default): 6\n   Devices: speaker\n- STREAM_NOTIFICATION:\n'
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_read(24): b'CLSE\x9c\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b'CLSE\x01\x00\x00\x00\x9c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:51:57 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\xb4\x02\x00\x00\x11\xdb\x00\x00\xb0\xaf\xba\xb1'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b"shell:dumpsys power | grep 'Display Power' | grep -q 'state=ON' && echo -e '1\\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\\c' && (dumpsys audio | grep paused | grep -qv 'Buffer Queue' && echo -e '1\\c' || (dumpsys audio | grep started | grep -qv 'Buffer Queue' && echo '2\\c' || echo '0\\c')) && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo) && dumpsys audio | grep '\\- STREAM_MUSIC:' -A 12\x00"
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(24): b'CLSE\x9c\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(24): b'OKAY\x9d\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9d\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x001\x00\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(1): b'1'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9d\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x001\x00\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(1): b'1'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9d\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x000\x00\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(1): b'0'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9d\x00\x00\x00\x01\x00\x00\x00\x13\x00\x00\x000\x06\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(19): b'Wake Locks: size=0\n'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9d\x00\x00\x00\x01\x00\x00\x00\x1e\x00\x00\x00V\x0b\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(30): b'com.google.android.youtube.tv\n'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9d\x00\x00\x00\x01\x00\x00\x00\x98\x00\x00\x00\xa13\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(152): b'      state=PlaybackState {state=0, position=0, buffered position=0, speed=0.0, updated=0, actions=0, custom actions=[], active item id=-1, error=null}\n'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9d\x00\x00\x00\x01\x00\x00\x00\xd7\x00\x00\x00\xe78\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(215): b'- STREAM_MUSIC:\n   Muted: false\n   Min: 0\n   Max: 15\n   Current: 2 (speaker): 11, 4 (headset): 10, 8 (headphone): 10, 400 (hdmi): 6, 40000000 (default): 11\n   Devices: hdmi\n- STREAM_ALARM:\n   Muted: false\n   Min: 0\n'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9d\x00\x00\x00\x01\x00\x00\x00W\x00\x00\x00\xe7\x17\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(87): b'   Max: 7\n   Current: 40000000 (default): 6\n   Devices: speaker\n- STREAM_NOTIFICATION:\n'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_read(24): b'CLSE\x9d\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b'CLSE\x01\x00\x00\x00\x9d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:52:08 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:52:19 DEBUG (SyncWorker_1) [adb_shell.adb_device] bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\xb4\x02\x00\x00\x11\xdb\x00\x00\xb0\xaf\xba\xb1'
2019-10-12 10:52:19 DEBUG (SyncWorker_1) [adb_shell.adb_device] bulk_write: b"shell:dumpsys power | grep 'Display Power' | grep -q 'state=ON' && echo -e '1\\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\\c' && (dumpsys audio | grep paused | grep -qv 'Buffer Queue' && echo -e '1\\c' || (dumpsys audio | grep started | grep -qv 'Buffer Queue' && echo '2\\c' || echo '0\\c')) && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo) && dumpsys audio | grep '\\- STREAM_MUSIC:' -A 12\x00"
2019-10-12 10:52:19 DEBUG (SyncWorker_1) [adb_shell.adb_device] bulk_read(24): b'CLSE\x9d\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:52:19 DEBUG (SyncWorker_1) [adb_shell.adb_device] bulk_read(24): b'CLSE\x9d\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:52:30 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\xb4\x02\x00\x00\x11\xdb\x00\x00\xb0\xaf\xba\xb1'
2019-10-12 10:52:30 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b"shell:dumpsys power | grep 'Display Power' | grep -q 'state=ON' && echo -e '1\\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\\c' && (dumpsys audio | grep paused | grep -qv 'Buffer Queue' && echo -e '1\\c' || (dumpsys audio | grep started | grep -qv 'Buffer Queue' && echo '2\\c' || echo '0\\c')) && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo) && dumpsys audio | grep '\\- STREAM_MUSIC:' -A 12\x00"
2019-10-12 10:52:30 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_read(24): b'OKAY\x9e\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:52:30 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9e\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x001\x00\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:52:30 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_read(1): b'1'
2019-10-12 10:52:30 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:52:30 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:52:30 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9e\x00\x00\x00\x01\x00\x00\x00\xf9\x01\x00\x00V\x96\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:52:30 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_read(505): b'10Wake Locks: size=0\ncom.google.android.youtube.tv\n      state=PlaybackState {state=0, position=0, buffered position=0, speed=0.0, updated=0, actions=0, custom actions=[], active item id=-1, error=null}\n- STREAM_MUSIC:\n   Muted: false\n   Min: 0\n   Max: 15\n   Current: 2 (speaker): 11, 4 (headset): 10, 8 (headphone): 10, 400 (hdmi): 6, 40000000 (default): 11\n   Devices: hdmi\n- STREAM_ALARM:\n   Muted: false\n   Min: 0\n   Max: 7\n   Current: 40000000 (default): 6\n   Devices: speaker\n- STREAM_NOTIFICATION:\n'
2019-10-12 10:52:30 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:52:30 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:52:30 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_read(24): b'CLSE\x9e\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:52:30 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b'CLSE\x01\x00\x00\x00\x9e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:52:30 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:52:41 DEBUG (SyncWorker_10) [adb_shell.adb_device] bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\xb4\x02\x00\x00\x11\xdb\x00\x00\xb0\xaf\xba\xb1'
2019-10-12 10:52:41 DEBUG (SyncWorker_10) [adb_shell.adb_device] bulk_write: b"shell:dumpsys power | grep 'Display Power' | grep -q 'state=ON' && echo -e '1\\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\\c' && (dumpsys audio | grep paused | grep -qv 'Buffer Queue' && echo -e '1\\c' || (dumpsys audio | grep started | grep -qv 'Buffer Queue' && echo '2\\c' || echo '0\\c')) && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo) && dumpsys audio | grep '\\- STREAM_MUSIC:' -A 12\x00"
2019-10-12 10:52:41 DEBUG (SyncWorker_10) [adb_shell.adb_device] bulk_read(24): b'OKAY\x9f\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:52:41 DEBUG (SyncWorker_10) [adb_shell.adb_device] bulk_read(24): b'CLSE\x9e\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:52:41 DEBUG (SyncWorker_10) [adb_shell.adb_device] bulk_read(24): b'CLSE\x9e\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:52:41 DEBUG (SyncWorker_10) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9f\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x001\x00\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:52:41 DEBUG (SyncWorker_10) [adb_shell.adb_device] bulk_read(1): b'1'
2019-10-12 10:52:41 DEBUG (SyncWorker_10) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:52:41 DEBUG (SyncWorker_10) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:52:41 DEBUG (SyncWorker_10) [adb_shell.adb_device] bulk_read(24): b'WRTE\x9f\x00\x00\x00\x01\x00\x00\x00\xf9\x01\x00\x00V\x96\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:52:41 DEBUG (SyncWorker_10) [adb_shell.adb_device] bulk_read(505): b'10Wake Locks: size=0\ncom.google.android.youtube.tv\n      state=PlaybackState {state=0, position=0, buffered position=0, speed=0.0, updated=0, actions=0, custom actions=[], active item id=-1, error=null}\n- STREAM_MUSIC:\n   Muted: false\n   Min: 0\n   Max: 15\n   Current: 2 (speaker): 11, 4 (headset): 10, 8 (headphone): 10, 400 (hdmi): 6, 40000000 (default): 11\n   Devices: hdmi\n- STREAM_ALARM:\n   Muted: false\n   Min: 0\n   Max: 7\n   Current: 40000000 (default): 6\n   Devices: speaker\n- STREAM_NOTIFICATION:\n'
2019-10-12 10:52:41 DEBUG (SyncWorker_10) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\x9f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:52:41 DEBUG (SyncWorker_10) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:52:41 DEBUG (SyncWorker_10) [adb_shell.adb_device] bulk_read(24): b'CLSE\x9f\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:52:41 DEBUG (SyncWorker_10) [adb_shell.adb_device] bulk_write: b'CLSE\x01\x00\x00\x00\x9f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:52:41 DEBUG (SyncWorker_10) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:52:52 DEBUG (SyncWorker_7) [adb_shell.adb_device] bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\xb4\x02\x00\x00\x11\xdb\x00\x00\xb0\xaf\xba\xb1'
2019-10-12 10:52:52 DEBUG (SyncWorker_7) [adb_shell.adb_device] bulk_write: b"shell:dumpsys power | grep 'Display Power' | grep -q 'state=ON' && echo -e '1\\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\\c' && (dumpsys audio | grep paused | grep -qv 'Buffer Queue' && echo -e '1\\c' || (dumpsys audio | grep started | grep -qv 'Buffer Queue' && echo '2\\c' || echo '0\\c')) && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo) && dumpsys audio | grep '\\- STREAM_MUSIC:' -A 12\x00"
2019-10-12 10:52:52 DEBUG (SyncWorker_7) [adb_shell.adb_device] bulk_read(24): b'OKAY\xa0\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:52:52 DEBUG (SyncWorker_7) [adb_shell.adb_device] bulk_read(24): b'CLSE\x9f\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:52:52 DEBUG (SyncWorker_7) [adb_shell.adb_device] bulk_read(24): b'CLSE\x9f\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:52:52 DEBUG (SyncWorker_7) [adb_shell.adb_device] bulk_read(24): b'WRTE\xa0\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x001\x00\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:52:52 DEBUG (SyncWorker_7) [adb_shell.adb_device] bulk_read(1): b'1'
2019-10-12 10:52:52 DEBUG (SyncWorker_7) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\xa0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:52:52 DEBUG (SyncWorker_7) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:52:52 DEBUG (SyncWorker_7) [adb_shell.adb_device] bulk_read(24): b'WRTE\xa0\x00\x00\x00\x01\x00\x00\x00\xf9\x01\x00\x00V\x96\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:52:52 DEBUG (SyncWorker_7) [adb_shell.adb_device] bulk_read(505): b'10Wake Locks: size=0\ncom.google.android.youtube.tv\n      state=PlaybackState {state=0, position=0, buffered position=0, speed=0.0, updated=0, actions=0, custom actions=[], active item id=-1, error=null}\n- STREAM_MUSIC:\n   Muted: false\n   Min: 0\n   Max: 15\n   Current: 2 (speaker): 11, 4 (headset): 10, 8 (headphone): 10, 400 (hdmi): 6, 40000000 (default): 11\n   Devices: hdmi\n- STREAM_ALARM:\n   Muted: false\n   Min: 0\n   Max: 7\n   Current: 40000000 (default): 6\n   Devices: speaker\n- STREAM_NOTIFICATION:\n'
2019-10-12 10:52:52 DEBUG (SyncWorker_7) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\xa0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:52:52 DEBUG (SyncWorker_7) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:52:52 DEBUG (SyncWorker_7) [adb_shell.adb_device] bulk_read(24): b'CLSE\xa0\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:52:52 DEBUG (SyncWorker_7) [adb_shell.adb_device] bulk_write: b'CLSE\x01\x00\x00\x00\xa0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:52:52 DEBUG (SyncWorker_7) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:53:03 DEBUG (SyncWorker_18) [adb_shell.adb_device] bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\xb4\x02\x00\x00\x11\xdb\x00\x00\xb0\xaf\xba\xb1'
2019-10-12 10:53:03 DEBUG (SyncWorker_18) [adb_shell.adb_device] bulk_write: b"shell:dumpsys power | grep 'Display Power' | grep -q 'state=ON' && echo -e '1\\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\\c' && (dumpsys audio | grep paused | grep -qv 'Buffer Queue' && echo -e '1\\c' || (dumpsys audio | grep started | grep -qv 'Buffer Queue' && echo '2\\c' || echo '0\\c')) && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo) && dumpsys audio | grep '\\- STREAM_MUSIC:' -A 12\x00"
2019-10-12 10:53:03 DEBUG (SyncWorker_18) [adb_shell.adb_device] bulk_read(24): b'OKAY\xa1\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:53:03 DEBUG (SyncWorker_18) [adb_shell.adb_device] bulk_read(24): b'CLSE\xa0\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:53:03 DEBUG (SyncWorker_18) [adb_shell.adb_device] bulk_read(24): b'CLSE\xa0\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:53:03 DEBUG (SyncWorker_18) [adb_shell.adb_device] bulk_read(24): b'WRTE\xa1\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x001\x00\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:53:03 DEBUG (SyncWorker_18) [adb_shell.adb_device] bulk_read(1): b'1'
2019-10-12 10:53:03 DEBUG (SyncWorker_18) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\xa1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:53:03 DEBUG (SyncWorker_18) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:53:03 DEBUG (SyncWorker_18) [adb_shell.adb_device] bulk_read(24): b'WRTE\xa1\x00\x00\x00\x01\x00\x00\x00\xf9\x01\x00\x00V\x96\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:53:03 DEBUG (SyncWorker_18) [adb_shell.adb_device] bulk_read(505): b'10Wake Locks: size=0\ncom.google.android.youtube.tv\n      state=PlaybackState {state=0, position=0, buffered position=0, speed=0.0, updated=0, actions=0, custom actions=[], active item id=-1, error=null}\n- STREAM_MUSIC:\n   Muted: false\n   Min: 0\n   Max: 15\n   Current: 2 (speaker): 11, 4 (headset): 10, 8 (headphone): 10, 400 (hdmi): 6, 40000000 (default): 11\n   Devices: hdmi\n- STREAM_ALARM:\n   Muted: false\n   Min: 0\n   Max: 7\n   Current: 40000000 (default): 6\n   Devices: speaker\n- STREAM_NOTIFICATION:\n'
2019-10-12 10:53:03 DEBUG (SyncWorker_18) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\xa1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:53:03 DEBUG (SyncWorker_18) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:53:03 DEBUG (SyncWorker_18) [adb_shell.adb_device] bulk_read(24): b'CLSE\xa1\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:53:03 DEBUG (SyncWorker_18) [adb_shell.adb_device] bulk_write: b'CLSE\x01\x00\x00\x00\xa1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:53:03 DEBUG (SyncWorker_18) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:53:14 DEBUG (SyncWorker_2) [adb_shell.adb_device] bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\xb4\x02\x00\x00\x11\xdb\x00\x00\xb0\xaf\xba\xb1'
2019-10-12 10:53:14 DEBUG (SyncWorker_2) [adb_shell.adb_device] bulk_write: b"shell:dumpsys power | grep 'Display Power' | grep -q 'state=ON' && echo -e '1\\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\\c' && (dumpsys audio | grep paused | grep -qv 'Buffer Queue' && echo -e '1\\c' || (dumpsys audio | grep started | grep -qv 'Buffer Queue' && echo '2\\c' || echo '0\\c')) && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo) && dumpsys audio | grep '\\- STREAM_MUSIC:' -A 12\x00"
2019-10-12 10:53:14 DEBUG (SyncWorker_2) [adb_shell.adb_device] bulk_read(24): b'OKAY\xa2\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:53:14 DEBUG (SyncWorker_2) [adb_shell.adb_device] bulk_read(24): b'CLSE\xa1\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:53:14 DEBUG (SyncWorker_2) [adb_shell.adb_device] bulk_read(24): b'CLSE\xa1\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:53:14 DEBUG (SyncWorker_2) [adb_shell.adb_device] bulk_read(24): b'WRTE\xa2\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x001\x00\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:53:14 DEBUG (SyncWorker_2) [adb_shell.adb_device] bulk_read(1): b'1'
2019-10-12 10:53:14 DEBUG (SyncWorker_2) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\xa2\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:53:14 DEBUG (SyncWorker_2) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:53:14 DEBUG (SyncWorker_2) [adb_shell.adb_device] bulk_read(24): b'WRTE\xa2\x00\x00\x00\x01\x00\x00\x00b\x01\x00\x00\xd7b\x00\x00\xa8\xad\xab\xba'
2019-10-12 10:53:14 DEBUG (SyncWorker_2) [adb_shell.adb_device] bulk_read(354): b'10Wake Locks: size=1\ncom.google.android.tvlauncher\n\n- STREAM_MUSIC:\n   Muted: false\n   Min: 0\n   Max: 15\n   Current: 2 (speaker): 11, 4 (headset): 10, 8 (headphone): 10, 400 (hdmi): 6, 40000000 (default): 11\n   Devices: hdmi\n- STREAM_ALARM:\n   Muted: false\n   Min: 0\n   Max: 7\n   Current: 40000000 (default): 6\n   Devices: speaker\n- STREAM_NOTIFICATION:\n'
2019-10-12 10:53:14 DEBUG (SyncWorker_2) [adb_shell.adb_device] bulk_write: b'OKAY\x01\x00\x00\x00\xa2\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:53:14 DEBUG (SyncWorker_2) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:53:14 DEBUG (SyncWorker_2) [adb_shell.adb_device] bulk_read(24): b'CLSE\xa2\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:53:14 DEBUG (SyncWorker_2) [adb_shell.adb_device] bulk_write: b'CLSE\x01\x00\x00\x00\xa2\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:53:14 DEBUG (SyncWorker_2) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:53:25 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\xb4\x02\x00\x00\x11\xdb\x00\x00\xb0\xaf\xba\xb1'
2019-10-12 10:53:25 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_write: b"shell:dumpsys power | grep 'Display Power' | grep -q 'state=ON' && echo -e '1\\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\\c' && (dumpsys audio | grep paused | grep -qv 'Buffer Queue' && echo -e '1\\c' || (dumpsys audio | grep started | grep -qv 'Buffer Queue' && echo '2\\c' || echo '0\\c')) && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo) && dumpsys audio | grep '\\- STREAM_MUSIC:' -A 12\x00"
2019-10-12 10:53:25 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_read(24): b'OKAY\xa3\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:53:25 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_read(24): b'CLSE\xa2\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:53:25 DEBUG (SyncWorker_12) [adb_shell.adb_device] bulk_read(24): b'CLSE\xa2\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:53:34 ERROR (SyncWorker_12) [homeassistant.components.androidtv.media_player] Failed to execute an ADB command. ADB connection re-establishing attempt in the next update. Error: Reading from mibox.bieniu.lan:5555 timed out (9.0 seconds)
2019-10-12 10:53:44 WARNING (SyncWorker_1) [androidtv.adb_manager] Couldn't connect to host mibox.bieniu.lan:5555, error: Timed out trying to connect to ADB device.
2019-10-12 10:55:24 DEBUG (SyncWorker_6) [adb_shell.adb_device] bulk_write: b'CNXN\x00\x00\x00\x01\x00\x10\x00\x00\x10\x00\x00\x00\x0c\x06\x00\x00\xbc\xb1\xa7\xb1'
2019-10-12 10:55:24 DEBUG (SyncWorker_6) [adb_shell.adb_device] bulk_write: b'host::raspberry\x00'
2019-10-12 10:55:24 DEBUG (SyncWorker_6) [adb_shell.adb_device] bulk_read(24): b'AUTH\x01\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\x94\t\x00\x00\xbe\xaa\xab\xb7'
2019-10-12 10:55:24 DEBUG (SyncWorker_6) [adb_shell.adb_device] bulk_read(20): b'P\xa5\x86\x97\xe8\x01\xb09\x8c>F\x9d\xc6\xbd\xc0J\x80!\xbb\x1a'
2019-10-12 10:55:24 DEBUG (SyncWorker_6) [adb_shell.adb_device] bulk_write: b'AUTH\x02\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\xd1\x7f\x00\x00\xbe\xaa\xab\xb7'
2019-10-12 10:55:24 DEBUG (SyncWorker_6) [adb_shell.adb_device] bulk_write: b'v\xc3\xd1)\xbd\xb0\x0b\x0e\x9a\xc3\xa0ZV\x10)\xeb\x8b\x98\xcc\xe5V\x10\x8a\xb9\x11>8"\xc7\xc9\x9a\xfc\x9e\x1b\xfc&:\xc0\x1dO\x80\xc3*\x01\xf1\xd7"\x1c9\x0e\xf7\xbc\xed\x08\x9e\xed9\x19s\xae\x16\x99\xe1_\n\xe2\xfc\x80\xd96\x87\xd0U\n\xe5xr%\x7f;$\x95\xce\xf7\xdd\x01\x10t\xb4\x08"@\xe0\xfe\x00\xd4\xc5\x0c\xd9K*w\x99\xc3\xe6V\xcf`\x81S\xa5\xfa\xa3\xe4uAn\t\x88\xe4\xcb\xa1RB\\w\xc3WQ\x9e\xd6v\xb43\x80:\\\x9d\xb2\x8e\x8f\x8d*\x86\xa1\x0f,\xbdw\x8bg!\xd2\x17A\x9a\xc3\xe4-\x85\x97\x12}\xa8}e\x8d:\xd4\x04p\x1b\xad(5\xec\x93\x0cMH\x1e2Z\xd0n4\xdd\x9b\xb3\x94u\t\xe2\x86\xf0\xb8W\xd2\x95\x80\xdf\x15\xf0X\xb9}\xd2N\x86=\x1c\xab\xa9\xfe\x1b2\xa9>\x8d\xe3c\xf44\xdf\xfc\xa7\x9c\xbe\xd5r\x14\xaa\xea7Z\xb2u\xfd=PSh\xdf2\xa8\xb9\x07\x81\xa5\xeb\xcc\x1d\xf2\xa1\xf0\x86'
2019-10-12 10:55:25 DEBUG (SyncWorker_6) [adb_shell.adb_device] bulk_read(24): b"CNXN\x00\x00\x00\x01\x00\x10\x00\x00i\x00\x00\x00.'\x00\x00\xbc\xb1\xa7\xb1"
2019-10-12 10:55:25 DEBUG (SyncWorker_6) [adb_shell.adb_device] bulk_read(105): b'device::ro.product.name=once;ro.product.model=MIBOX3;ro.product.device=once;features=stat_v2,cmd,shell_v2'
2019-10-12 10:55:35 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\xb4\x02\x00\x00\x11\xdb\x00\x00\xb0\xaf\xba\xb1'
2019-10-12 10:55:35 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b"shell:dumpsys power | grep 'Display Power' | grep -q 'state=ON' && echo -e '1\\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\\c' && (dumpsys audio | grep paused | grep -qv 'Buffer Queue' && echo -e '1\\c' || (dumpsys audio | grep started | grep -qv 'Buffer Queue' && echo '2\\c' || echo '0\\c')) && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo) && dumpsys audio | grep '\\- STREAM_MUSIC:' -A 12\x00"
2019-10-12 10:55:35 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_read(24): b'OKAY\xa5\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:55:35 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_read(24): b'CLSE\xa5\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:55:35 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b'CLSE\x01\x00\x00\x00\xa5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:55:35 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:55:46 DEBUG (SyncWorker_6) [adb_shell.adb_device] bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\xb4\x02\x00\x00\x11\xdb\x00\x00\xb0\xaf\xba\xb1'
2019-10-12 10:55:46 DEBUG (SyncWorker_6) [adb_shell.adb_device] bulk_write: b"shell:dumpsys power | grep 'Display Power' | grep -q 'state=ON' && echo -e '1\\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\\c' && (dumpsys audio | grep paused | grep -qv 'Buffer Queue' && echo -e '1\\c' || (dumpsys audio | grep started | grep -qv 'Buffer Queue' && echo '2\\c' || echo '0\\c')) && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo) && dumpsys audio | grep '\\- STREAM_MUSIC:' -A 12\x00"
2019-10-12 10:55:55 ERROR (SyncWorker_6) [homeassistant.components.androidtv.media_player] Failed to execute an ADB command. ADB connection re-establishing attempt in the next update. Error: Reading from mibox.bieniu.lan:5555 timed out (9.0 seconds)
2019-10-12 10:56:05 WARNING (SyncWorker_17) [androidtv.adb_manager] Couldn't connect to host mibox.bieniu.lan:5555, error: Timed out trying to connect to ADB device.
2019-10-12 10:57:24 DEBUG (SyncWorker_16) [adb_shell.adb_device] bulk_write: b'CNXN\x00\x00\x00\x01\x00\x10\x00\x00\x10\x00\x00\x00\x0c\x06\x00\x00\xbc\xb1\xa7\xb1'
2019-10-12 10:57:24 DEBUG (SyncWorker_16) [adb_shell.adb_device] bulk_write: b'host::raspberry\x00'
2019-10-12 10:57:24 DEBUG (SyncWorker_16) [adb_shell.adb_device] bulk_read(24): b'AUTH\x01\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00e\x0c\x00\x00\xbe\xaa\xab\xb7'
2019-10-12 10:57:24 DEBUG (SyncWorker_16) [adb_shell.adb_device] bulk_read(20): b'\xd3\xef\x7f_\xa6\xc0`b\x19\\z\xe4\xf3\xe2\xed\x8d\xe1W\xfbH'
2019-10-12 10:57:24 DEBUG (SyncWorker_16) [adb_shell.adb_device] bulk_write: b'AUTH\x02\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\xaa\x8b\x00\x00\xbe\xaa\xab\xb7'
2019-10-12 10:57:24 DEBUG (SyncWorker_16) [adb_shell.adb_device] bulk_write: b'\xa0D\xbcO?\xab\x817G\xdc}^\x98Y\xe3\xa6\xc0\xdc\xdeY36\xdbU\xd5/\x9c\x91`\xff\x0f\xa7\x85L\xc3\xe2\x91\x8f~\xd9Q\xb2\x1f#\x01\xd12N\xd8\xf4[\xd5k\xd6\xb4y\x91El\xd6\xea[\xae/\x93\xf7o\xcc\xc7t\xdc\xc3\xfb\xad\xcc\x91\x0e\xfcs[\xfa\xc7\x83\xb3\xc7\xe4\xbdu\xc1\xbf\xd3\xe0\xcatIH\xae\xd87\xb12kgnQ-\xcca\xbc\x02KZ\x1a\xe49\xbe\xa1\xc9\xad\xa5\xd9>\x7f\x15\xcc\x86\xa6\x9a\x9f\xea\xae\x08I\xc8\xfc4\xf3\xbfh\xa5\x8a+A\xaa\xc7b\x90\x8b^|Z\xc7\xd4\xcd\x0e\x00_uX\xc2`\xf6\xc6\xcb\xda\x18\xf8`(\xdc\xbck\xe8\xe20\xeed7\xb5\x01\xe2\xfa\xa2P\x13\xb3\xb0r\xbfa$\x98\xf4\xebA\x1aiG\xbf\xcd\xc5\xf5b\xb1\x9d\x151\t\x10\xebM[\x02\x04\xe1\x12\xbb\x93\x8b\xc0\xe0\xe61\xaa\x9e\xa8\xb5GBM\xf3\xd5\x0f\x94\x11\x88\x8d\x8f\xb0\xb8\xfcj(E\x8ag\x96\xcde\x92\xe5,\xe4\xb1\x96\xff'
2019-10-12 10:57:24 DEBUG (SyncWorker_16) [adb_shell.adb_device] bulk_read(24): b"CNXN\x00\x00\x00\x01\x00\x10\x00\x00i\x00\x00\x00.'\x00\x00\xbc\xb1\xa7\xb1"
2019-10-12 10:57:24 DEBUG (SyncWorker_16) [adb_shell.adb_device] bulk_read(105): b'device::ro.product.name=once;ro.product.model=MIBOX3;ro.product.device=once;features=stat_v2,cmd,shell_v2'
2019-10-12 10:57:35 DEBUG (SyncWorker_5) [adb_shell.adb_device] bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\xb4\x02\x00\x00\x11\xdb\x00\x00\xb0\xaf\xba\xb1'
2019-10-12 10:57:35 DEBUG (SyncWorker_5) [adb_shell.adb_device] bulk_write: b"shell:dumpsys power | grep 'Display Power' | grep -q 'state=ON' && echo -e '1\\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\\c' && (dumpsys audio | grep paused | grep -qv 'Buffer Queue' && echo -e '1\\c' || (dumpsys audio | grep started | grep -qv 'Buffer Queue' && echo '2\\c' || echo '0\\c')) && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo) && dumpsys audio | grep '\\- STREAM_MUSIC:' -A 12\x00"
2019-10-12 10:57:35 DEBUG (SyncWorker_5) [adb_shell.adb_device] bulk_read(24): b'OKAY\xa7\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:57:35 DEBUG (SyncWorker_5) [adb_shell.adb_device] bulk_read(24): b'CLSE\xa7\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:57:35 DEBUG (SyncWorker_5) [adb_shell.adb_device] bulk_write: b'CLSE\x01\x00\x00\x00\xa7\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:57:35 DEBUG (SyncWorker_5) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:57:46 DEBUG (SyncWorker_14) [adb_shell.adb_device] bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\xb4\x02\x00\x00\x11\xdb\x00\x00\xb0\xaf\xba\xb1'
2019-10-12 10:57:46 DEBUG (SyncWorker_14) [adb_shell.adb_device] bulk_write: b"shell:dumpsys power | grep 'Display Power' | grep -q 'state=ON' && echo -e '1\\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\\c' && (dumpsys audio | grep paused | grep -qv 'Buffer Queue' && echo -e '1\\c' || (dumpsys audio | grep started | grep -qv 'Buffer Queue' && echo '2\\c' || echo '0\\c')) && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo) && dumpsys audio | grep '\\- STREAM_MUSIC:' -A 12\x00"
2019-10-12 10:57:55 ERROR (SyncWorker_14) [homeassistant.components.androidtv.media_player] Failed to execute an ADB command. ADB connection re-establishing attempt in the next update. Error: Reading from mibox.bieniu.lan:5555 timed out (9.0 seconds)
2019-10-12 10:58:05 WARNING (SyncWorker_3) [androidtv.adb_manager] Couldn't connect to host mibox.bieniu.lan:5555, error: Timed out trying to connect to ADB device.
2019-10-12 10:59:23 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b'CNXN\x00\x00\x00\x01\x00\x10\x00\x00\x10\x00\x00\x00\x0c\x06\x00\x00\xbc\xb1\xa7\xb1'
2019-10-12 10:59:23 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b'host::raspberry\x00'
2019-10-12 10:59:23 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_read(24): b'AUTH\x01\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\x93\x08\x00\x00\xbe\xaa\xab\xb7'
2019-10-12 10:59:23 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_read(20): b's\xd4_e\xa4s\x02\x95\x0f\x1e\xec\n\x95Y9[`\x8e\xe1f'
2019-10-12 10:59:23 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b'AUTH\x02\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\xfb\x86\x00\x00\xbe\xaa\xab\xb7'
2019-10-12 10:59:23 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b"3\x98\x17A\x80<\xf8\xf3\x8a)\xf6\xa5\xbf\x90\x9b\xb8\x11\xc8\xbdO\xae\x14\xaf\xb1\xd3\x90\xaat\xaa4\xd0\x10-\x89tE\x8b\xfd)?u\xb5\x89\xe2$\xaei\xfd\x15 \x82\xee\xa7\x0b$\x9f\xe3\xd9\x7f\xcc\xe1\xa3E\xd6\xdf\xadS\x1d\xd7\xd6\x8b\x0fSK\xa5-~M\xdb{\xc9\xd7\x05\xea%u5\x15\xf7\xee\x06\x8c\xfeF\x95'\xed\x86\xd9}.$\n0\xc88?{7\xdeCd3\xe9\xdb\x06\xd3E`\xa9\x9b\xf1\xe6*\xe9\xff\xe3\x13\x93k)\xc3`a\xef\xdfR\xd9\x88\xd6g=\x89>\xc9})C\xec\x8c\xb2\xbdP\x0ec\xd5\x83go\xe2L\xd9d;\xf1\xadlw}i\xbcou\xa0\xd1\x15v\xa4.\xc5\xdb\xda^\xbf\xdd\xc6\xe6\xc1C\xcb\x94\xae\xe8\xef/\x08$8#\xb5P\xf6\x8b\x95\x83`\xa9\x99\xdf\xb0\x04\xef\xd6|\xa1\x1cm7\xab`>\x89U\xbb\xc2\xb3d\xf3\xc9\xb64;_\xdc\xd9\x93\xe1g\xee\x1c\x15A\xc6\x8b\xd5\\\xf7\xc3O<\xa8\x800\xdc\x16O"
2019-10-12 10:59:23 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_read(24): b"CNXN\x00\x00\x00\x01\x00\x10\x00\x00i\x00\x00\x00.'\x00\x00\xbc\xb1\xa7\xb1"
2019-10-12 10:59:23 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_read(105): b'device::ro.product.name=once;ro.product.model=MIBOX3;ro.product.device=once;features=stat_v2,cmd,shell_v2'
2019-10-12 10:59:34 DEBUG (SyncWorker_15) [adb_shell.adb_device] bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\xb4\x02\x00\x00\x11\xdb\x00\x00\xb0\xaf\xba\xb1'
2019-10-12 10:59:34 DEBUG (SyncWorker_15) [adb_shell.adb_device] bulk_write: b"shell:dumpsys power | grep 'Display Power' | grep -q 'state=ON' && echo -e '1\\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\\c' && (dumpsys audio | grep paused | grep -qv 'Buffer Queue' && echo -e '1\\c' || (dumpsys audio | grep started | grep -qv 'Buffer Queue' && echo '2\\c' || echo '0\\c')) && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo) && dumpsys audio | grep '\\- STREAM_MUSIC:' -A 12\x00"
2019-10-12 10:59:34 DEBUG (SyncWorker_15) [adb_shell.adb_device] bulk_read(24): b'OKAY\xa9\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6'
2019-10-12 10:59:34 DEBUG (SyncWorker_15) [adb_shell.adb_device] bulk_read(24): b'CLSE\xa9\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:59:34 DEBUG (SyncWorker_15) [adb_shell.adb_device] bulk_write: b'CLSE\x01\x00\x00\x00\xa9\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba'
2019-10-12 10:59:34 DEBUG (SyncWorker_15) [adb_shell.adb_device] bulk_write: b''
2019-10-12 10:59:45 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\xb4\x02\x00\x00\x11\xdb\x00\x00\xb0\xaf\xba\xb1'
2019-10-12 10:59:45 DEBUG (SyncWorker_0) [adb_shell.adb_device] bulk_write: b"shell:dumpsys power | grep 'Display Power' | grep -q 'state=ON' && echo -e '1\\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\\c' && (dumpsys audio | grep paused | grep -qv 'Buffer Queue' && echo -e '1\\c' || (dumpsys audio | grep started | grep -qv 'Buffer Queue' && echo '2\\c' || echo '0\\c')) && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo) && dumpsys audio | grep '\\- STREAM_MUSIC:' -A 12\x00"
2019-10-12 10:59:54 ERROR (SyncWorker_0) [homeassistant.components.androidtv.media_player] Failed to execute an ADB command. ADB connection re-establishing attempt in the next update. Error: Reading from mibox.bieniu.lan:5555 timed out (9.0 seconds)
2019-10-12 11:00:05 WARNING (SyncWorker_4) [androidtv.adb_manager] Couldn't connect to host mibox.bieniu.lan:5555, error: Timed out trying to connect to ADB device.

Unable to unpack ADB command... error('unpack requires a buffer of 24 bytes',)

This error keeps occurring for me when I run an automated script. Its occurrence is random; the error sometimes happens after looping through my program 20 times or sometimes after looping 200 times. I have tried looking at adb_message.py to see if there is anything I can do to fix this but nothing I have tried so far has helped.

My last idea is to change encoding/decoding from utf-8 to latin-1, but this would be a change in several adb_shell files. I have searched the other issues and the solutions there did not help; mainly setting adb_device._maxdata = 2048.

log_dev=device.shell('logcat -v epoch -d')   
  File "/usr/local/lib/python3.6/dist-packages/adb_shell/adb_device.py", line 445, in shell
    return self._service(b'shell', command.encode('utf8'), transport_timeout_s, read_timeout_s, timeout_s, decode)
  File "/usr/local/lib/python3.6/dist-packages/adb_shell/adb_device.py", line 333, in _service
    return b''.join(self._streaming_command(service, command, adb_info)).decode('utf8')
  File "/usr/local/lib/python3.6/dist-packages/adb_shell/adb_device.py", line 997, in _streaming_command
    for data in self._read_until_close(adb_info):
  File "/usr/local/lib/python3.6/dist-packages/adb_shell/adb_device.py", line 932, in _read_until_close
    cmd, data = self._read_until([constants.CLSE, constants.WRTE], adb_info)
  File "/usr/local/lib/python3.6/dist-packages/adb_shell/adb_device.py", line 888, in _read_until
    cmd, remote_id2, local_id2, data = self._read(expected_cmds, adb_info)
  File "/usr/local/lib/python3.6/dist-packages/adb_shell/adb_device.py", line 825, in _read
    cmd, arg0, arg1, data_length, data_checksum = unpack(msg)
  File "/usr/local/lib/python3.6/dist-packages/adb_shell/adb_message.py", line 122, in unpack
    raise ValueError('Unable to unpack ADB command. (length={})'.format(len(message)), constants.MESSAGE_FORMAT, message, e)
ValueError: ('Unable to unpack ADB command. (length=18)', b'<6I', 
b'CLSE\xa2\x06\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00', error('unpack requires a buffer of 24 bytes',))

Asked to approve the adb connection at each HA restart

Description

  • I use a static adbkey
  • I have both a Fire TV and a Nvidia Shield and both show the same inconvenience

Each time I restart HA, I'm asked to approve the adb key, even if I check "Always authorize"
The key thumbprint is always the same.

As the adb connection works with "plain" adb, I assume it is an issue or with the lib, or with my specific setup.

Log

2021-01-11 10:31:53 DEBUG (MainThread) [adb_shell.adb_device_async] bulk_write: b'CNXN\x00\x00\x00\x01\x00\x00\x10\x00\x0c\x00\x00\x00~\x03\x00\x00\xbc\xb1\xa7\xb1'
2021-01-11 10:31:54 DEBUG (MainThread) [adb_shell.adb_device_async] bulk_write: b'host::RPI-4\x00'
2021-01-11 10:31:55 DEBUG (MainThread) [adb_shell.adb_device_async] bulk_read(24): b'AUTH\x01\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00Z\x0c\x00\x00\xbe\xaa\xab\xb7'
2021-01-11 10:31:55 DEBUG (MainThread) [adb_shell.adb_device_async] bulk_read(20): b'\x88\xd9\xee\x0f\xf0\xb8\xa4~\x89\x15\xe2\xaa\x8f_\x81\xf0\xf5\xf7yD'
2021-01-11 10:31:55 DEBUG (MainThread) [adb_shell.adb_device_async] bulk_write: b'AUTH\x02\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\xfc{\x00\x00\xbe\xaa\xab\xb7'
2021-01-11 10:31:55 DEBUG (MainThread) [adb_shell.adb_device_async] bulk_write: b"y\xb4E\xe1{\xc2\xcb\xa7\x1dD\xa6}u\r\x04%\xbd\x9e\x15s\x07\xd2E\xa1?\xa7\x7f\xf7An\xd8+X\xc0{7\xd9\xa6(\xa18\xcar\xc2<\xc2\xc4\x85\xcb\xfd\xe3`\xcfS,?\x84\x7f\x9c_\x0b`\xfdEz\xa8\xbc{N\xf9\xb9\xefU[P\x94\x0b\x8cf\xdb\x8bX\x9e*\x0f\x0b/\xfe\x87\x95\xb9\xda\xc7$\xfb W\xc7\xc3\xd7\xe1(\x1d\xa6ra\xdd\xd5\xdc#p\x93'\x14\xe8\xd8\xd8\x078\x85\xd0\x18k\xb3\x9d\xaa\xfdK\xae\xa7 \x8es\x98\xc7\x98\xdc,\x9cYi\x7f^\x92KZ\xee\xa1\x13\x0fJ\xa0u\xe9\x0b\x10?Q\xc3*6\x05\xe5\xfa\xb1\xfcE\x07f\xe0'\x89Y\xa5\x8an\xd2\x12\xb5\\H\xd1S\xe1\x9e\xdc1Cu\xc2:3\xab\xee\x02H\xc6}\x1dz\x9aA\xa0r\xafR\x0b\x8aJ\xd9\xf3\x15ap\xcc[\xf4#b\\\xe4s\x1e\xd7\x8dy\xea\x91\x07\x90\x98\x03\x0b\xbdZ5#\x96\x13\xcc\xb9Cw\x1b1\x9eU/\x94$F\x87|5\x88\xa7"
2021-01-11 10:31:55 DEBUG (MainThread) [adb_shell.adb_device_async] bulk_read(24): b'AUTH\x01\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\xb6\x08\x00\x00\xbe\xaa\xab\xb7'
2021-01-11 10:31:55 DEBUG (MainThread) [adb_shell.adb_device_async] bulk_read(20): b'\xfc\x19\xeaK\xc3\x18\x03L\x1c@l\x97\x89C\xd8Y\x9a\x06\x8c\xba'
2021-01-11 10:31:55 DEBUG (MainThread) [adb_shell.adb_device_async] bulk_write: b'AUTH\x03\x00\x00\x00\x00\x00\x00\x00\xc6\x02\x00\x00\xef\xec\x00\x00\xbe\xaa\xab\xb7'
2021-01-11 10:31:55 DEBUG (MainThread) [adb_shell.adb_device_async] bulk_write: bytearray(b'QAAAAFWm+h8D2cpCU4aMqSfgJCTxknD0b3pe0mTg4KbKhosqbxMI9qI50zz0yc5Ju7AcFoux9hMPOlro0f3btMzx1KMldrsbVz+tWvEkEAQgglh1/ntBe0+FISbHSaV0mLV3RAte/ISQ8WsuY+QAB2IghPgnWM7VflJf4QZLovaMvBCj9NlzAk4DEvTivqRQv4KltfW0O+cUwDxqWms6H3rzN6oefZSQlCje4BXArsDz3GZwilyvyBi81qFNdPk6MHnSqyyFQKXoVhdEW0X5mZEQPRBjWc4tLPmWzEpJLr8f0Dn55hOwfL9mezd++tC1MCaqgtBM0AVADrNsvviM+qDG4V104Uuw9/kJDq/AL8shn8XkeOtkg46DvvDVr1phZhAs2vLyz7rkVRm38uX9MlfhFzd9jdMktPktN+isAiNI7I0itFCmJH5ztOvWC51pYmoEvpQbC+uw/282kF8DhGG+R8uGtSJmplWlhP2lnKye2mwNVRA3iBis7ZheORc8jwz+z0lN2XsrkCy6iRWiauK/4aITHWJ5KRaIq4hwhEEAIc1uM/U61i7Jun0RE5X0SO+4RYJG8GkvAT/IfD5NqVW9qzuZhYlZdzpDavkrsWTI22ZFWWhJ3rW7F8C6l9PVCdsUXMLUk8dKfX0SD2Ad6r8LaWBkiVfzQPUP6Gm9229tYyK7pNLCBwEAAQA= @unknown\x00')
2021-01-11 10:32:02 WARNING (MainThread) [homeassistant.components.media_player] Setup of media_player platform androidtv is taking over 10 seconds.
2021-01-11 10:32:05 WARNING (MainThread) [androidtv.adb_manager.adb_manager_async] Couldn't connect to amazon-4c8a85df4.lan:5555.  TcpTimeoutException: Reading from amazon-4c8a85df4.lan:5555 timed out (10.0 seconds)
2021-01-11 10:32:05 WARNING (MainThread) [homeassistant.components.androidtv.media_player] Could not connect to AFTV 4K at amazon-4c8a85df4.lan:5555 using Python ADB implementation with adbkey='/config/adbkey'
2021-01-11 10:32:05 WARNING (MainThread) [homeassistant.components.media_player] Platform androidtv not ready yet. Retrying in 30 seconds.

AdbDeviceUsb not working with MacOS X due to error 'LIBUSB_ERROR_ACCESS [-3]'

Description

connect to an USB Android device on Mac OS X failed:

signer = PythonRSASigner(pub, priv)
d = AdbDeviceUsb(serial='f3ee4049') # or without serial parameter
d.connect(rsa_keys=[signer], auth_timeout_s=0.1)

Log

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.10/site-packages/adb_shell/adb_device.py", line 675, in connect
    self._available, self._maxdata = self._io_manager.connect(self._banner, rsa_keys, auth_timeout_s, auth_callback, adb_info)
  File "/usr/local/lib/python3.10/site-packages/adb_shell/adb_device.py", line 221, in connect
    self._transport.connect(adb_info.transport_timeout_s)
  File "/usr/local/lib/python3.10/site-packages/adb_shell/transport/usb_transport.py", line 242, in connect
    transport.detachKernelDriver(iface_number)
  File "/usr/local/lib/python3.10/site-packages/usb1/__init__.py", line 1199, in detachKernelDriver
    mayRaiseUSBError(
  File "/usr/local/lib/python3.10/site-packages/usb1/__init__.py", line 127, in mayRaiseUSBError
    __raiseUSBError(value)
  File "/usr/local/lib/python3.10/site-packages/usb1/__init__.py", line 119, in raiseUSBError
    raise __STATUS_TO_EXCEPTION_DICT.get(value, __USBError)(value)
usb1.USBErrorAccess: LIBUSB_ERROR_ACCESS [-3]

Using pull on BytesIO object

Due to this programs complexity, I'm struggling to subclass to use pull onto a BytesIO object rather than an actual file on my machine.

Is there any sort of implemented way I can do this that I'm missing in my reading of the docs?

Some parameters have changed from prev version

Hi there!
I had a piece of code that looked like this:

device.pull(some_path, dest_file=another_path)

And just want to know if the adb_shell version I was using was the previous, v0.2.1

(there is no real issue, I have just updated to the new version, and updated the code to:

 device.pull(some_path, another_path)

)

Another changed I have done is removing the default_timeout_s parameter in AdbDeviceTcp, because, althought it continues in the documentation, i got the Unexpected argument warning with:

device = AdbDeviceTcp(remote_ip, 5555, default_timeout_s=16.)

(that now I have updated to:

device = AdbDeviceTcp(remote_ip, 5555)

)
Thanks in advance ๐Ÿ˜„

Libusb error

I'm getting an error when trying to pull the the correct dll to use for libusb
This issue continues off of issue#117

Below is a snippet of the code along with the error it gives:

import os
import sys
os.add_dll_directory('C:\\Users\\Public\\Documents')

from adb_shell.transport.usb_transport import UsbTransport
from adb_shell.adb_device import AdbDeviceTcp, AdbDeviceUsb
from adb_shell.auth.sign_pythonrsa import PythonRSASigner

# Connect via USB (package must be installed via `pip install adb-shell[usb])`
transport = UsbTransport.find_adb()
print(transport)

with open('C:\\Users\\Public\\Documents\\adbkey') as f:
   priv = f.read()
signer = PythonRSASigner('', priv)

# NOTE: This next line is incorrect, see the note at the end of this post
device = AdbDeviceUsb(transport)
device.connect(rsa_keys=[signer], auth_timeout_s=0.1)

# Send a shell command
response3 = device.shell('echo TEST3')
Traceback (most recent call last):
  File "C:/Users/stefan.pompilio/PhoneTestingAdb/main.py", line 24, in <module>
    device = AdbDeviceUsb(transport)
  File "C:\Users\stefan.pompilio\PhoneTestingAdb\venv\lib\site-packages\adb_shell\adb_device.py", line 1205, in __init__
    transport = UsbTransport.find_adb(serial, port_path, default_transport_timeout_s)
  File "C:\Users\stefan.pompilio\PhoneTestingAdb\venv\lib\site-packages\adb_shell\transport\usb_transport.py", line 620, in find_adb
    return cls._find(
  File "C:\Users\stefan.pompilio\PhoneTestingAdb\venv\lib\site-packages\adb_shell\transport\usb_transport.py", line 507, in _find
    return cls._find_first(setting_matcher, device_matcher, usb_info=usb_info, default_transport_timeout_s=default_transport_timeout_s)
  File "C:\Users\stefan.pompilio\PhoneTestingAdb\venv\lib\site-packages\adb_shell\transport\usb_transport.py", line 597, in _find_first
    return next(cls._find_devices(setting_matcher, device_matcher=device_matcher, usb_info=usb_info, default_transport_timeout_s=default_transport_timeout_s))
  File "C:\Users\stefan.pompilio\PhoneTestingAdb\venv\lib\site-packages\adb_shell\transport\usb_transport.py", line 565, in _find_devices
    if device_matcher is None or device_matcher(transport):
  File "C:\Users\stefan.pompilio\PhoneTestingAdb\venv\lib\site-packages\adb_shell\transport\usb_transport.py", line 470, in <lambda>
    return lambda device: device.serial_number == serial
  File "C:\Users\stefan.pompilio\PhoneTestingAdb\venv\lib\site-packages\adb_shell\transport\usb_transport.py", line 410, in serial_number
    return self._device.getSerialNumber()
  File "C:\Users\stefan.pompilio\PhoneTestingAdb\venv\lib\site-packages\usb1\__init__.py", line 2136, in getSerialNumber
    return self.open().getSerialNumber()
  File "C:\Users\stefan.pompilio\PhoneTestingAdb\venv\lib\site-packages\usb1\__init__.py", line 2171, in open
    mayRaiseUSBError(libusb1.libusb_open(self.device_p, byref(handle)))
  File "C:\Users\stefan.pompilio\PhoneTestingAdb\venv\lib\site-packages\usb1\__init__.py", line 133, in mayRaiseUSBError
    __raiseUSBError(value)
  File "C:\Users\stefan.pompilio\PhoneTestingAdb\venv\lib\site-packages\usb1\__init__.py", line 125, in raiseUSBError
    raise __STATUS_TO_EXCEPTION_DICT.get(value, __USBError)(value)
usb1.USBErrorNotSupported: LIBUSB_ERROR_NOT_SUPPORTED [-12]

I've tried using zadig to upgrade the driver, but that hasn't worked. Any ideas are appreciated!

Note

The line

device = AdbDeviceUsb(transport)

above is incorrect. The first parameter to AdbDeviceUsb is the device serial number or None, not the transport object itself. See #118 (comment) for the correct way to instantiate an AdbDeviceUsb object.

adb server claims usb device: results in USBErrorBusy

Description

connect() fails with USBErrorBusy. Only way to get past this is to run "adb kill-server" and then quickly retry.
Looks like self._transport.claimInterface(self._interface_number) fails.

transport.kernelDriverActive(iface_number) returns false before this too.

This is using a Xiaomi phone plugged in to Ubuntu 20.

Looking in /sys/bus/usb/drivers/usb/1-1.2/1-1.2:1.0/ (my device) I see driver is:
driver -> ../../../../../../../bus/usb/drivers/usbfs/

Looks like the adb command line - used for "adb devices" for example, claims the device indefinitely.

Anyway around this anyone?

Unable to yield from a second AdbDevice.streaming_shell on the same AdbDevice

I have a routine looking for events. I'm mapping user input on the screen to a series of well-defined actions ("swipe left", etc.). I want a streaming_shell() for each gesture so I can delineate between them.

for g in gesture:
    print("record the {} gesture".format(g))
    gesture_stream = device.streaming_shell('getevent -t -q')
    while True:
        try:
            events = process_getevent(next(gesture_stream))
            # ... process events ...
        except adb_shell.exceptions.TcpTimeoutException:
            # Events have dried up and/or we timed out
            break

It goes through the first gesture just fine, but on the second gesture it errors at the next(). Here is the output:

Traceback (most recent call last):
  File "/home/ggallo/.pyenv/versions/3.9.1/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/ggallo/.pyenv/versions/3.9.1/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/ggallo/mytest.py", line 186, in <module>
    exit(main(sys.argv[1:]))
  File "/home/ggallo/mytest.py", line 177, in main
    record_gestures(device, ident, args.gestures)
  File "/home/ggallo/mytest.py", line 140, in record_gestures
    events = process_getevent(next(gesture_stream))
  File "/home/ggallo/venv/lib/python3.9/site-packages/adb_shell/adb_device.py", line 441, in streaming_shell
    for line in self._streaming_service(b'shell', command.encode('utf8'), transport_timeout_s, read_timeout_s, decode):
  File "/home/ggallo/venv/lib/python3.9/site-packages/adb_shell/adb_device.py", line 362, in _streaming_service
    for line in (stream_line.decode('utf8') for stream_line in stream):
  File "/home/ggallo/venv/lib/python3.9/site-packages/adb_shell/adb_device.py", line 362, in <genexpr>
    for line in (stream_line.decode('utf8') for stream_line in stream):
  File "/home/ggallo/venv/lib/python3.9/site-packages/adb_shell/adb_device.py", line 965, in _streaming_command
    for data in self._read_until_close(adb_info):
  File "/home/ggallo/venv/lib/python3.9/site-packages/adb_shell/adb_device.py", line 900, in _read_until_close
    cmd, data = self._read_until([constants.CLSE, constants.WRTE], adb_info)
  File "/home/ggallo/venv/lib/python3.9/site-packages/adb_shell/adb_device.py", line 870, in _read_until
    raise exceptions.InvalidResponseError('Incorrect remote id, expected {0} got {1}'.format(adb_info.remote_id, remote_id2))
adb_shell.exceptions.InvalidResponseError: Incorrect remote id, expected 177 got 176

I can open two non-streaming shells in a row and run commands without incident. Of course this won't work for my use case, because I'm waiting on input, but it's just to show that shell() doesn't have the same problem.

# adb_test.py
... other prep ...
d = AdbDeviceTcp(ip, port)
d.connect(rsa_keys=[signer])
print(d.shell('echo hello'))
print(d.shell('echo world'))

$ python adb_test.py 
hello

world

$

Is this intended behavior? Are we meant to close the entire TCP cxn and retry for each streaming shell? (This isn't asked to be snarky, I haven't done much serious shell-adjacent programming in some time and am very rusty.)

License and Copyright issue.

Abstract

Hello,

We are considering the idea to use adb_shell as a replacement for python-adb in our project, but I believe that adb_shell is in copyright and license infringement towards python-adb. This can be solved on our side, when adding adb_shell to our project, but it would be even better to do it on your side (for you and your future users).

Disclaimer: I am not a legal expert. I am just applying the license as I understand them and following other well-known projects' practices. My interpretation could be wrong.

License infringement: Apache license copy

Problem:

In the Apache license, point 4. (a):

You must give any other recipients of the Work or Derivative Works a copy of this License;

The repository contains code from python-adb (licensed under apache) and does not include a full copy of the apache license.

Solution:

Add a full copy of the apache license at the root of the project. Can be appended to the LICENSE file or a separate file, doesn't matter.

Exemple: https://github.com/renpy/renios/blob/5f01ce1bbb94c04193bf1bbcfb941c4d8563a98b/LICENSE.md

OR

Get an authorization from Google to re-license everything under MIT

Copyright infringement: missing google copyright notice

Problem

In the Apache license, point 4. (b):

You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works;

Unmodified files still includes the google copyright notice (ie: sign_cryptography.py) which is nice.

There is no obligation for files that only contains new works.

But files that includes both new and old works does not include a google copyright notice (ie: adb_device.py).

Solution

In files that includes work from python-adb:

  • Add the original copyright notice and license from python-adb

  • Add a new copyright notice or anything that could indicate that the file was modified

  • Possibly add an additional copyright statement and a license header for the additional work

exemple: https://github.com/LibreOffice/core/blob/master/TEMPLATE.SOURCECODE.HEADER

License infringment: Apache to MIT re-license

Problem

This repository includes work covered by MIT license and work covered by Apache license.
Some files includes work covered by MIT and work covered by Apache

The apache license has more restrictions than MIT:

You must cause any modified files to carry prominent notices stating that You changed the files;

And:

Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.

As a result a joint-work under Apache and MIT licenses โˆ’ And his is probably the only point where I am 100% sure โˆ’ can be automatically re-licensed under Apache, but cannot be re-licensed under MIT without the copyright holder's consent.

As a result: a file containing joint-work cannot be under MIT and the repository as a whole cannot be under MIT.

Solution

License everything under Apache

OR

Get an authorization from Google to re-license everything under MIT

OR

License the additional files under MIT and license the files that contains joint-work under Apache.
The repository would then contains files under different licenses or the repository as a whole could be under Apache.

OR

License old work under Apache and additional work under MIT even for joint-work in the same file. The joint-work will have part of its code under MIT and parts of his code under Apache. The repository as a whole could be under Apache or under both licenses.

Even if the repository is under Apache, any file or line of code that is under MIT, would still be usable under MIT if separated from the Apache code:

  • if we remove every line of code from google, the file/repository could be under MIT again.
  • if we copy some lines of code that only include additional work it could be under MIT as well.

Improvement: add contributors to copyright notice

Problem

This is probably not the most important change, but the copyright notice in the LICENSE file is:

Copyright (c) 2019 Jeff Irion

And the project does not include a Contributor License Agreement.

So the copyright holder for any line of code is the person that wrote that line. And the copyright holder for all the additional work (excluding google's work) is probably something like "Jeff Irion and contributor 1 and contributor 2 and ...". But since the contribution can be tracked by git, I don't think there is any infringement, it just more conventional to include contributors in the copyright notice. You can also list all contributors by name in the copyright notice or a separate file, but it's completely optional.

Solution

Change copyright notice to:

Copyright (c) 2019 Jeff Irion and contributors

OR

Add a Contributor License Agreement

Cannot catch adb_shell.exceptions.UsbDeviceNotFoundError

I'm having some trouble implementing graceful error handling for this particular exception.

My code currently looks like this:

import os
import usb1
import sys
import adb_shell.exceptions
from adb_shell.adb_device import AdbDeviceUsb
from adb_shell.auth.sign_pythonrsa import PythonRSASigner

home = os.path.expanduser("~")
adbkey = home + "/.android/adbkey"

with open(adbkey) as f:
    priv = f.read()
with open(adbkey + '.pub') as f:
    pub = f.read()
signer = PythonRSASigner(pub, priv)

"""Need to kill adb server if it's running"""
device = AdbDeviceUsb()
try:
    device.connect(rsa_keys=[signer], auth_timeout_s=0.1)
except exceptions.UsbDeviceNotFoundError:
    print("Error, device not found")
    sys.exit(1)
except usb1.USBErrorBusy:
    os.system('adb kill-server')
    device.connect(rsa_keys=[signer], auth_timeout_s=0.1)
finally:
    print("Successfully connected to device.")

I figured out that I needed to import usb1 to catch the USBErrorBusy, and that part works. But I'm not having any luck catching the USBDeviceNotFoundError. I noticed that it gets raised from within a try except block that catches an exception called StopIteration, so I tried to catch that one, which failed because it's already being handled by your code. I have tried various ways of importing the class, the module, etc and can't figure out how to address this error.

I have tried:

import adb_shell
...
except adb_shell.exceptions.USBDeviceNotFoundError:

import adb_shell.exceptions
...
except exceptions.USBDeviceNotFoundError:

from adb_shell.exceptions import USBDeviceNotFoundError:
...
except USBDeviceNotFoundError:

import adb_shell
...
except adb_shell.exceptions.Exception:
except adb_shell.Exception:

I even experimentally tried the ill-advised:

except Exception:
    pass

And the exception goes uncaught. I assume that I could modify the code, remove your try/except block and catch the StopIteration myself and that would probably work, but I'm not familiar enough with the underlying structure to know if this is a good idea or not. And as StopIteration is not very descriptive of the problem in that situation, I agree with your idea of trying to raise a more descriptive exception.

Any ideas?

usb1.USBErrorAccess: LIBUSB_ERROR_ACCESS [-3]

My operating system is windows and my python version is 3.11

    with open(adbkey) as f:
        priv = f.read()
    with open(adbkey + '.pub') as f:
        pub = f.read()
    signer = PythonRSASigner(pub, priv)

    device1 = AdbDeviceUsb(serial='1234567')
    device1.connect(rsa_keys=[signer])

I tried to connect to a device via USB by my python code but failed.

Traceback (most recent call last):
  File "C:\Users\xzp9097\Desktop\adb_operate\adb_test.py", line 58, in <module>
    ao.connect()
  File "C:\Users\xzp9097\Desktop\adb_operate\adb_test.py", line 21, in connect
    self.device.connect()
  File "C:\Users\xzp9097\Desktop\adb_operate\venv\Lib\site-packages\adb_shell\adb_device.py", line 675, in connect
    self._available, self._maxdata = self._io_manager.connect(self._banner, rsa_keys, auth_timeout_s, auth_callback, adb_info)
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xzp9097\Desktop\adb_operate\venv\Lib\site-packages\adb_shell\adb_device.py", line 221, in connect
    self._transport.connect(adb_info.transport_timeout_s)
  File "C:\Users\xzp9097\Desktop\adb_operate\venv\Lib\site-packages\adb_shell\transport\usb_transport.py", line 238, in connect
    transport = self._device.open()
                ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xzp9097\Desktop\adb_operate\venv\Lib\site-packages\usb1\__init__.py", line 2055, in open
    mayRaiseUSBError(libusb1.libusb_open(self.device_p, byref(handle)))
  File "C:\Users\xzp9097\Desktop\adb_operate\venv\Lib\site-packages\usb1\__init__.py", line 127, in mayRaiseUSBError
    __raiseUSBError(value)
  File "C:\Users\xzp9097\Desktop\adb_operate\venv\Lib\site-packages\usb1\__init__.py", line 119, in raiseUSBError
    raise __STATUS_TO_EXCEPTION_DICT.get(value, __USBError)(value)
usb1.USBErrorAccess: LIBUSB_ERROR_ACCESS [-3]

Then I reboot the system and try running the code again. It connected successed.
I found out that if I use CMD to connect the device first, and then execute my code it would raise the error, unless reboot the system.
How can I modify my code to solve this problem?
Thanks a lot

USB transport not working

Description

I'm having a bit of trouble with your adb shell for python.

Despite installing using the 'pip install adb-shell[usb]' command, I am getting the transport error and it's telling me to install the package in the same way.

Do you have any idea what's wrong?

Log

No logs available

adb_shell.exceptions.InvalidCommandError in `connect()` with Android emulator

Hello, Jeff, i need help)
When i running my code:

from adb_shell import adb_device
from adb_shell.auth.sign_pythonrsa import PythonRSASigner
import os


class Controller:
    def __init__(self, host: str, port: int):
        self.host, self.port = host, port
        self.device, self._signer = None, None

    def connect_to_device(self, timeout: int):
        self.device = adb_device.AdbDeviceTcp(self.host, self.port, default_timeout_s=timeout)
        self._make_sign("~/.android/adbkey")
        self.device.connect(auth_timeout_s=0.1, rsa_keys=[self._signer])

    def _make_sign(self, path: str):
        with open(os.path.expanduser(path)) as file:
            rsa_key = file.read()
        self._signer = PythonRSASigner("", rsa_key)

    def shell(self, command: str) -> str:
        output = self.device.shell(command, decode=True)
        return output


if __name__ == '__main__':
    adb_controller = Controller("localhost", 5556)
    adb_controller.connect_to_device(timeout=10)
    print(adb_controller.shell("echo work!"))

An emulator is running on 5556 port.
I get an error adb_shell.exceptions.InvalidCommandError: ('Unknown command: 72646e41', 1919184449, (543451503, 1936617283)) or something like this, I would like to know why this is happening.

rsa in java

Hi, I read the rsa sign code, it is special. How can I use ras in java. Thank you!

Shell command arguments not executed

Description

I tried to execute ls in shell(), then it executes, but when I try to execute ls /bin it executes only ls without /bin argument.

Log

From python3 adb_shell

device1.shell('ls')

output:

Reserve0   default.prop                init.usb.rc      sdcard     
acct       dev                         init.zygote32.rc storage    
bin        etc                         lost+found       sys        
bugreports file_contexts.bin           mnt              system     
cache      init                        odm              tmp-mksh   
charger    init.environ.rc             oem              ueventd.rc 
config     init.rc                     proc             vendor     
d          init.recovery.sun50iw6p1.rc product          verity_key 
data       init.usb.configfs.rc        sbin         

with /bin:

device1.shell('ls /bin')

output:

Reserve0   default.prop                init.usb.rc      sdcard     
acct       dev                         init.zygote32.rc storage    
bin        etc                         lost+found       sys        
bugreports file_contexts.bin           mnt              system     
cache      init                        odm              tmp-mksh   
charger    init.environ.rc             oem              ueventd.rc 
config     init.rc                     proc             vendor     
d          init.recovery.sun50iw6p1.rc product          verity_key 
data       init.usb.configfs.rc        sbin 

NOTE: But if use generic adb from android-platform-tools then ls /bin executes as ls /bin, but not as ls

P.S.: If you try to execute touch somefile, shell() will execute only touch and then the error appears:

touch: Needs 1 argument (see "touch --help")

raw option to device::shell response

Hi,
I'm using this library to take a screenshot with the command /system/bin/screencap -p. Currently, saving the screenshot fails because the shell function always decodes adb's response

I made a small change to optionally skip the decoding part, the commit is here. All tests still pass, so this shouldn't be a breaking change.

To reproduce the current error, do something like:

from adb_shell.adb_device import AdbDeviceTcp
device = AdbDeviceTcp(ip, port)
response = device.shell('/system/bin/screencap -p')
with open("out.png", "bw") as f:
    f.write(response)

This should throw a UnicodeDecodeError. With my change, the only difference would be response = device.shell('/system/bin/screencap -p', raw=True).

May I open a PR?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.