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

Side by Side Diff: build/android/devil/android/sdk/adb_wrapper.py

Issue 1415413005: Revert of [Android] Add a configurable environment for devil/. (RELAND) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « build/android/devil/android/sdk/aapt.py ('k') | build/android/devil/android/sdk/dexdump.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
11 import collections 11 import collections
12 import errno 12 import errno
13 import logging 13 import logging
14 import os 14 import os
15 import re 15 import re
16 import threading
17 16
18 from devil import devil_env
19 from devil.android import decorators 17 from devil.android import decorators
20 from devil.android import device_errors 18 from devil.android import device_errors
21 from devil.utils import cmd_helper 19 from devil.utils import cmd_helper
22 from devil.utils import timeout_retry 20 from devil.utils import timeout_retry
21 from pylib import constants
23 22
24 23
25 _DEFAULT_TIMEOUT = 30 24 _DEFAULT_TIMEOUT = 30
26 _DEFAULT_RETRIES = 2 25 _DEFAULT_RETRIES = 2
27 26
28 _EMULATOR_RE = re.compile(r'^emulator-[0-9]+$') 27 _EMULATOR_RE = re.compile(r'^emulator-[0-9]+$')
29 28
30 _READY_STATE = 'device' 29 _READY_STATE = 'device'
31 30
32 31
(...skipping 10 matching lines...) Expand all
43 raise IOError(errno.ENOENT, os.strerror(errno.ENOENT), path) 42 raise IOError(errno.ENOENT, os.strerror(errno.ENOENT), path)
44 43
45 44
46 DeviceStat = collections.namedtuple('DeviceStat', 45 DeviceStat = collections.namedtuple('DeviceStat',
47 ['st_mode', 'st_size', 'st_time']) 46 ['st_mode', 'st_size', 'st_time'])
48 47
49 48
50 class AdbWrapper(object): 49 class AdbWrapper(object):
51 """A wrapper around a local Android Debug Bridge executable.""" 50 """A wrapper around a local Android Debug Bridge executable."""
52 51
53 _adb_path = None
54 _adb_path_lock = threading.Lock()
55
56 def __init__(self, device_serial): 52 def __init__(self, device_serial):
57 """Initializes the AdbWrapper. 53 """Initializes the AdbWrapper.
58 54
59 Args: 55 Args:
60 device_serial: The device serial number as a string. 56 device_serial: The device serial number as a string.
61 """ 57 """
62 if not device_serial: 58 if not device_serial:
63 raise ValueError('A device serial must be specified') 59 raise ValueError('A device serial must be specified')
64 self._device_serial = str(device_serial) 60 self._device_serial = str(device_serial)
65 61
66 @classmethod 62 # pylint: disable=unused-argument
67 def _GetAdbPath(cls):
68 if not cls._adb_path:
69 with cls._adb_path_lock:
70 if not cls._adb_path:
71 cls._adb_path = devil_env.config.FetchPath('adb')
72 return cls._adb_path
73
74 @classmethod 63 @classmethod
75 def _BuildAdbCmd(cls, args, device_serial, cpu_affinity=None): 64 def _BuildAdbCmd(cls, args, device_serial, cpu_affinity=None):
76 if cpu_affinity is not None: 65 if cpu_affinity is not None:
77 cmd = ['taskset', '-c', str(cpu_affinity)] 66 cmd = ['taskset', '-c', str(cpu_affinity)]
78 else: 67 else:
79 cmd = [] 68 cmd = []
80 cmd.append(cls._GetAdbPath()) 69 cmd.append(constants.GetAdbPath())
81 if device_serial is not None: 70 if device_serial is not None:
82 cmd.extend(['-s', device_serial]) 71 cmd.extend(['-s', device_serial])
83 cmd.extend(args) 72 cmd.extend(args)
84 return cmd 73 return cmd
74 # pylint: enable=unused-argument
85 75
86 # pylint: disable=unused-argument 76 # pylint: disable=unused-argument
87 @classmethod 77 @classmethod
88 @decorators.WithTimeoutAndRetries 78 @decorators.WithTimeoutAndRetries
89 def _RunAdbCmd(cls, args, timeout=None, retries=None, device_serial=None, 79 def _RunAdbCmd(cls, args, timeout=None, retries=None, device_serial=None,
90 check_error=True, cpu_affinity=None): 80 check_error=True, cpu_affinity=None):
91 # pylint: disable=no-member 81 # pylint: disable=no-member
92 status, output = cmd_helper.GetCmdStatusAndOutputWithTimeout( 82 status, output = cmd_helper.GetCmdStatusAndOutputWithTimeout(
93 cls._BuildAdbCmd(args, device_serial, cpu_affinity=cpu_affinity), 83 cls._BuildAdbCmd(args, device_serial, cpu_affinity=cpu_affinity),
94 timeout_retry.CurrentTimeoutThreadGroup().GetRemainingTime()) 84 timeout_retry.CurrentTimeoutThreadGroup().GetRemainingTime())
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 @property 655 @property
666 def is_emulator(self): 656 def is_emulator(self):
667 return _EMULATOR_RE.match(self._device_serial) 657 return _EMULATOR_RE.match(self._device_serial)
668 658
669 @property 659 @property
670 def is_ready(self): 660 def is_ready(self):
671 try: 661 try:
672 return self.GetState() == _READY_STATE 662 return self.GetState() == _READY_STATE
673 except device_errors.CommandFailedError: 663 except device_errors.CommandFailedError:
674 return False 664 return False
OLDNEW
« no previous file with comments | « build/android/devil/android/sdk/aapt.py ('k') | build/android/devil/android/sdk/dexdump.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698