Beispiel #1
0
def GetDevices(banner,
               default_timeout_ms,
               auth_timeout_ms,
               on_error=None,
               as_root=False):
    """Returns the list of devices available.

  Caller MUST call CloseDevices(devices) on the return value or call .Close() on
  each element to close the USB handles.

  Arguments:
  - banner: authentication banner associated with the RSA keys. It's better to
        use a constant.
  - default_timeout_ms: default I/O operation timeout.
  - auth_timeout_ms: timeout for the user to accept the public key.
  - on_error: callback when an internal failure occurs.
  - as_root: if True, restarts adbd as root if possible.

  Returns one of:
    - list of HighDevice instances.
    - None if adb is unavailable.
  """
    with _ADB_KEYS_LOCK:
        if not _ADB_KEYS:
            return []
    # List of unopened common.UsbHandle.
    handles = list(
        common.UsbHandle.FindDevicesSafe(adb_commands_safe.DeviceIsAvailable,
                                         timeout_ms=default_timeout_ms))

    def fn(handle):
        device = HighDevice.Connect(handle,
                                    banner=banner,
                                    default_timeout_ms=default_timeout_ms,
                                    auth_timeout_ms=auth_timeout_ms,
                                    on_error=on_error)
        if as_root and device.cache.has_su and not device.IsRoot():
            # This updates the port path of the device thus clears its cache.
            device.Root()
        return device

    devices = parallel.pmap(fn, handles)
    _PER_DEVICE_CACHE.trim(devices)
    return devices
Beispiel #2
0
def GetDevices(
    banner, default_timeout_ms, auth_timeout_ms, on_error=None, as_root=False):
  """Returns the list of devices available.

  Caller MUST call CloseDevices(devices) on the return value or call .Close() on
  each element to close the USB handles.

  Arguments:
  - banner: authentication banner associated with the RSA keys. It's better to
        use a constant.
  - default_timeout_ms: default I/O operation timeout.
  - auth_timeout_ms: timeout for the user to accept the public key.
  - on_error: callback when an internal failure occurs.
  - as_root: if True, restarts adbd as root if possible.

  Returns one of:
    - list of HighDevice instances.
    - None if adb is unavailable.
  """
  with _ADB_KEYS_LOCK:
    if not _ADB_KEYS:
      return []
  # List of unopened common.UsbHandle.
  handles = list(
      common.UsbHandle.FindDevicesSafe(
          adb_commands_safe.DeviceIsAvailable, timeout_ms=default_timeout_ms))

  def fn(handle):
    device = HighDevice.Connect(
        handle, banner=banner, default_timeout_ms=default_timeout_ms,
        auth_timeout_ms=auth_timeout_ms, on_error=on_error)
    if as_root and device.cache.has_su and not device.IsRoot():
      # This updates the port path of the device thus clears its cache.
      device.Root()
    return device

  devices = parallel.pmap(fn, handles)
  _PER_DEVICE_CACHE.trim(devices)
  return devices
Beispiel #3
0
 def test_junk(self):
   parallel._QUEUE_OUT.put(0)
   self.assertEqual([1, 2], parallel.pmap(lambda x: x+1, [0, 1]))
   self.assertEqual(0, parallel._QUEUE_OUT.qsize())
Beispiel #4
0
 def test_locked(self):
   with parallel._POOL_LOCK:
     self.assertEqual([1, 2], parallel.pmap(lambda x: x+1, [0, 1]))
Beispiel #5
0
 def test_throw_2(self):
   def fn(_):
     raise Foo()
   with self.assertRaises(Foo):
     parallel.pmap(fn, [0, 1])
Beispiel #6
0
 def test_2(self):
   self.assertEqual([1, 2], parallel.pmap(lambda x: x+1, [0, 1]))
Beispiel #7
0
 def test_1(self):
   self.assertEqual([1], parallel.pmap(lambda x: x+1, [0]))
Beispiel #8
0
 def test_0(self):
   self.assertEqual([], parallel.pmap(self.fail, []))
Beispiel #9
0
 def test_junk(self):
     parallel._QUEUE_OUT.put(0)
     self.assertEqual([1, 2], parallel.pmap(lambda x: x + 1, [0, 1]))
     self.assertEqual(0, parallel._QUEUE_OUT.qsize())
Beispiel #10
0
 def test_locked(self):
     with parallel._POOL_LOCK:
         self.assertEqual([1, 2], parallel.pmap(lambda x: x + 1, [0, 1]))
Beispiel #11
0
    def test_throw_2(self):
        def fn(_):
            raise Foo()

        with self.assertRaises(Foo):
            parallel.pmap(fn, [0, 1])
Beispiel #12
0
 def test_2(self):
     self.assertEqual([1, 2], parallel.pmap(lambda x: x + 1, [0, 1]))
Beispiel #13
0
 def test_1(self):
     self.assertEqual([1], parallel.pmap(lambda x: x + 1, [0]))
Beispiel #14
0
 def test_0(self):
     self.assertEqual([], parallel.pmap(self.fail, []))