| 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 """Brings in Chrome Android's android_commands module, which itself is a | 4 """Brings in Chrome Android's android_commands module, which itself is a |
| 5 thin(ish) wrapper around adb.""" | 5 thin(ish) wrapper around adb.""" |
| 6 import os | 6 import os |
| 7 import sys | 7 import sys |
| 8 | 8 |
| 9 # This is currently a thin wrapper around Chrome Android's | 9 # This is currently a thin wrapper around Chrome Android's |
| 10 # build scripts, located in chrome/build/android. This file exists mainly to | 10 # build scripts, located in chrome/build/android. This file exists mainly to |
| 11 # deal with locating the module. | 11 # deal with locating the module. |
| 12 | 12 |
| 13 # Get build/android scripts into our path. | 13 # Get build/android scripts into our path. |
| 14 sys.path.append( | 14 sys.path.append( |
| 15 os.path.abspath( | 15 os.path.abspath( |
| 16 os.path.join(os.path.dirname(__file__), | 16 os.path.join(os.path.dirname(__file__), |
| 17 '../../../build/android'))) | 17 '../../../build/android'))) |
| 18 try: | 18 try: |
| 19 from pylib import ( # pylint: disable=F0401 | 19 from pylib import android_commands # pylint: disable=F0401 |
| 20 android_commands as real_android_commands) | |
| 21 from pylib import forwarder # pylint: disable=F0401 | 20 from pylib import forwarder # pylint: disable=F0401 |
| 22 from pylib import valgrind_tools # pylint: disable=F0401 | 21 from pylib import valgrind_tools # pylint: disable=F0401 |
| 23 except Exception: | 22 except Exception: |
| 24 real_android_commands = None | 23 real_android_commands = None |
| 25 | 24 |
| 26 def IsAndroidSupported(): | 25 def IsAndroidSupported(): |
| 27 return real_android_commands != None | 26 return android_commands != None |
| 28 | 27 |
| 29 def GetAttachedDevices(): | 28 def GetAttachedDevices(): |
| 30 """Returns a list of attached, online android devices. | 29 """Returns a list of attached, online android devices. |
| 31 | 30 |
| 32 If a preferred device has been set with ANDROID_SERIAL, it will be first in | 31 If a preferred device has been set with ANDROID_SERIAL, it will be first in |
| 33 the returned list.""" | 32 the returned list.""" |
| 34 return real_android_commands.GetAttachedDevices() | 33 return android_commands.GetAttachedDevices() |
| 35 | 34 |
| 36 class ADBCommands(object): | 35 class AdbCommands(object): |
| 37 """A thin wrapper around ADB""" | 36 """A thin wrapper around ADB""" |
| 38 | 37 |
| 39 def __init__(self, device): | 38 def __init__(self, device): |
| 40 self._adb = real_android_commands.AndroidCommands(device) | 39 self._adb = android_commands.AndroidCommands(device) |
| 41 | 40 |
| 42 def Adb(self): | 41 def Adb(self): |
| 43 return self._adb | 42 return self._adb |
| 44 | 43 |
| 45 def Forward(self, local, remote): | 44 def Forward(self, local, remote): |
| 46 ret = self._adb.Adb().SendCommand('forward %s %s' % (local, remote)) | 45 ret = self._adb.Adb().SendCommand('forward %s %s' % (local, remote)) |
| 47 assert ret == '' | 46 assert ret == '' |
| 48 | 47 |
| 49 def RunShellCommand(self, command, timeout_time=20, log_result=False): | 48 def RunShellCommand(self, command, timeout_time=20, log_result=False): |
| 50 """Send a command to the adb shell and return the result. | 49 """Send a command to the adb shell and return the result. |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 159 |
| 161 @property | 160 @property |
| 162 def url(self): | 161 def url(self): |
| 163 assert self._forwarder | 162 assert self._forwarder |
| 164 return 'http://localhost:%i' % self._device_port | 163 return 'http://localhost:%i' % self._device_port |
| 165 | 164 |
| 166 def Close(self): | 165 def Close(self): |
| 167 if self._forwarder: | 166 if self._forwarder: |
| 168 self._forwarder.Close() | 167 self._forwarder.Close() |
| 169 self._forwarder = None | 168 self._forwarder = None |
| OLD | NEW |