def devices()

in ioXt/uraniborg/scripts/python/syscall_wrapper.py [0:0]


  def devices(logger=None):
    """Calls 'adb devices -l' to list connected devices via ADB.

    Args:
      logger: An optional logger object used for logging.

    Returns:
      A list of DeviceInfo containing all connected devices.
      <code>None</code> is returned if error occurs.
    """
    if not logger:
      logger = AdbWrapper.set_up_default_logger()
    cmd = AdbWrapper.BASE_ADB_COMMAND[:]
    cmd.extend(["devices", "-l"])
    logger.debug("cmd: %s", cmd)
    sw = SyscallWrapper(logger)
    sw.call_returnable_command(cmd)
    if sw.error_occured:
      logger.error("Failure: %s", sw.error_final)
      return None

    if len(sw.result_final) < 2:
      logger.warning("No devices connected!")
      return []

    connected_devices = []
    for line in sw.result_final[1:]:
      logger.debug("line: %s", line)

      device = DeviceInfo()
      line_components = line.split()
      device.serial_number = line_components[0]

      if "unauthorized" in line:
        logger.warning("ADB has not been authorized for device with serial "
                       "number %s", device.serial_number)
        device.unauthorized = True
        connected_devices.append(device)
        continue

      for component in line_components:
        if component.find("product:") == 0:
          device.product_name = component.split(":")[1].strip()
        elif component.find("model:") == 0:
          device.model_name = component.split(":")[1].strip()
        elif component.find("device:") == 0:
          device.device_name = component.split(":")[1].strip()
        elif component.find("transport_id:") == 0:
          device.transport_id = component.split(":")[1].strip()
      connected_devices.append(device)

    return connected_devices