Beispiel #1
0
def DroidConnectByHWID(hwid, timeout=30, **kwargs):
  """Try to connect to the given device by waiting for it to show up using mDNS with the given timeout."""

  import re
  if re.match('[0-9]+.[0-9]+.[0-9]+.[0-9]+', hwid):
    print "Connected via SUT to %s" % (hwid)
    return DroidSUT(hwid, **kwargs)

  nt = NetworkTools()
  local_ip = nt.getLanIp()

  zc = Zeroconf(local_ip)

  evt = threading.Event()
  listener = ZeroconfListener(hwid, evt)
  sb = ServiceBrowser(zc, "_sutagent._tcp.local.", listener)
  foundIP = None
  if evt.wait(timeout):
    # we found the hwid 
    foundIP = listener.ip
    sb.cancel()
    zc.close()

  if foundIP is not None:
    return DroidSUT(foundIP, **kwargs)
    print "Connected via SUT to %s [at %s]" % (hwid, foundIP)

  # try connecting via adb
  try:
    sut = DroidADB(deviceSerial=hwid, **kwargs)
  except:
    return None

  print "Connected via ADB to %s" % (hwid)
  return sut
Beispiel #2
0
def DroidConnectByHWID(hwid, timeout=30, **kwargs):
    """Try to connect to the given device by waiting for it to show up using mDNS with the given timeout."""
    zc = Zeroconf(moznetwork.get_ip())

    evt = threading.Event()
    listener = ZeroconfListener(hwid, evt)
    sb = ServiceBrowser(zc, "_sutagent._tcp.local.", listener)
    foundIP = None
    if evt.wait(timeout):
        # we found the hwid
        foundIP = listener.ip
    sb.cancel()
    zc.close()

    if foundIP is not None:
        return DroidSUT(foundIP, **kwargs)
    print "Connected via SUT to %s [at %s]" % (hwid, foundIP)

    # try connecting via adb
    try:
        sut = DroidADB(deviceSerial=hwid, **kwargs)
    except:
        return None

    print "Connected via ADB to %s" % (hwid)
    return sut