| 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..25ef5828da1c682aa1d88fea24bb762a5030fbcd 100644
|
| --- a/build/android/pylib/local/device/local_device_environment.py
|
| +++ b/build/android/pylib/local/device/local_device_environment.py
|
| @@ -3,15 +3,22 @@
|
| # found in the LICENSE file.
|
|
|
| import logging
|
| +import os
|
| import threading
|
|
|
| from devil.android import device_blacklist
|
| from devil.android import device_errors
|
| from devil.android import device_utils
|
| from devil.utils import parallelizer
|
| +from pylib import constants
|
| from pylib.base import environment
|
|
|
|
|
| +def _DeviceCachePath(device):
|
| + file_name = 'device_cache_%s.json' % device.adb.GetDeviceSerial()
|
| + return os.path.join(constants.GetOutDirectory(), file_name)
|
| +
|
| +
|
| class LocalDeviceEnvironment(environment.Environment):
|
|
|
| def __init__(self, args, _error_func):
|
| @@ -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,14 @@ class LocalDeviceEnvironment(environment.Environment):
|
|
|
| #override
|
| def TearDown(self):
|
| - pass
|
| + # Write the cache even when not using it so that it will be ready the first
|
| + # time that it is enabled. Writing it every time is also necessary so that
|
| + # an invalid cache can be flushed just by disabling it for one run.
|
| + 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:
|
|
|