def _connect(self, tries: int = 1) -> AdbClient:
     try:
         client = AdbClient(host=self.host, port=self.port)
         client.version()
         return client
     except RuntimeError as e:
         if isinstance(e.__context__, ConnectionRefusedError) and tries > 0:
             os.system('adb start-server')
             return self._connect(tries - 1)
         else:
             raise e
def get_devices():
    for attempt in range(2):
        try:
            client = AdbClient(host="127.0.0.1", port=5037)
            client.version()  # a random call to check if adb server is up
        except Exception as err:
            eprint(str(err))
            eprint("⚡ Starting ADB server...")
            subprocess.run(["adb", "start-server"])

    devices = client.devices()
    if len(devices) == 0:
        eprint("⚠️  no devices connected!")
    return devices
Example #3
0
 def __init__(self):
     self.log = MyLogger('ADB', LOG_LEVEL=logging.INFO)
     client = Client(host='127.0.0.1', port=5037)
     self.log.debug(client.version())
     devices = client.devices()
     if len(devices) == 0:
         self.log.debug("no devices")
         quit()
     self.device = devices[0]
     self.log.debug(f'updating info for {self.device}')
     number = 5
     touch_id = 0
     lines = self.device.shell('getevent -p').split("\n")
     for line in lines:
         if "/dev/input" in line:
             number = line[-1]
         if "Touch" in line:
             touch_id = number
             self.touch = f"sendevent /dev/input/event{number}"
         if "max" in line and "ABS" in line and number == touch_id:
             values = line.split(', ')
             for value in values:
                 if "max" in value:
                     self.max = int(value[4:])
                     self.log.debug(f"found max: {self.max}")
Example #4
0
 def connectServer(self):
     """
         Method to establish a connection between smartphone and computer.
     """
     client = AdbClient(host=self.host, port=self.port)
     if client :
         print("Client version :", client.version())
         return client
     else:
         print("Problem to connect adb Server, please verify your port or host")
Example #5
0
def conecta_android():
    client = AdbClient(host="127.0.0.1", port=5037)
    print(client.version())
    os.system('adb kill-server')
    sleep(1)
    os.system('adb usb')
    sleep(1)
    os.system('adb devices')
    sleep(1)
    os.system('adb tcpip 5556')
    sleep(1)
    os.system('adb connect "192.168.0.11:5556"')
    sleep(1)
    device = client.device("192.168.0.11:5556")
    device.shell("echo hello world !")
    return device
Example #6
0
def client(request):
    logger.info("Connecting to adb server {}:{}...".format(adb_host, adb_port))
    client = AdbClient(host=adb_host, port=adb_port)

    def try_to_connect_to_adb_server():
        try:
            client.version()
            return True
        except Exception:
            return False

    wait_until_true(try_to_connect_to_adb_server,
                    timeout=60,
                    description="Try to connect to adb server {}:{}".format(
                        adb_host, adb_port))

    logger.info("Adb server version: {}".format(client.version()))

    return client