| 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 """Provides a variety of device interactions based on adb. | 5 """Provides a variety of device interactions based on adb. |
| 6 | 6 |
| 7 Eventually, this will be based on adb_wrapper. | 7 Eventually, this will be based on adb_wrapper. |
| 8 """ | 8 """ |
| 9 # pylint: disable=unused-argument | 9 # pylint: disable=unused-argument |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 import zipfile | 23 import zipfile |
| 24 | 24 |
| 25 import pylib.android_commands | 25 import pylib.android_commands |
| 26 from pylib import cmd_helper | 26 from pylib import cmd_helper |
| 27 from pylib import constants | 27 from pylib import constants |
| 28 from pylib import device_signal | 28 from pylib import device_signal |
| 29 from pylib.device import adb_wrapper | 29 from pylib.device import adb_wrapper |
| 30 from pylib.device import decorators | 30 from pylib.device import decorators |
| 31 from pylib.device import device_blacklist | 31 from pylib.device import device_blacklist |
| 32 from pylib.device import device_errors | 32 from pylib.device import device_errors |
| 33 from pylib.device import device_filter | |
| 34 from pylib.device import intent | 33 from pylib.device import intent |
| 35 from pylib.device import logcat_monitor | 34 from pylib.device import logcat_monitor |
| 36 from pylib.device.commands import install_commands | 35 from pylib.device.commands import install_commands |
| 37 from pylib.utils import apk_helper | 36 from pylib.utils import apk_helper |
| 38 from pylib.utils import base_error | 37 from pylib.utils import base_error |
| 39 from pylib.utils import device_temp_file | 38 from pylib.utils import device_temp_file |
| 40 from pylib.utils import host_utils | 39 from pylib.utils import host_utils |
| 41 from pylib.utils import md5sum | 40 from pylib.utils import md5sum |
| 42 from pylib.utils import parallelizer | 41 from pylib.utils import parallelizer |
| 43 from pylib.utils import timeout_retry | 42 from pylib.utils import timeout_retry |
| (...skipping 1491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1535 host_pie_path = os.path.join(constants.GetOutDirectory(), 'run_pie') | 1534 host_pie_path = os.path.join(constants.GetOutDirectory(), 'run_pie') |
| 1536 if not os.path.exists(host_pie_path): | 1535 if not os.path.exists(host_pie_path): |
| 1537 raise device_errors.CommandFailedError('Please build run_pie') | 1536 raise device_errors.CommandFailedError('Please build run_pie') |
| 1538 pie = '%s/run_pie' % constants.TEST_EXECUTABLE_DIR | 1537 pie = '%s/run_pie' % constants.TEST_EXECUTABLE_DIR |
| 1539 self.adb.Push(host_pie_path, pie) | 1538 self.adb.Push(host_pie_path, pie) |
| 1540 | 1539 |
| 1541 self._cache['run_pie'] = pie | 1540 self._cache['run_pie'] = pie |
| 1542 | 1541 |
| 1543 return self._cache['run_pie'] | 1542 return self._cache['run_pie'] |
| 1544 | 1543 |
| 1544 def GetClientCache(self, client_name): |
| 1545 """Returns client cache.""" |
| 1546 if client_name not in self._client_caches: |
| 1547 self._client_caches[client_name] = {} |
| 1548 return self._client_caches[client_name] |
| 1549 |
| 1550 def _ClearCache(self): |
| 1551 """Clears all caches.""" |
| 1552 for client in self._client_caches: |
| 1553 self._client_caches[client].clear() |
| 1554 self._cache.clear() |
| 1555 |
| 1545 @classmethod | 1556 @classmethod |
| 1546 def parallel(cls, devices=None, async=False): | 1557 def parallel(cls, devices=None, async=False): |
| 1547 """Creates a Parallelizer to operate over the provided list of devices. | 1558 """Creates a Parallelizer to operate over the provided list of devices. |
| 1548 | 1559 |
| 1549 If |devices| is either |None| or an empty list, the Parallelizer will | 1560 If |devices| is either |None| or an empty list, the Parallelizer will |
| 1550 operate over all attached devices that have not been blacklisted. | 1561 operate over all attached devices that have not been blacklisted. |
| 1551 | 1562 |
| 1552 Args: | 1563 Args: |
| 1553 devices: A list of either DeviceUtils instances or objects from | 1564 devices: A list of either DeviceUtils instances or objects from |
| 1554 from which DeviceUtils instances can be constructed. If None, | 1565 from which DeviceUtils instances can be constructed. If None, |
| 1555 all attached devices will be used. | 1566 all attached devices will be used. |
| 1556 async: If true, returns a Parallelizer that runs operations | 1567 async: If true, returns a Parallelizer that runs operations |
| 1557 asynchronously. | 1568 asynchronously. |
| 1558 | 1569 |
| 1559 Returns: | 1570 Returns: |
| 1560 A Parallelizer operating over |devices|. | 1571 A Parallelizer operating over |devices|. |
| 1561 """ | 1572 """ |
| 1562 if not devices: | 1573 if not devices: |
| 1563 devices = adb_wrapper.AdbWrapper.Devices( | 1574 devices = cls.HealthyDevices() |
| 1564 filters=device_filter.DefaultFilters()) | |
| 1565 if not devices: | 1575 if not devices: |
| 1566 raise device_errors.NoDevicesError() | 1576 raise device_errors.NoDevicesError() |
| 1567 | 1577 |
| 1568 devices = [d if isinstance(d, cls) else cls(d) for d in devices] | 1578 devices = [d if isinstance(d, cls) else cls(d) for d in devices] |
| 1569 if async: | 1579 if async: |
| 1570 return parallelizer.Parallelizer(devices) | 1580 return parallelizer.Parallelizer(devices) |
| 1571 else: | 1581 else: |
| 1572 return parallelizer.SyncParallelizer(devices) | 1582 return parallelizer.SyncParallelizer(devices) |
| 1573 | 1583 |
| 1574 def GetClientCache(self, client_name): | 1584 @classmethod |
| 1575 """Returns client cache.""" | 1585 def HealthyDevices(cls): |
| 1576 if client_name not in self._client_caches: | 1586 blacklist = device_blacklist.ReadBlacklist() |
| 1577 self._client_caches[client_name] = {} | 1587 def blacklisted(adb): |
| 1578 return self._client_caches[client_name] | 1588 if adb.GetDeviceSerial() in blacklist: |
| 1589 logging.warning('Device %s is blacklisted.', adb.GetDeviceSerial()) |
| 1590 return True |
| 1591 return False |
| 1579 | 1592 |
| 1580 def _ClearCache(self): | 1593 return [cls(adb) for adb in adb_wrapper.AdbWrapper.Devices() |
| 1581 """Clears all caches.""" | 1594 if not blacklisted(adb)] |
| 1582 for client in self._client_caches: | 1595 |
| 1583 self._client_caches[client].clear() | |
| 1584 self._cache.clear() | |
| OLD | NEW |