Chromium Code Reviews| Index: tools/android/loading/device_setup.py |
| diff --git a/tools/android/loading/device_setup.py b/tools/android/loading/device_setup.py |
| index 4d5d40b3050a382ea4d5a2b653ce1ff4964956fe..b8a9413a72aa4ce84a144656f5c617618bee2811 100644 |
| --- a/tools/android/loading/device_setup.py |
| +++ b/tools/android/loading/device_setup.py |
| @@ -3,6 +3,7 @@ |
| # found in the LICENSE file. |
| import contextlib |
| +import logging |
| import os |
| import sys |
| import time |
| @@ -11,6 +12,7 @@ _SRC_DIR = os.path.abspath(os.path.join( |
| os.path.dirname(__file__), '..', '..', '..')) |
| sys.path.append(os.path.join(_SRC_DIR, 'third_party', 'catapult', 'devil')) |
| +from devil.android import device_utils |
| from devil.android.sdk import intent |
| sys.path.append(os.path.join(_SRC_DIR, 'build', 'android')) |
| @@ -23,6 +25,25 @@ DEVTOOLS_PORT = 9222 |
| DEVTOOLS_HOSTNAME = 'localhost' |
| DEFAULT_CHROME_PACKAGE = 'chrome' |
| + |
| +class DeviceSetupException(Exception): |
| + def __init__(self, msg): |
| + super(DeviceSetupException, self).__init__(msg) |
| + logging.error(msg) |
| + |
| + |
| +def GetFirstDevice(): |
| + """Returns the first connected device. |
| + |
| + Raises: |
| + DeviceSetupException if there is no such device. |
| + """ |
| + devices = device_utils.DeviceUtils.HealthyDevices() |
| + if not devices: |
| + raise DeviceSetupException('No devices found') |
| + return devices[0] |
| + |
| + |
| @contextlib.contextmanager |
| def FlagReplacer(device, command_line_path, new_flags): |
| """Replaces chrome flags in a context, restores them afterwards. |
| @@ -83,6 +104,7 @@ def DeviceConnection(device, |
| Returns: |
| A context manager type which evaluates to a DevToolsConnection. |
| + |
|
Benoit L
2016/01/21 14:14:38
nit: no blank line here.
mattcary
2016/01/21 16:11:35
Done.
|
| """ |
| package_info = constants.PACKAGE_INFO[package] |
| command_line_path = '/data/local/chrome-command-line' |