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

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

Issue 724413003: Migrate device_utils.RestartServer to adb_wrapper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased against master Created 6 years 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
« no previous file with comments | « no previous file | build/android/pylib/device/device_utils.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 @classmethod
143 def KillServer(cls, timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES):
144 cls._RunAdbCmd(['kill-server'], timeout=timeout, retries=retries)
145
146 @classmethod
147 def StartServer(cls, timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES):
148 # CPU affinity is used to reduce adb instability http://crbug.com/268450
149 cls._RunAdbCmd(['start-server'], timeout=timeout, retries=retries,
150 cpu_affinity=0)
151
138 # TODO(craigdh): Determine the filter criteria that should be supported. 152 # TODO(craigdh): Determine the filter criteria that should be supported.
139 @classmethod 153 @classmethod
140 def GetDevices(cls, timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES): 154 def GetDevices(cls, timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES):
141 """Get the list of active attached devices. 155 """Get the list of active attached devices.
142 156
143 Args: 157 Args:
144 timeout: (optional) Timeout per try in seconds. 158 timeout: (optional) Timeout per try in seconds.
145 retries: (optional) Number of retries to attempt. 159 retries: (optional) Number of retries to attempt.
146 160
147 Yields: 161 Yields:
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 """Restarts the adbd daemon with root permissions, if possible. 470 """Restarts the adbd daemon with root permissions, if possible.
457 471
458 Args: 472 Args:
459 timeout: (optional) Timeout per try in seconds. 473 timeout: (optional) Timeout per try in seconds.
460 retries: (optional) Number of retries to attempt. 474 retries: (optional) Number of retries to attempt.
461 """ 475 """
462 output = self._RunDeviceAdbCmd(['root'], timeout, retries) 476 output = self._RunDeviceAdbCmd(['root'], timeout, retries)
463 if 'cannot' in output: 477 if 'cannot' in output:
464 raise device_errors.AdbCommandFailedError( 478 raise device_errors.AdbCommandFailedError(
465 ['root'], output, device_serial=self._device_serial) 479 ['root'], output, device_serial=self._device_serial)
OLDNEW
« no previous file with comments | « no previous file | build/android/pylib/device/device_utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698