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 1825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1836 for client in self._client_caches: | 1836 for client in self._client_caches: |
1837 self._client_caches[client].clear() | 1837 self._client_caches[client].clear() |
1838 self._cache = { | 1838 self._cache = { |
1839 # Map of packageId -> list of on-device .apk paths | 1839 # Map of packageId -> list of on-device .apk paths |
1840 'package_apk_paths': {}, | 1840 'package_apk_paths': {}, |
1841 # Map of packageId -> set of on-device .apk checksums | 1841 # Map of packageId -> set of on-device .apk checksums |
1842 'package_apk_checksums': {}, | 1842 'package_apk_checksums': {}, |
1843 } | 1843 } |
1844 | 1844 |
1845 @classmethod | 1845 @classmethod |
1846 def parallel(cls, devices=None, async=False): | 1846 def parallel(cls, devices, async=False): |
1847 """Creates a Parallelizer to operate over the provided list of devices. | 1847 """Creates a Parallelizer to operate over the provided list of devices. |
1848 | 1848 |
1849 If |devices| is either |None| or an empty list, the Parallelizer will | 1849 If |devices| is either |None| or an empty list, the Parallelizer will |
1850 operate over all attached devices that have not been blacklisted. | 1850 operate over all attached devices that have not been blacklisted. |
1851 | 1851 |
1852 Args: | 1852 Args: |
1853 devices: A list of either DeviceUtils instances or objects from | 1853 devices: A list of either DeviceUtils instances or objects from |
1854 from which DeviceUtils instances can be constructed. If None, | 1854 from which DeviceUtils instances can be constructed. If None, |
1855 all attached devices will be used. | 1855 all attached devices will be used. |
1856 async: If true, returns a Parallelizer that runs operations | 1856 async: If true, returns a Parallelizer that runs operations |
1857 asynchronously. | 1857 asynchronously. |
1858 | 1858 |
1859 Returns: | 1859 Returns: |
1860 A Parallelizer operating over |devices|. | 1860 A Parallelizer operating over |devices|. |
1861 """ | 1861 """ |
1862 if not devices: | 1862 if not devices: |
1863 devices = cls.HealthyDevices() | 1863 raise device_errors.NoDevicesError() |
1864 if not devices: | |
1865 raise device_errors.NoDevicesError() | |
1866 | 1864 |
1867 devices = [d if isinstance(d, cls) else cls(d) for d in devices] | 1865 devices = [d if isinstance(d, cls) else cls(d) for d in devices] |
1868 if async: | 1866 if async: |
1869 return parallelizer.Parallelizer(devices) | 1867 return parallelizer.Parallelizer(devices) |
1870 else: | 1868 else: |
1871 return parallelizer.SyncParallelizer(devices) | 1869 return parallelizer.SyncParallelizer(devices) |
1872 | 1870 |
1873 @classmethod | 1871 @classmethod |
1874 def HealthyDevices(cls): | 1872 def HealthyDevices(cls, blacklist=None): |
1875 blacklist = device_blacklist.ReadBlacklist() | 1873 if not blacklist: |
| 1874 # TODO(jbudorick): Remove once clients pass in the blacklist. |
| 1875 blacklist = device_blacklist.Blacklist(device_blacklist.BLACKLIST_JSON) |
| 1876 |
| 1877 blacklisted_devices = blacklist.Read() |
1876 def blacklisted(adb): | 1878 def blacklisted(adb): |
1877 if adb.GetDeviceSerial() in blacklist: | 1879 if adb.GetDeviceSerial() in blacklisted_devices: |
1878 logging.warning('Device %s is blacklisted.', adb.GetDeviceSerial()) | 1880 logging.warning('Device %s is blacklisted.', adb.GetDeviceSerial()) |
1879 return True | 1881 return True |
1880 return False | 1882 return False |
1881 | 1883 |
1882 return [cls(adb) for adb in adb_wrapper.AdbWrapper.Devices() | 1884 return [cls(adb) for adb in adb_wrapper.AdbWrapper.Devices() |
1883 if not blacklisted(adb)] | 1885 if not blacklisted(adb)] |
1884 | 1886 |
1885 @decorators.WithTimeoutAndRetriesFromInstance() | 1887 @decorators.WithTimeoutAndRetriesFromInstance() |
1886 def RestartAdbd(self, timeout=None, retries=None): | 1888 def RestartAdbd(self, timeout=None, retries=None): |
1887 logging.info('Restarting adbd on device.') | 1889 logging.info('Restarting adbd on device.') |
1888 with device_temp_file.DeviceTempFile(self.adb, suffix='.sh') as script: | 1890 with device_temp_file.DeviceTempFile(self.adb, suffix='.sh') as script: |
1889 self.WriteFile(script.name, _RESTART_ADBD_SCRIPT) | 1891 self.WriteFile(script.name, _RESTART_ADBD_SCRIPT) |
1890 self.RunShellCommand(['source', script.name], as_root=True) | 1892 self.RunShellCommand(['source', script.name], as_root=True) |
1891 self.adb.WaitForDevice() | 1893 self.adb.WaitForDevice() |
OLD | NEW |