Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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. |
|
frankf
2013/07/19 23:19:20
Add Args section, describing each argument.
navabi
2013/07/20 01:02:57
Done.
| |
| 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 |
| 106 """ | 89 """ |
| 90 adb_devices_output = cmd_helper.GetCmdOutput([constants.ADB_PATH, 'devices']) | |
| 91 | |
| 107 re_device = re.compile('^([a-zA-Z0-9_:.-]+)\tdevice$', re.MULTILINE) | 92 re_device = re.compile('^([a-zA-Z0-9_:.-]+)\tdevice$', re.MULTILINE) |
| 108 devices = re_device.findall(cmd_helper.GetCmdOutput([constants.ADB_PATH, | 93 online_devices = re_device.findall(adb_devices_output) |
| 109 'devices'])) | 94 |
| 95 re_device = re.compile('^emulator-[0-9]+', re.MULTILINE) | |
|
frankf
2013/07/19 23:19:20
This includes both online and offline emulators ri
navabi
2013/07/20 01:02:57
Good catch.
| |
| 96 emulator_devices = re_device.findall(adb_devices_output) | |
| 97 | |
| 98 re_device = re.compile('^([a-zA-Z0-9_:.-]+)\toffline$', re.MULTILINE) | |
| 99 offline_devices = re_device.findall(adb_devices_output) | |
| 100 | |
| 101 devices = [] | |
| 102 # First determine list of online devices (e.g. hardware and/or emulator). | |
| 103 if hardware and emulator: | |
| 104 devices = online_devices | |
| 105 elif hardware: | |
| 106 devices = [device for device in online_devices | |
| 107 if device not in emulator_devices] | |
| 108 elif emulator: | |
| 109 devices = emulator_devices | |
| 110 | |
| 111 # Now add offline devices if offline is true | |
| 112 if offline: | |
| 113 devices = devices + offline_devices | |
| 114 | |
| 110 preferred_device = os.environ.get('ANDROID_SERIAL') | 115 preferred_device = os.environ.get('ANDROID_SERIAL') |
| 111 if preferred_device in devices: | 116 if preferred_device in devices: |
| 112 devices.remove(preferred_device) | 117 devices.remove(preferred_device) |
| 113 devices.insert(0, preferred_device) | 118 devices.insert(0, preferred_device) |
| 114 return devices | 119 return devices |
| 115 | 120 |
| 116 | 121 |
| 117 def GetAttachedOfflineDevices(): | |
|
frankf
2013/07/19 23:19:20
You need update device_status_check
navabi
2013/07/20 01:02:57
device_status_check moved to buildbot/bb_device_st
| |
| 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): | 122 def IsDeviceAttached(device): |
| 128 """Return true if the device is attached and online.""" | 123 """Return true if the device is attached and online.""" |
| 129 return device in GetAttachedDevices() | 124 return device in GetAttachedDevices() |
| 130 | 125 |
| 131 | 126 |
| 132 def _GetFilesFromRecursiveLsOutput(path, ls_output, re_file, utc_offset=None): | 127 def _GetFilesFromRecursiveLsOutput(path, ls_output, re_file, utc_offset=None): |
| 133 """Gets a list of files from `ls` command output. | 128 """Gets a list of files from `ls` command output. |
| 134 | 129 |
| 135 Python's os.walk isn't used because it doesn't work over adb shell. | 130 Python's os.walk isn't used because it doesn't work over adb shell. |
| 136 | 131 |
| (...skipping 1301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1438 """ | 1433 """ |
| 1439 def __init__(self, output): | 1434 def __init__(self, output): |
| 1440 self._output = output | 1435 self._output = output |
| 1441 | 1436 |
| 1442 def write(self, data): | 1437 def write(self, data): |
| 1443 data = data.replace('\r\r\n', '\n') | 1438 data = data.replace('\r\r\n', '\n') |
| 1444 self._output.write(data) | 1439 self._output.write(data) |
| 1445 | 1440 |
| 1446 def flush(self): | 1441 def flush(self): |
| 1447 self._output.flush() | 1442 self._output.flush() |
| OLD | NEW |