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

Side by Side Diff: build/android/pylib/android_commands.py

Issue 19774008: Do not reboot emulator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed nits. Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « build/android/buildbot/bb_device_steps.py ('k') | build/android/pylib/utils/emulator.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 (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 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 """Provides an interface to communicate with the device via the adb command. 5 """Provides an interface to communicate with the device via the adb command.
6 6
7 Assumes adb binary is currently on system path. 7 Assumes adb binary is currently on system path.
8 """ 8 """
9 9
10 import collections 10 import collections
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 KEYCODE_DPAD_UP = 19 58 KEYCODE_DPAD_UP = 19
59 KEYCODE_DPAD_DOWN = 20 59 KEYCODE_DPAD_DOWN = 20
60 KEYCODE_DPAD_RIGHT = 22 60 KEYCODE_DPAD_RIGHT = 22
61 KEYCODE_ENTER = 66 61 KEYCODE_ENTER = 66
62 KEYCODE_MENU = 82 62 KEYCODE_MENU = 82
63 63
64 MD5SUM_DEVICE_FOLDER = constants.TEST_EXECUTABLE_DIR + '/md5sum/' 64 MD5SUM_DEVICE_FOLDER = constants.TEST_EXECUTABLE_DIR + '/md5sum/'
65 MD5SUM_DEVICE_PATH = MD5SUM_DEVICE_FOLDER + 'md5sum_bin' 65 MD5SUM_DEVICE_PATH = MD5SUM_DEVICE_FOLDER + 'md5sum_bin'
66 MD5SUM_LD_LIBRARY_PATH = 'LD_LIBRARY_PATH=%s' % MD5SUM_DEVICE_FOLDER 66 MD5SUM_LD_LIBRARY_PATH = 'LD_LIBRARY_PATH=%s' % MD5SUM_DEVICE_FOLDER
67 67
68 def GetEmulators():
69 """Returns a list of emulators. Does not filter by status (e.g. offline).
70
71 Both devices starting with 'emulator' will be returned in below output:
72
73 * daemon not running. starting it now on port 5037 *
74 * daemon started successfully *
75 List of devices attached
76 027c10494100b4d7 device
77 emulator-5554 offline
78 emulator-5558 device
79 """
80 re_device = re.compile('^emulator-[0-9]+', re.MULTILINE)
81 devices = re_device.findall(cmd_helper.GetCmdOutput([constants.ADB_PATH,
82 'devices']))
83 return devices
84
85 68
86 def GetAVDs(): 69 def GetAVDs():
87 """Returns a list of AVDs.""" 70 """Returns a list of AVDs."""
88 re_avd = re.compile('^[ ]+Name: ([a-zA-Z0-9_:.-]+)', re.MULTILINE) 71 re_avd = re.compile('^[ ]+Name: ([a-zA-Z0-9_:.-]+)', re.MULTILINE)
89 avds = re_avd.findall(cmd_helper.GetCmdOutput(['android', 'list', 'avd'])) 72 avds = re_avd.findall(cmd_helper.GetCmdOutput(['android', 'list', 'avd']))
90 return avds 73 return avds
91 74
92 75
93 def GetAttachedDevices(): 76 def GetAttachedDevices(hardware=True, emulator=True, offline=False):
94 """Returns a list of attached, online android devices. 77 """Returns a list of attached, android devices and emulators.
95 78
96 If a preferred device has been set with ANDROID_SERIAL, it will be first in 79 If a preferred device has been set with ANDROID_SERIAL, it will be first in
97 the returned list. 80 the returned list. The arguments specify what devices to include in the list.
98 81
99 Example output: 82 Example output:
100 83
101 * daemon not running. starting it now on port 5037 * 84 * daemon not running. starting it now on port 5037 *
102 * daemon started successfully * 85 * daemon started successfully *
103 List of devices attached 86 List of devices attached
104 027c10494100b4d7 device 87 027c10494100b4d7 device
105 emulator-5554 offline 88 emulator-5554 offline
89
90 Args:
91 hardware: Include attached actual devices that are online.
92 emulator: Include emulators (i.e. AVD's) currently on host.
93 offline: Include devices and emulators that are offline.
94
95 Returns: List of devices.
106 """ 96 """
97 adb_devices_output = cmd_helper.GetCmdOutput([constants.ADB_PATH, 'devices'])
98
107 re_device = re.compile('^([a-zA-Z0-9_:.-]+)\tdevice$', re.MULTILINE) 99 re_device = re.compile('^([a-zA-Z0-9_:.-]+)\tdevice$', re.MULTILINE)
108 devices = re_device.findall(cmd_helper.GetCmdOutput([constants.ADB_PATH, 100 online_devices = re_device.findall(adb_devices_output)
109 'devices'])) 101
102 re_device = re.compile('^(emulator-[0-9]+)\tdevice', re.MULTILINE)
103 emulator_devices = re_device.findall(adb_devices_output)
104
105 re_device = re.compile('^([a-zA-Z0-9_:.-]+)\toffline$', re.MULTILINE)
106 offline_devices = re_device.findall(adb_devices_output)
107
108 devices = []
109 # First determine list of online devices (e.g. hardware and/or emulator).
110 if hardware and emulator:
111 devices = online_devices
112 elif hardware:
113 devices = [device for device in online_devices
114 if device not in emulator_devices]
115 elif emulator:
116 devices = emulator_devices
117
118 # Now add offline devices if offline is true
119 if offline:
120 devices = devices + offline_devices
121
110 preferred_device = os.environ.get('ANDROID_SERIAL') 122 preferred_device = os.environ.get('ANDROID_SERIAL')
111 if preferred_device in devices: 123 if preferred_device in devices:
112 devices.remove(preferred_device) 124 devices.remove(preferred_device)
113 devices.insert(0, preferred_device) 125 devices.insert(0, preferred_device)
114 return devices 126 return devices
115 127
116 128
117 def GetAttachedOfflineDevices():
118 """Returns a list of attached, offline android devices.
119
120 Returns: List of devices with status 'offline'.
121 """
122 re_device = re.compile('^([a-zA-Z0-9_:.-]+)\toffline$', re.MULTILINE)
123 return re_device.findall(cmd_helper.GetCmdOutput([constants.ADB_PATH,
124 'devices']))
125
126
127 def IsDeviceAttached(device): 129 def IsDeviceAttached(device):
128 """Return true if the device is attached and online.""" 130 """Return true if the device is attached and online."""
129 return device in GetAttachedDevices() 131 return device in GetAttachedDevices()
130 132
131 133
132 def _GetFilesFromRecursiveLsOutput(path, ls_output, re_file, utc_offset=None): 134 def _GetFilesFromRecursiveLsOutput(path, ls_output, re_file, utc_offset=None):
133 """Gets a list of files from `ls` command output. 135 """Gets a list of files from `ls` command output.
134 136
135 Python's os.walk isn't used because it doesn't work over adb shell. 137 Python's os.walk isn't used because it doesn't work over adb shell.
136 138
(...skipping 1301 matching lines...) Expand 10 before | Expand all | Expand 10 after
1438 """ 1440 """
1439 def __init__(self, output): 1441 def __init__(self, output):
1440 self._output = output 1442 self._output = output
1441 1443
1442 def write(self, data): 1444 def write(self, data):
1443 data = data.replace('\r\r\n', '\n') 1445 data = data.replace('\r\r\n', '\n')
1444 self._output.write(data) 1446 self._output.write(data)
1445 1447
1446 def flush(self): 1448 def flush(self):
1447 self._output.flush() 1449 self._output.flush()
OLDNEW
« no previous file with comments | « build/android/buildbot/bb_device_steps.py ('k') | build/android/pylib/utils/emulator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698