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

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

Issue 804033002: Revert of Migrate device_utils.RestartServer to adb_wrapper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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, cpu_affinity=None): 59 def _BuildAdbCmd(cls, args, device_serial):
60 if cpu_affinity is not None: 60 cmd = [constants.GetAdbPath()]
61 cmd = ['taskset', '-c', str(cpu_affinity)]
62 else:
63 cmd = []
64 cmd.append(constants.GetAdbPath())
65 if device_serial is not None: 61 if device_serial is not None:
66 cmd.extend(['-s', device_serial]) 62 cmd.extend(['-s', device_serial])
67 cmd.extend(args) 63 cmd.extend(args)
68 return cmd 64 return cmd
69 # pylint: enable=unused-argument 65 # pylint: enable=unused-argument
70 66
71 # pylint: disable=unused-argument 67 # pylint: disable=unused-argument
72 @classmethod 68 @classmethod
73 @decorators.WithTimeoutAndRetries 69 @decorators.WithTimeoutAndRetries
74 def _RunAdbCmd(cls, args, timeout=None, retries=None, device_serial=None, 70 def _RunAdbCmd(cls, args, timeout=None, retries=None, device_serial=None,
75 check_error=True, cpu_affinity=None): 71 check_error=True):
76 status, output = cmd_helper.GetCmdStatusAndOutputWithTimeout( 72 status, output = cmd_helper.GetCmdStatusAndOutputWithTimeout(
77 cls._BuildAdbCmd(args, device_serial, cpu_affinity=cpu_affinity), 73 cls._BuildAdbCmd(args, device_serial),
78 timeout_retry.CurrentTimeoutThread().GetRemainingTime()) 74 timeout_retry.CurrentTimeoutThread().GetRemainingTime())
79 if status != 0: 75 if status != 0:
80 raise device_errors.AdbCommandFailedError( 76 raise device_errors.AdbCommandFailedError(
81 args, output, status, device_serial) 77 args, output, status, device_serial)
82 # This catches some errors, including when the device drops offline; 78 # This catches some errors, including when the device drops offline;
83 # unfortunately adb is very inconsistent with error reporting so many 79 # unfortunately adb is very inconsistent with error reporting so many
84 # command failures present differently. 80 # command failures present differently.
85 if check_error and output.startswith('error:'): 81 if check_error and output.startswith('error:'):
86 raise device_errors.AdbCommandFailedError(args, output) 82 raise device_errors.AdbCommandFailedError(args, output)
87 return output 83 return output
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 """The string representation of an instance. 128 """The string representation of an instance.
133 129
134 Returns: 130 Returns:
135 The device serial number as a string. 131 The device serial number as a string.
136 """ 132 """
137 return self._device_serial 133 return self._device_serial
138 134
139 def __repr__(self): 135 def __repr__(self):
140 return '%s(\'%s\')' % (self.__class__.__name__, self) 136 return '%s(\'%s\')' % (self.__class__.__name__, self)
141 137
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
152 # TODO(craigdh): Determine the filter criteria that should be supported. 138 # TODO(craigdh): Determine the filter criteria that should be supported.
153 @classmethod 139 @classmethod
154 def GetDevices(cls, timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES): 140 def GetDevices(cls, timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES):
155 """Get the list of active attached devices. 141 """Get the list of active attached devices.
156 142
157 Args: 143 Args:
158 timeout: (optional) Timeout per try in seconds. 144 timeout: (optional) Timeout per try in seconds.
159 retries: (optional) Number of retries to attempt. 145 retries: (optional) Number of retries to attempt.
160 146
161 Yields: 147 Yields:
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 """Restarts the adbd daemon with root permissions, if possible. 456 """Restarts the adbd daemon with root permissions, if possible.
471 457
472 Args: 458 Args:
473 timeout: (optional) Timeout per try in seconds. 459 timeout: (optional) Timeout per try in seconds.
474 retries: (optional) Number of retries to attempt. 460 retries: (optional) Number of retries to attempt.
475 """ 461 """
476 output = self._RunDeviceAdbCmd(['root'], timeout, retries) 462 output = self._RunDeviceAdbCmd(['root'], timeout, retries)
477 if 'cannot' in output: 463 if 'cannot' in output:
478 raise device_errors.AdbCommandFailedError( 464 raise device_errors.AdbCommandFailedError(
479 ['root'], output, device_serial=self._device_serial) 465 ['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