Coder Social home page Coder Social logo

Comments (4)

codeskyblue avatar codeskyblue commented on June 16, 2024

Sure it is possible to do it

from adbutils.

codeskyblue avatar codeskyblue commented on June 16, 2024

The adbutils need make some update to support asyncio

from adbutils.

chaooe avatar chaooe commented on June 16, 2024

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

from adbutils.

chaooe avatar chaooe commented on June 16, 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")

from adbutils.

Related Issues (20)

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.