Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: build/android/pylib/device/adb_wrapper.py

Issue 839143002: Roll Chrome into Mojo. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Rebase Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 Args: 50 Args:
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 def _BuildAdbCmd(cls, args, device_serial): 59 def _BuildAdbCmd(cls, args, device_serial, cpu_affinity=None):
60 cmd = [constants.GetAdbPath()] 60 if cpu_affinity is not None:
61 cmd = ['taskset', '-c', str(cpu_affinity)]
62 else:
63 cmd = []
64 cmd.append(constants.GetAdbPath())
61 if device_serial is not None: 65 if device_serial is not None:
62 cmd.extend(['-s', device_serial]) 66 cmd.extend(['-s', device_serial])
63 cmd.extend(args) 67 cmd.extend(args)
64 return cmd 68 return cmd
65 # pylint: enable=unused-argument 69 # pylint: enable=unused-argument
66 70
67 # pylint: disable=unused-argument 71 # pylint: disable=unused-argument
68 @classmethod 72 @classmethod
69 @decorators.WithTimeoutAndRetries 73 @decorators.WithTimeoutAndRetries
70 def _RunAdbCmd(cls, args, timeout=None, retries=None, device_serial=None, 74 def _RunAdbCmd(cls, args, timeout=None, retries=None, device_serial=None,
71 check_error=True): 75 check_error=True, cpu_affinity=None):
72 status, output = cmd_helper.GetCmdStatusAndOutputWithTimeout( 76 status, output = cmd_helper.GetCmdStatusAndOutputWithTimeout(
73 cls._BuildAdbCmd(args, device_serial), 77 cls._BuildAdbCmd(args, device_serial, cpu_affinity=cpu_affinity),
74 timeout_retry.CurrentTimeoutThread().GetRemainingTime()) 78 timeout_retry.CurrentTimeoutThread().GetRemainingTime())
75 if status != 0: 79 if status != 0:
76 raise device_errors.AdbCommandFailedError( 80 raise device_errors.AdbCommandFailedError(
77 args, output, status, device_serial) 81 args, output, status, device_serial)
78 # This catches some errors, including when the device drops offline; 82 # This catches some errors, including when the device drops offline;
79 # unfortunately adb is very inconsistent with error reporting so many 83 # unfortunately adb is very inconsistent with error reporting so many
80 # command failures present differently. 84 # command failures present differently.
81 if check_error and output.startswith('error:'): 85 if check_error and output.startswith('error:'):
82 raise device_errors.AdbCommandFailedError(args, output) 86 raise device_errors.AdbCommandFailedError(args, output)
83 return output 87 return output
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 """The string representation of an instance. 132 """The string representation of an instance.
129 133
130 Returns: 134 Returns:
131 The device serial number as a string. 135 The device serial number as a string.
132 """ 136 """
133 return self._device_serial 137 return self._device_serial
134 138
135 def __repr__(self): 139 def __repr__(self):
136 return '%s(\'%s\')' % (self.__class__.__name__, self) 140 return '%s(\'%s\')' % (self.__class__.__name__, self)
137 141
142 # pylint: disable=unused-argument
143 @classmethod
144 def IsServerOnline(cls):
145 status, output = cmd_helper.GetCmdStatusAndOutput(['pgrep', 'adb'])
146 output = [int(x) for x in output.split()]
147 logging.info('PIDs for adb found: %r', output)
148 return status == 0
149 # pylint: enable=unused-argument
150
151 @classmethod
152 def KillServer(cls, timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES):
153 cls._RunAdbCmd(['kill-server'], timeout=timeout, retries=retries)
154
155 @classmethod
156 def StartServer(cls, timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES):
157 # CPU affinity is used to reduce adb instability http://crbug.com/268450
158 cls._RunAdbCmd(['start-server'], timeout=timeout, retries=retries,
159 cpu_affinity=0)
160
138 # TODO(craigdh): Determine the filter criteria that should be supported. 161 # TODO(craigdh): Determine the filter criteria that should be supported.
139 @classmethod 162 @classmethod
140 def GetDevices(cls, timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES): 163 def GetDevices(cls, timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES):
141 """Get the list of active attached devices. 164 """Get the list of active attached devices.
142 165
143 Args: 166 Args:
144 timeout: (optional) Timeout per try in seconds. 167 timeout: (optional) Timeout per try in seconds.
145 retries: (optional) Number of retries to attempt. 168 retries: (optional) Number of retries to attempt.
146 169
147 Yields: 170 Yields:
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 if expect_status is not None: 238 if expect_status is not None:
216 output_end = output.rfind('%') 239 output_end = output.rfind('%')
217 if output_end < 0: 240 if output_end < 0:
218 # causes the status string to become empty and raise a ValueError 241 # causes the status string to become empty and raise a ValueError
219 output_end = len(output) 242 output_end = len(output)
220 243
221 try: 244 try:
222 status = int(output[output_end+1:]) 245 status = int(output[output_end+1:])
223 except ValueError: 246 except ValueError:
224 logging.warning('exit status of shell command %r missing.', command) 247 logging.warning('exit status of shell command %r missing.', command)
225 raise device_errors.AdbCommandFailedError( 248 raise device_errors.AdbShellCommandFailedError(
226 args, output, device_serial=self._device_serial) 249 command, output, status=None, device_serial=self._device_serial)
227 output = output[:output_end] 250 output = output[:output_end]
228 if status != expect_status: 251 if status != expect_status:
229 raise device_errors.AdbCommandFailedError( 252 raise device_errors.AdbShellCommandFailedError(
230 args, output, status, self._device_serial) 253 command, output, status=status, device_serial=self._device_serial)
231 return output 254 return output
232 255
233 def Ls(self, path, timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES): 256 def Ls(self, path, timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES):
234 """List the contents of a directory on the device. 257 """List the contents of a directory on the device.
235 258
236 Args: 259 Args:
237 path: Path on the device filesystem. 260 path: Path on the device filesystem.
238 timeout: (optional) Timeout per try in seconds. 261 timeout: (optional) Timeout per try in seconds.
239 retries: (optional) Number of retries to attempt. 262 retries: (optional) Number of retries to attempt.
240 263
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 """Restarts the adbd daemon with root permissions, if possible. 479 """Restarts the adbd daemon with root permissions, if possible.
457 480
458 Args: 481 Args:
459 timeout: (optional) Timeout per try in seconds. 482 timeout: (optional) Timeout per try in seconds.
460 retries: (optional) Number of retries to attempt. 483 retries: (optional) Number of retries to attempt.
461 """ 484 """
462 output = self._RunDeviceAdbCmd(['root'], timeout, retries) 485 output = self._RunDeviceAdbCmd(['root'], timeout, retries)
463 if 'cannot' in output: 486 if 'cannot' in output:
464 raise device_errors.AdbCommandFailedError( 487 raise device_errors.AdbCommandFailedError(
465 ['root'], output, device_serial=self._device_serial) 488 ['root'], output, device_serial=self._device_serial)
OLDNEW
« no previous file with comments | « build/android/findbugs_filter/findbugs_known_bugs.txt ('k') | build/android/pylib/device/device_errors.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698