OLD | NEW |
---|---|
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 """This module wraps Android's adb tool. | 5 """This module wraps Android's adb tool. |
6 | 6 |
7 This is a thin wrapper around the adb interface. Any additional complexity | 7 This is a thin wrapper around the adb interface. Any additional complexity |
8 should be delegated to a higher level (ex. DeviceUtils). | 8 should be delegated to a higher level (ex. DeviceUtils). |
9 """ | 9 """ |
10 | 10 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 device_serial: The device serial number as a string. | 51 device_serial: The device serial number as a string. |
52 """ | 52 """ |
53 if not device_serial: | 53 if not device_serial: |
54 raise ValueError('A device serial must be specified') | 54 raise ValueError('A device serial must be specified') |
55 self._device_serial = str(device_serial) | 55 self._device_serial = str(device_serial) |
56 | 56 |
57 # pylint: disable=unused-argument | 57 # pylint: disable=unused-argument |
58 @classmethod | 58 @classmethod |
59 @decorators.WithTimeoutAndRetries | 59 @decorators.WithTimeoutAndRetries |
60 def _RunAdbCmd(cls, args, timeout=None, retries=None, device_serial=None, | 60 def _RunAdbCmd(cls, args, timeout=None, retries=None, device_serial=None, |
61 check_error=True): | 61 check_error=True, cpu_affinity=None): |
jbudorick
2014/12/11 01:43:13
Probably doesn't surprise you to hear that I'm not
perezju
2014/12/11 11:38:00
Yeah, I don't like this too much either. But could
jbudorick
2014/12/11 16:27:17
Agreed.
| |
62 cmd = [constants.GetAdbPath()] | 62 if cpu_affinity is not None: |
63 cmd = ['taskset', '-c', str(cpu_affinity)] | |
jbudorick
2014/12/11 01:43:13
How is this going to interact with _BuildAdbCmd in
perezju
2014/12/11 11:38:00
I think cpu_affinity (or something like that) woul
| |
64 else: | |
65 cmd = [] | |
66 cmd.append(constants.GetAdbPath()) | |
63 if device_serial is not None: | 67 if device_serial is not None: |
64 cmd.extend(['-s', device_serial]) | 68 cmd.extend(['-s', device_serial]) |
65 cmd.extend(args) | 69 cmd.extend(args) |
66 status, output = cmd_helper.GetCmdStatusAndOutputWithTimeout( | 70 status, output = cmd_helper.GetCmdStatusAndOutputWithTimeout( |
67 cmd, timeout_retry.CurrentTimeoutThread().GetRemainingTime()) | 71 cmd, timeout_retry.CurrentTimeoutThread().GetRemainingTime()) |
68 if status != 0: | 72 if status != 0: |
69 raise device_errors.AdbCommandFailedError( | 73 raise device_errors.AdbCommandFailedError( |
70 args, output, status, device_serial) | 74 args, output, status, device_serial) |
71 # This catches some errors, including when the device drops offline; | 75 # This catches some errors, including when the device drops offline; |
72 # unfortunately adb is very inconsistent with error reporting so many | 76 # unfortunately adb is very inconsistent with error reporting so many |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 """The string representation of an instance. | 112 """The string representation of an instance. |
109 | 113 |
110 Returns: | 114 Returns: |
111 The device serial number as a string. | 115 The device serial number as a string. |
112 """ | 116 """ |
113 return self._device_serial | 117 return self._device_serial |
114 | 118 |
115 def __repr__(self): | 119 def __repr__(self): |
116 return '%s(\'%s\')' % (self.__class__.__name__, self) | 120 return '%s(\'%s\')' % (self.__class__.__name__, self) |
117 | 121 |
122 @classmethod | |
123 def KillServer(cls, timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES): | |
124 cls._RunAdbCmd(['kill-server'], timeout=timeout, retries=retries) | |
125 | |
126 @classmethod | |
127 def StartServer(cls, timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES): | |
128 # CPU affinity is used to reduce adb instability http://crbug.com/268450 | |
129 cls._RunAdbCmd(['start-server'], timeout=timeout, retries=retries, | |
130 cpu_affinity=0) | |
131 | |
118 # TODO(craigdh): Determine the filter criteria that should be supported. | 132 # TODO(craigdh): Determine the filter criteria that should be supported. |
119 @classmethod | 133 @classmethod |
120 def GetDevices(cls, timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES): | 134 def GetDevices(cls, timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES): |
121 """Get the list of active attached devices. | 135 """Get the list of active attached devices. |
122 | 136 |
123 Args: | 137 Args: |
124 timeout: (optional) Timeout per try in seconds. | 138 timeout: (optional) Timeout per try in seconds. |
125 retries: (optional) Number of retries to attempt. | 139 retries: (optional) Number of retries to attempt. |
126 | 140 |
127 Yields: | 141 Yields: |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
438 """Restarts the adbd daemon with root permissions, if possible. | 452 """Restarts the adbd daemon with root permissions, if possible. |
439 | 453 |
440 Args: | 454 Args: |
441 timeout: (optional) Timeout per try in seconds. | 455 timeout: (optional) Timeout per try in seconds. |
442 retries: (optional) Number of retries to attempt. | 456 retries: (optional) Number of retries to attempt. |
443 """ | 457 """ |
444 output = self._RunDeviceAdbCmd(['root'], timeout, retries) | 458 output = self._RunDeviceAdbCmd(['root'], timeout, retries) |
445 if 'cannot' in output: | 459 if 'cannot' in output: |
446 raise device_errors.AdbCommandFailedError( | 460 raise device_errors.AdbCommandFailedError( |
447 ['root'], output, device_serial=self._device_serial) | 461 ['root'], output, device_serial=self._device_serial) |
OLD | NEW |