Chromium Code Reviews| Index: build/android/pylib/local/device/local_device_environment.py |
| diff --git a/build/android/pylib/local/device/local_device_environment.py b/build/android/pylib/local/device/local_device_environment.py |
| index ee0ff987afd353f22095d06d3c52f4014dddcf44..f0a6ca5c081118b86e605b45bb7ccc57a3a01aac 100644 |
| --- a/build/android/pylib/local/device/local_device_environment.py |
| +++ b/build/android/pylib/local/device/local_device_environment.py |
| @@ -3,6 +3,7 @@ |
| # found in the LICENSE file. |
| import logging |
| +import os |
| import threading |
| from devil.android import device_blacklist |
| @@ -10,6 +11,12 @@ from devil.android import device_errors |
| from devil.android import device_utils |
| from devil.utils import parallelizer |
| from pylib.base import environment |
| +from pylib import constants |
|
jbudorick
2015/10/08 14:34:49
nit: this should precede pylib.base.environment
agrieve
2015/10/08 16:03:28
Done.
|
| + |
| + |
| +def _DeviceCachePath(device): |
| + file_name = 'device_cache_%s.json' % device.adb.GetDeviceSerial() |
| + return os.path.join(constants.GetOutDirectory(), file_name) |
| class LocalDeviceEnvironment(environment.Environment): |
| @@ -24,11 +31,12 @@ class LocalDeviceEnvironment(environment.Environment): |
| self._devices = [] |
| self._max_tries = 1 + args.num_retries |
| self._tool_name = args.tool |
| + self._enable_device_cache = args.enable_device_cache |
| #override |
| def SetUp(self): |
| available_devices = device_utils.DeviceUtils.HealthyDevices( |
| - self._blacklist) |
| + self._blacklist, enable_device_files_cache=self._enable_device_cache) |
| if not available_devices: |
| raise device_errors.NoDevicesError |
| if self._device_serial: |
| @@ -40,6 +48,15 @@ class LocalDeviceEnvironment(environment.Environment): |
| else: |
| self._devices = available_devices |
| + if self._enable_device_cache: |
| + for d in self._devices: |
| + cache_path = _DeviceCachePath(d) |
| + if os.path.exists(cache_path): |
| + logging.info('Using device cache: %s', cache_path) |
| + with open(cache_path) as f: |
| + d.LoadCacheData(f.read()) |
| + os.unlink(cache_path) |
| + |
| @property |
| def devices(self): |
| if not self._devices: |
| @@ -60,7 +77,13 @@ class LocalDeviceEnvironment(environment.Environment): |
| #override |
| def TearDown(self): |
| - pass |
| + # Write the cache even when not using it so that a bad cache will be fixed |
|
jbudorick
2015/10/08 14:34:49
I lost you on the reasoning here as written. I can
agrieve
2015/10/08 16:03:28
Reworded
agrieve
2015/10/09 00:28:31
Should also note that the extra time is negligible
jbudorick
2015/10/09 00:30:31
Fair enough.
|
| + # by running once without it enabled. |
| + for d in self._devices: |
| + cache_path = _DeviceCachePath(d) |
| + with open(cache_path, 'w') as f: |
| + f.write(d.DumpCacheData()) |
| + logging.info('Wrote device cache: %s', cache_path) |
| def BlacklistDevice(self, device): |
| if not self._blacklist: |