| 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 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 def _GetChangedFilesImpl(self, host_path, device_path): | 846 def _GetChangedFilesImpl(self, host_path, device_path): |
| 848 real_host_path = os.path.realpath(host_path) | 847 real_host_path = os.path.realpath(host_path) |
| 849 try: | 848 try: |
| 850 real_device_path = self.RunShellCommand( | 849 real_device_path = self.RunShellCommand( |
| 851 ['realpath', device_path], single_line=True, check_return=True) | 850 ['realpath', device_path], single_line=True, check_return=True) |
| 852 except device_errors.CommandFailedError: | 851 except device_errors.CommandFailedError: |
| 853 real_device_path = None | 852 real_device_path = None |
| 854 if not real_device_path: | 853 if not real_device_path: |
| 855 return [(host_path, device_path)] | 854 return [(host_path, device_path)] |
| 856 | 855 |
| 857 host_hash_tuples = md5sum.CalculateHostMd5Sums([real_host_path]) | 856 host_checksums = md5sum.CalculateHostMd5Sums([real_host_path]) |
| 858 device_paths_to_md5 = ( | 857 device_paths_to_md5 = ( |
| 859 real_device_path if os.path.isfile(real_host_path) | 858 real_device_path if os.path.isfile(real_host_path) |
| 860 else ('%s/%s' % (real_device_path, os.path.relpath(p, real_host_path)) | 859 else ('%s/%s' % (real_device_path, os.path.relpath(p, real_host_path)) |
| 861 for _, p in host_hash_tuples)) | 860 for p in host_checksums.iterkeys())) |
| 862 device_hash_tuples = md5sum.CalculateDeviceMd5Sums( | 861 device_checksums = md5sum.CalculateDeviceMd5Sums( |
| 863 device_paths_to_md5, self) | 862 device_paths_to_md5, self) |
| 864 | 863 |
| 865 if os.path.isfile(host_path): | 864 if os.path.isfile(host_path): |
| 866 if (not device_hash_tuples | 865 host_checksum = host_checksums.get(real_host_path) |
| 867 or device_hash_tuples[0].hash != host_hash_tuples[0].hash): | 866 device_checksum = device_checksums.get(real_device_path) |
| 867 if host_checksum != device_checksum: |
| 868 return [(host_path, device_path)] | 868 return [(host_path, device_path)] |
| 869 else: | 869 else: |
| 870 return [] | 870 return [] |
| 871 else: | 871 else: |
| 872 device_tuple_dict = dict((d.path, d.hash) for d in device_hash_tuples) | |
| 873 to_push = [] | 872 to_push = [] |
| 874 for host_hash, host_abs_path in ( | 873 for host_abs_path, host_checksum in host_checksums.iteritems(): |
| 875 (h.hash, h.path) for h in host_hash_tuples): | |
| 876 device_abs_path = '%s/%s' % ( | 874 device_abs_path = '%s/%s' % ( |
| 877 real_device_path, os.path.relpath(host_abs_path, real_host_path)) | 875 real_device_path, os.path.relpath(host_abs_path, real_host_path)) |
| 878 if (device_abs_path not in device_tuple_dict | 876 if (device_checksums.get(device_abs_path) != host_checksum): |
| 879 or device_tuple_dict[device_abs_path] != host_hash): | |
| 880 to_push.append((host_abs_path, device_abs_path)) | 877 to_push.append((host_abs_path, device_abs_path)) |
| 881 return to_push | 878 return to_push |
| 882 | 879 |
| 883 def _InstallCommands(self): | 880 def _InstallCommands(self): |
| 884 if self._commands_installed is None: | 881 if self._commands_installed is None: |
| 885 try: | 882 try: |
| 886 if not install_commands.Installed(self): | 883 if not install_commands.Installed(self): |
| 887 install_commands.InstallCommands(self) | 884 install_commands.InstallCommands(self) |
| 888 self._commands_installed = True | 885 self._commands_installed = True |
| 889 except Exception as e: | 886 except Exception as e: |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1535 host_pie_path = os.path.join(constants.GetOutDirectory(), 'run_pie') | 1532 host_pie_path = os.path.join(constants.GetOutDirectory(), 'run_pie') |
| 1536 if not os.path.exists(host_pie_path): | 1533 if not os.path.exists(host_pie_path): |
| 1537 raise device_errors.CommandFailedError('Please build run_pie') | 1534 raise device_errors.CommandFailedError('Please build run_pie') |
| 1538 pie = '%s/run_pie' % constants.TEST_EXECUTABLE_DIR | 1535 pie = '%s/run_pie' % constants.TEST_EXECUTABLE_DIR |
| 1539 self.adb.Push(host_pie_path, pie) | 1536 self.adb.Push(host_pie_path, pie) |
| 1540 | 1537 |
| 1541 self._cache['run_pie'] = pie | 1538 self._cache['run_pie'] = pie |
| 1542 | 1539 |
| 1543 return self._cache['run_pie'] | 1540 return self._cache['run_pie'] |
| 1544 | 1541 |
| 1542 def GetClientCache(self, client_name): |
| 1543 """Returns client cache.""" |
| 1544 if client_name not in self._client_caches: |
| 1545 self._client_caches[client_name] = {} |
| 1546 return self._client_caches[client_name] |
| 1547 |
| 1548 def _ClearCache(self): |
| 1549 """Clears all caches.""" |
| 1550 for client in self._client_caches: |
| 1551 self._client_caches[client].clear() |
| 1552 self._cache.clear() |
| 1553 |
| 1545 @classmethod | 1554 @classmethod |
| 1546 def parallel(cls, devices=None, async=False): | 1555 def parallel(cls, devices=None, async=False): |
| 1547 """Creates a Parallelizer to operate over the provided list of devices. | 1556 """Creates a Parallelizer to operate over the provided list of devices. |
| 1548 | 1557 |
| 1549 If |devices| is either |None| or an empty list, the Parallelizer will | 1558 If |devices| is either |None| or an empty list, the Parallelizer will |
| 1550 operate over all attached devices that have not been blacklisted. | 1559 operate over all attached devices that have not been blacklisted. |
| 1551 | 1560 |
| 1552 Args: | 1561 Args: |
| 1553 devices: A list of either DeviceUtils instances or objects from | 1562 devices: A list of either DeviceUtils instances or objects from |
| 1554 from which DeviceUtils instances can be constructed. If None, | 1563 from which DeviceUtils instances can be constructed. If None, |
| 1555 all attached devices will be used. | 1564 all attached devices will be used. |
| 1556 async: If true, returns a Parallelizer that runs operations | 1565 async: If true, returns a Parallelizer that runs operations |
| 1557 asynchronously. | 1566 asynchronously. |
| 1558 | 1567 |
| 1559 Returns: | 1568 Returns: |
| 1560 A Parallelizer operating over |devices|. | 1569 A Parallelizer operating over |devices|. |
| 1561 """ | 1570 """ |
| 1562 if not devices: | 1571 if not devices: |
| 1563 devices = adb_wrapper.AdbWrapper.Devices( | 1572 devices = cls.HealthyDevices() |
| 1564 filters=device_filter.DefaultFilters()) | |
| 1565 if not devices: | 1573 if not devices: |
| 1566 raise device_errors.NoDevicesError() | 1574 raise device_errors.NoDevicesError() |
| 1567 | 1575 |
| 1568 devices = [d if isinstance(d, cls) else cls(d) for d in devices] | 1576 devices = [d if isinstance(d, cls) else cls(d) for d in devices] |
| 1569 if async: | 1577 if async: |
| 1570 return parallelizer.Parallelizer(devices) | 1578 return parallelizer.Parallelizer(devices) |
| 1571 else: | 1579 else: |
| 1572 return parallelizer.SyncParallelizer(devices) | 1580 return parallelizer.SyncParallelizer(devices) |
| 1573 | 1581 |
| 1574 def GetClientCache(self, client_name): | 1582 @classmethod |
| 1575 """Returns client cache.""" | 1583 def HealthyDevices(cls): |
| 1576 if client_name not in self._client_caches: | 1584 blacklist = device_blacklist.ReadBlacklist() |
| 1577 self._client_caches[client_name] = {} | 1585 def blacklisted(adb): |
| 1578 return self._client_caches[client_name] | 1586 if adb.GetDeviceSerial() in blacklist: |
| 1587 logging.warning('Device %s is blacklisted.', adb.GetDeviceSerial()) |
| 1588 return True |
| 1589 return False |
| 1579 | 1590 |
| 1580 def _ClearCache(self): | 1591 return [cls(adb) for adb in adb_wrapper.AdbWrapper.Devices() |
| 1581 """Clears all caches.""" | 1592 if not blacklisted(adb)] |
| 1582 for client in self._client_caches: | 1593 |
| 1583 self._client_caches[client].clear() | |
| 1584 self._cache.clear() | |
| OLD | NEW |