Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout shell commands after gaining root on device #231

Open
nurpabuccu opened this issue Dec 22, 2023 · 0 comments
Open

Timeout shell commands after gaining root on device #231

nurpabuccu opened this issue Dec 22, 2023 · 0 comments

Comments

@nurpabuccu
Copy link

nurpabuccu commented Dec 22, 2023

Description

I am connecting my android device in docker container with AdbDeviceTcp. I want to gain root privileges and tried this:

android_device.root(timeout_s=10)

But whenever i try to use root, commands after it not execute it will give:

Timeout: read 0 of 24 bytes (transport_timeout_s = 10.0, read_timeout_s = 10.0)

my code:

android_device = AdbDeviceTcp("0.0.0.0", adb_port)
try:
    if not android_device.connect(auth_timeout_s=1, transport_timeout_s=3):
        raise Exception("Adb connection failed")
    print("available 1:",android_device.available)
    res = android_device.streaming_shell("echo TEST1")
    print(list(res))
    print(android_device.root(timeout_s=10))
    print("available 2:",android_device.available)
    res = android_device.streaming_shell("echo TEST2")
    print(list(res))
except Exception as e:
    print(e)

output:

available 1: True
['TEST1\n']
None
available 2: True
Traceback (most recent call last):
  File "/home/ubuntu/test/main.py", line 100, in main
    start_submission(args.sample, args.config)
  File "/home/ubuntu/test/main.py", line 50, in start_submission
    print(list(res))
  File "/home/ubuntu/.local/lib/python3.10/site-packages/adb_shell/adb_device.py", line 868, in streaming_shell
    for line in self._streaming_service(b'shell', command.encode('utf8'), transport_timeout_s, read_timeout_s, decode):
  File "/home/ubuntu/.local/lib/python3.10/site-packages/adb_shell/adb_device.py", line 738, in _streaming_service
    for line in (stream_line.decode('utf8', _DECODE_ERRORS) for stream_line in stream):
  File "/home/ubuntu/.local/lib/python3.10/site-packages/adb_shell/adb_device.py", line 738, in <genexpr>
    for line in (stream_line.decode('utf8', _DECODE_ERRORS) for stream_line in stream):
  File "/home/ubuntu/.local/lib/python3.10/site-packages/adb_shell/adb_device.py", line 1288, in _streaming_command
    adb_info = self._open(b'%s:%s' % (service, command), transport_timeout_s, read_timeout_s, timeout_s)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/adb_shell/adb_device.py", line 1186, in _open
    _, adb_info.remote_id, _, _ = self._io_manager.read([constants.OKAY], adb_info)
  File "/home/ubuntu/.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/ubuntu/.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/ubuntu/.local/lib/python3.10/site-packages/adb_shell/adb_device.py", line 455, in _read_bytes_from_device
    raise exceptions.AdbTimeoutError("Timeout: read {} of {} bytes (transport_timeout_s = {}, read_timeout_s = {})".format(len(data), len(data) + length, adb_info.transport_timeout_s, adb_info.read_timeout_s))
adb_shell.exceptions.AdbTimeoutError: Timeout: read 0 of 24 bytes (transport_timeout_s = 10.0, read_timeout_s = 10.0)

If I run the script second time it works:

available 1: True
['TEST1\n']
None
available 2: True
['TEST2\n']

What can be the reason? I need to fix this problem quickly.
My host adb is not connected to device during tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant