OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """ | 5 """ |
6 Provides a variety of device interactions based on adb. | 6 Provides a variety of device interactions based on adb. |
7 | 7 |
8 Eventually, this will be based on adb_wrapper. | 8 Eventually, this will be based on adb_wrapper. |
9 """ | 9 """ |
10 | 10 |
| 11 import multiprocessing |
11 import pylib.android_commands | 12 import pylib.android_commands |
12 from pylib.device import adb_wrapper | 13 from pylib.device import adb_wrapper |
13 | 14 |
14 | 15 |
15 def GetAVDs(): | 16 def GetAVDs(): |
16 return pylib.android_commands.GetAVDs() | 17 return pylib.android_commands.GetAVDs() |
17 | 18 |
18 | 19 |
| 20 # multiprocessing map_async requires a top-level function for pickle library. |
| 21 def RebootDeviceSafe(device): |
| 22 """Reboot a device, wait for it to start, and squelch timeout exceptions.""" |
| 23 try: |
| 24 DeviceUtils(device).old_interface.Reboot(True) |
| 25 except Exception as e: |
| 26 return e |
| 27 |
| 28 |
| 29 def RebootDevices(): |
| 30 """Reboot all attached and online devices.""" |
| 31 devices = pylib.android_commands.GetAttachedDevices() |
| 32 print 'Rebooting: %s' % devices |
| 33 if devices: |
| 34 pool = multiprocessing.Pool(len(devices)) |
| 35 results = pool.map_async(RebootDeviceSafe, devices).get(99999) |
| 36 |
| 37 for device, result in zip(devices, results): |
| 38 if result: |
| 39 print '%s failed to startup.' % device |
| 40 |
| 41 if any(results): |
| 42 print 'RebootDevices() Warning: %s' % results |
| 43 else: |
| 44 print 'Reboots complete.' |
| 45 |
| 46 |
19 class DeviceUtils(object): | 47 class DeviceUtils(object): |
20 | 48 |
21 def __init__(self, device): | 49 def __init__(self, device): |
22 self.old_interface = None | 50 self.old_interface = None |
23 if isinstance(device, basestring): | 51 if isinstance(device, basestring): |
24 self.old_interface = pylib.android_commands.AndroidCommands(device) | 52 self.old_interface = pylib.android_commands.AndroidCommands(device) |
25 elif isinstance(device, adb_wrapper.AdbWrapper): | 53 elif isinstance(device, adb_wrapper.AdbWrapper): |
26 self.old_interface = pylib.android_commands.AndroidCommands(str(device)) | 54 self.old_interface = pylib.android_commands.AndroidCommands(str(device)) |
27 elif isinstance(device, pylib.android_commands.AndroidCommands): | 55 elif isinstance(device, pylib.android_commands.AndroidCommands): |
28 self.old_interface = device | 56 self.old_interface = device |
29 elif not device: | 57 elif not device: |
30 self.old_interface = pylib.android_commands.AndroidCommands() | 58 self.old_interface = pylib.android_commands.AndroidCommands() |
31 | 59 |
OLD | NEW |