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

[Feature request] Provides the usb-device-to-tcp function #114

Open
codematrixer opened this issue Apr 30, 2024 · 4 comments
Open

[Feature request] Provides the usb-device-to-tcp function #114

codematrixer opened this issue Apr 30, 2024 · 4 comments

Comments

@codematrixer
Copy link

adbkit provides a powerful feature: usb-device-to-tcp. Execute the following command to use it
node node_modules/adbkit/bin/adbkit usb-device-to-tcp -p ${PORT} ${SERIAL}
However, due to the complexity of the Node.js environment and its version requirements, it's difficult to maintain.

Is it possible to implement this feature in adbutils?

@codeskyblue
Copy link
Member

Sure it is possible to do it

@codeskyblue
Copy link
Member

The adbutils need make some update to support asyncio

@chaooe
Copy link

chaooe commented May 10, 2024

i am also waiting for this feature. and i also like the adbkit provide by you.

@chaooe
Copy link

chaooe commented May 11, 2024

a simple way that using the exist installed adbkit and can be only used one device connected.

from adbutils import adb
import os
import subprocess

global connected_device
connected_device =[]
# 监控设备连接 track-devices
os.system("adb start-server")
while True:
    try:
        for event in adb.track_devices():
            if "emulator" in event.serial or "0123456789ABCDEF" in event.serial:
                continue
            print(event.present, event.serial, event.status)
            if event.status == 'device':
                connected_device.append(event.serial)
                cmd = 'adbkit usb-device-to-tcp -p 5555 {}'.format(event.serial)
                p = subprocess.Popen(cmd, shell=True)
                print(f"set the device {event.serial} to tcp port 5555")
            if event.serial in connected_device and event.status !="device":
                connected_device.remove(event.serial)
                if p is not None:
                    p.terminate()
                    p = None
                print(f"set the device {event.serial} is offline")
    except InterruptedError:
        break
    except Exception as e:
        print(f'adb killed server:{e}')
        if connected_device !=[]:
            connected_device=[]
        if p is not None:
            p.terminate()
            p = None
        os.system("adb start-server")
    finally:
        if p is not None:
            p.terminate()
            p = None
        os.system("adb start-server")

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

3 participants