Chromium Code Reviews| Index: build/android/pylib/android_commands.py |
| diff --git a/build/android/pylib/android_commands.py b/build/android/pylib/android_commands.py |
| index 4cfd04fd1185604f45695093e47f2c8d1f4bd934..9ca49a92a5d7caa4d882d2feadef52dd82bd28a1 100644 |
| --- a/build/android/pylib/android_commands.py |
| +++ b/build/android/pylib/android_commands.py |
| @@ -65,23 +65,6 @@ MD5SUM_DEVICE_FOLDER = constants.TEST_EXECUTABLE_DIR + '/md5sum/' |
| MD5SUM_DEVICE_PATH = MD5SUM_DEVICE_FOLDER + 'md5sum_bin' |
| MD5SUM_LD_LIBRARY_PATH = 'LD_LIBRARY_PATH=%s' % MD5SUM_DEVICE_FOLDER |
| -def GetEmulators(): |
| - """Returns a list of emulators. Does not filter by status (e.g. offline). |
| - |
| - Both devices starting with 'emulator' will be returned in below output: |
| - |
| - * daemon not running. starting it now on port 5037 * |
| - * daemon started successfully * |
| - List of devices attached |
| - 027c10494100b4d7 device |
| - emulator-5554 offline |
| - emulator-5558 device |
| - """ |
| - re_device = re.compile('^emulator-[0-9]+', re.MULTILINE) |
| - devices = re_device.findall(cmd_helper.GetCmdOutput([constants.ADB_PATH, |
| - 'devices'])) |
| - return devices |
| - |
| def GetAVDs(): |
| """Returns a list of AVDs.""" |
| @@ -90,11 +73,11 @@ def GetAVDs(): |
| return avds |
| -def GetAttachedDevices(): |
| - """Returns a list of attached, online android devices. |
| +def GetAttachedDevices(hardware=True, emulator=True, offline=False): |
| + """Returns a list of attached, android devices and emulators. |
| If a preferred device has been set with ANDROID_SERIAL, it will be first in |
| - the returned list. |
| + 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.
|
| Example output: |
| @@ -104,9 +87,31 @@ def GetAttachedDevices(): |
| 027c10494100b4d7 device |
| emulator-5554 offline |
| """ |
| + adb_devices_output = cmd_helper.GetCmdOutput([constants.ADB_PATH, 'devices']) |
| + |
| re_device = re.compile('^([a-zA-Z0-9_:.-]+)\tdevice$', re.MULTILINE) |
| - devices = re_device.findall(cmd_helper.GetCmdOutput([constants.ADB_PATH, |
| - 'devices'])) |
| + online_devices = re_device.findall(adb_devices_output) |
| + |
| + 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.
|
| + emulator_devices = re_device.findall(adb_devices_output) |
| + |
| + re_device = re.compile('^([a-zA-Z0-9_:.-]+)\toffline$', re.MULTILINE) |
| + offline_devices = re_device.findall(adb_devices_output) |
| + |
| + devices = [] |
| + # First determine list of online devices (e.g. hardware and/or emulator). |
| + if hardware and emulator: |
| + devices = online_devices |
| + elif hardware: |
| + devices = [device for device in online_devices |
| + if device not in emulator_devices] |
| + elif emulator: |
| + devices = emulator_devices |
| + |
| + # Now add offline devices if offline is true |
| + if offline: |
| + devices = devices + offline_devices |
| + |
| preferred_device = os.environ.get('ANDROID_SERIAL') |
| if preferred_device in devices: |
| devices.remove(preferred_device) |
| @@ -114,16 +119,6 @@ def GetAttachedDevices(): |
| return devices |
| -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
|
| - """Returns a list of attached, offline android devices. |
| - |
| - Returns: List of devices with status 'offline'. |
| - """ |
| - re_device = re.compile('^([a-zA-Z0-9_:.-]+)\toffline$', re.MULTILINE) |
| - return re_device.findall(cmd_helper.GetCmdOutput([constants.ADB_PATH, |
| - 'devices'])) |
| - |
| - |
| def IsDeviceAttached(device): |
| """Return true if the device is attached and online.""" |
| return device in GetAttachedDevices() |