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

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

Issue 754433003: Update from https://crrev.com/305340 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
11 import errno 11 import errno
12 import os 12 import os
13 13
14 from pylib import cmd_helper 14 from pylib import cmd_helper
15 from pylib import constants
15 from pylib.device import decorators 16 from pylib.device import decorators
16 from pylib.device import device_errors 17 from pylib.device import device_errors
17 from pylib.utils import timeout_retry 18 from pylib.utils import timeout_retry
18 19
19 20
20 _DEFAULT_TIMEOUT = 30 21 _DEFAULT_TIMEOUT = 30
21 _DEFAULT_RETRIES = 2 22 _DEFAULT_RETRIES = 2
22 23
23 24
24 def _VerifyLocalFileExists(path): 25 def _VerifyLocalFileExists(path):
(...skipping 13 matching lines...) Expand all
38 """A wrapper around a local Android Debug Bridge executable.""" 39 """A wrapper around a local Android Debug Bridge executable."""
39 40
40 def __init__(self, device_serial): 41 def __init__(self, device_serial):
41 """Initializes the AdbWrapper. 42 """Initializes the AdbWrapper.
42 43
43 Args: 44 Args:
44 device_serial: The device serial number as a string. 45 device_serial: The device serial number as a string.
45 """ 46 """
46 self._device_serial = str(device_serial) 47 self._device_serial = str(device_serial)
47 48
48 # pylint: disable=W0613 49 # pylint: disable=unused-argument
49 @classmethod 50 @classmethod
50 @decorators.WithTimeoutAndRetries 51 @decorators.WithTimeoutAndRetries
51 def _RunAdbCmd(cls, arg_list, timeout=None, retries=None, check_error=True): 52 def _RunAdbCmd(cls, arg_list, timeout=None, retries=None, check_error=True):
52 cmd = ['adb'] + arg_list 53 cmd = [constants.GetAdbPath()] + arg_list
53 exit_code, output = cmd_helper.GetCmdStatusAndOutputWithTimeout( 54 exit_code, output = cmd_helper.GetCmdStatusAndOutputWithTimeout(
54 cmd, timeout_retry.CurrentTimeoutThread().GetRemainingTime()) 55 cmd, timeout_retry.CurrentTimeoutThread().GetRemainingTime())
55 if exit_code != 0: 56 if exit_code != 0:
56 raise device_errors.AdbCommandFailedError( 57 raise device_errors.AdbCommandFailedError(
57 cmd, 'returned non-zero exit code %d and output %r' % 58 cmd, 'returned non-zero exit code %d and output %r' %
58 (exit_code, output)) 59 (exit_code, output))
59 # This catches some errors, including when the device drops offline; 60 # This catches some errors, including when the device drops offline;
60 # unfortunately adb is very inconsistent with error reporting so many 61 # unfortunately adb is very inconsistent with error reporting so many
61 # command failures present differently. 62 # command failures present differently.
62 if check_error and output[:len('error:')] == 'error:': 63 if check_error and output[:len('error:')] == 'error:':
63 raise device_errors.AdbCommandFailedError(arg_list, output) 64 raise device_errors.AdbCommandFailedError(arg_list, output)
64 return output 65 return output
65 # pylint: enable=W0613 66 # pylint: enable=unused-argument
66 67
67 def _DeviceAdbCmd(self, arg_list, timeout, retries, check_error=True): 68 def _DeviceAdbCmd(self, arg_list, timeout, retries, check_error=True):
68 """Runs an adb command on the device associated with this object. 69 """Runs an adb command on the device associated with this object.
69 70
70 Args: 71 Args:
71 arg_list: A list of arguments to adb. 72 arg_list: A list of arguments to adb.
72 timeout: Timeout in seconds. 73 timeout: Timeout in seconds.
73 retries: Number of retries. 74 retries: Number of retries.
74 check_error: Check that the command doesn't return an error message. This 75 check_error: Check that the command doesn't return an error message. This
75 does NOT check the return code of shell commands. 76 does NOT check the return code of shell commands.
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 """Restarts the adbd daemon with root permissions, if possible. 390 """Restarts the adbd daemon with root permissions, if possible.
390 391
391 Args: 392 Args:
392 timeout: (optional) Timeout per try in seconds. 393 timeout: (optional) Timeout per try in seconds.
393 retries: (optional) Number of retries to attempt. 394 retries: (optional) Number of retries to attempt.
394 """ 395 """
395 output = self._DeviceAdbCmd(['root'], timeout, retries) 396 output = self._DeviceAdbCmd(['root'], timeout, retries)
396 if 'cannot' in output: 397 if 'cannot' in output:
397 raise device_errors.AdbCommandFailedError(['root'], output) 398 raise device_errors.AdbCommandFailedError(['root'], output)
398 399
OLDNEW
« no previous file with comments | « build/android/pylib/constants.py ('k') | build/android/pylib/device/commands/install_commands.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698