| 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 | 
| 11 import collections | 11 import collections | 
| 12 import contextlib | 12 import contextlib | 
| 13 import itertools | 13 import itertools | 
| 14 import logging | 14 import logging | 
| 15 import multiprocessing | 15 import multiprocessing | 
| 16 import os | 16 import os | 
| 17 import posixpath | 17 import posixpath | 
| 18 import re | 18 import re | 
| 19 import shutil | 19 import shutil | 
| 20 import sys | 20 import sys | 
| 21 import tempfile | 21 import tempfile | 
| 22 import threading | 22 import threading | 
| 23 import time | 23 import time | 
| 24 import zipfile | 24 import zipfile | 
| 25 | 25 | 
| 26 import pylib.android_commands |  | 
| 27 from pylib import cmd_helper | 26 from pylib import cmd_helper | 
| 28 from pylib import constants | 27 from pylib import constants | 
| 29 from pylib import device_signal | 28 from pylib import device_signal | 
| 30 from pylib.constants import keyevent | 29 from pylib.constants import keyevent | 
| 31 from pylib.device import adb_wrapper | 30 from pylib.device import adb_wrapper | 
| 32 from pylib.device import decorators | 31 from pylib.device import decorators | 
| 33 from pylib.device import device_blacklist | 32 from pylib.device import device_blacklist | 
| 34 from pylib.device import device_errors | 33 from pylib.device import device_errors | 
| 35 from pylib.device import intent | 34 from pylib.device import intent | 
| 36 from pylib.device import logcat_monitor | 35 from pylib.device import logcat_monitor | 
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 167       device: Either a device serial, an existing AdbWrapper instance, or an | 166       device: Either a device serial, an existing AdbWrapper instance, or an | 
| 168               an existing AndroidCommands instance. | 167               an existing AndroidCommands instance. | 
| 169       default_timeout: An integer containing the default number of seconds to | 168       default_timeout: An integer containing the default number of seconds to | 
| 170                        wait for an operation to complete if no explicit value | 169                        wait for an operation to complete if no explicit value | 
| 171                        is provided. | 170                        is provided. | 
| 172       default_retries: An integer containing the default number or times an | 171       default_retries: An integer containing the default number or times an | 
| 173                        operation should be retried on failure if no explicit | 172                        operation should be retried on failure if no explicit | 
| 174                        value is provided. | 173                        value is provided. | 
| 175     """ | 174     """ | 
| 176     self.adb = None | 175     self.adb = None | 
| 177     self.old_interface = None |  | 
| 178     if isinstance(device, basestring): | 176     if isinstance(device, basestring): | 
| 179       self.adb = adb_wrapper.AdbWrapper(device) | 177       self.adb = adb_wrapper.AdbWrapper(device) | 
| 180       self.old_interface = pylib.android_commands.AndroidCommands(device) |  | 
| 181     elif isinstance(device, adb_wrapper.AdbWrapper): | 178     elif isinstance(device, adb_wrapper.AdbWrapper): | 
| 182       self.adb = device | 179       self.adb = device | 
| 183       self.old_interface = pylib.android_commands.AndroidCommands(str(device)) |  | 
| 184     elif isinstance(device, pylib.android_commands.AndroidCommands): |  | 
| 185       self.adb = adb_wrapper.AdbWrapper(device.GetDevice()) |  | 
| 186       self.old_interface = device |  | 
| 187     else: | 180     else: | 
| 188       raise ValueError('Unsupported device value: %r' % device) | 181       raise ValueError('Unsupported device value: %r' % device) | 
| 189     self._commands_installed = None | 182     self._commands_installed = None | 
| 190     self._default_timeout = default_timeout | 183     self._default_timeout = default_timeout | 
| 191     self._default_retries = default_retries | 184     self._default_retries = default_retries | 
| 192     self._cache = {} | 185     self._cache = {} | 
| 193     self._client_caches = {} | 186     self._client_caches = {} | 
| 194     assert hasattr(self, decorators.DEFAULT_TIMEOUT_ATTR) | 187     assert hasattr(self, decorators.DEFAULT_TIMEOUT_ATTR) | 
| 195     assert hasattr(self, decorators.DEFAULT_RETRIES_ATTR) | 188     assert hasattr(self, decorators.DEFAULT_RETRIES_ATTR) | 
| 196 | 189 | 
| (...skipping 1692 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1889     return [cls(adb) for adb in adb_wrapper.AdbWrapper.Devices() | 1882     return [cls(adb) for adb in adb_wrapper.AdbWrapper.Devices() | 
| 1890             if not blacklisted(adb)] | 1883             if not blacklisted(adb)] | 
| 1891 | 1884 | 
| 1892   @decorators.WithTimeoutAndRetriesFromInstance() | 1885   @decorators.WithTimeoutAndRetriesFromInstance() | 
| 1893   def RestartAdbd(self, timeout=None, retries=None): | 1886   def RestartAdbd(self, timeout=None, retries=None): | 
| 1894     logging.info('Restarting adbd on device.') | 1887     logging.info('Restarting adbd on device.') | 
| 1895     with device_temp_file.DeviceTempFile(self.adb, suffix='.sh') as script: | 1888     with device_temp_file.DeviceTempFile(self.adb, suffix='.sh') as script: | 
| 1896       self.WriteFile(script.name, _RESTART_ADBD_SCRIPT) | 1889       self.WriteFile(script.name, _RESTART_ADBD_SCRIPT) | 
| 1897       self.RunShellCommand(['source', script.name], as_root=True) | 1890       self.RunShellCommand(['source', script.name], as_root=True) | 
| 1898       self.adb.WaitForDevice() | 1891       self.adb.WaitForDevice() | 
| OLD | NEW | 
|---|