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 android_commands # pylint: disable=F0401 | 19 from pylib import android_commands # pylint: disable=F0401 |
20 from pylib import cmd_helper # pylint: disable=F0401 | 20 from pylib import cmd_helper # pylint: disable=F0401 |
21 from pylib import forwarder # pylint: disable=F0401 | 21 from pylib import forwarder # pylint: disable=F0401 |
22 from pylib import ports # pylint: disable=F0401 | 22 from pylib import ports # pylint: disable=F0401 |
23 from pylib import valgrind_tools # pylint: disable=F0401 | |
24 except Exception: | 23 except Exception: |
25 android_commands = None | 24 android_commands = None |
26 | 25 |
27 | 26 |
28 def IsAndroidSupported(): | 27 def IsAndroidSupported(): |
29 return android_commands != None | 28 return android_commands != None |
30 | 29 |
31 | 30 |
32 def GetAttachedDevices(): | 31 def GetAttachedDevices(): |
33 """Returns a list of attached, online android devices. | 32 """Returns a list of attached, online android devices. |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 if not buildtype: | 148 if not buildtype: |
150 return (HasForwarder(buildtype='Release') or | 149 return (HasForwarder(buildtype='Release') or |
151 HasForwarder(buildtype='Debug')) | 150 HasForwarder(buildtype='Debug')) |
152 return (os.path.exists(os.path.join(GetOutDirectory(), buildtype, | 151 return (os.path.exists(os.path.join(GetOutDirectory(), buildtype, |
153 'device_forwarder')) and | 152 'device_forwarder')) and |
154 os.path.exists(os.path.join(GetOutDirectory(), buildtype, | 153 os.path.exists(os.path.join(GetOutDirectory(), buildtype, |
155 'host_forwarder'))) | 154 'host_forwarder'))) |
156 | 155 |
157 class Forwarder(object): | 156 class Forwarder(object): |
158 def __init__(self, adb, *port_pairs): | 157 def __init__(self, adb, *port_pairs): |
159 tool = valgrind_tools.BaseTool() | 158 self._adb = adb.Adb() |
160 self._host_port = port_pairs[0].local_port | 159 self._host_port = port_pairs[0].local_port |
161 | 160 |
162 new_port_pairs = [(port_pair.local_port, port_pair.remote_port) | 161 new_port_pairs = [(port_pair.local_port, port_pair.remote_port) |
163 for port_pair in port_pairs] | 162 for port_pair in port_pairs] |
164 | 163 |
165 self._forwarder = forwarder.Forwarder(adb.Adb(), Forwarder._GetBuildType()) | 164 self._port_pairs = new_port_pairs |
166 self._forwarder.Run(new_port_pairs, tool) | 165 forwarder.Forwarder.Map(new_port_pairs, self._adb) |
167 | 166 |
168 @staticmethod | 167 @staticmethod |
169 def _GetBuildType(): | 168 def _GetBuildType(): |
170 assert HasForwarder() | 169 assert HasForwarder() |
171 return 'Debug' if HasForwarder('Debug') else 'Release' | 170 return 'Debug' if HasForwarder('Debug') else 'Release' |
172 | 171 |
173 @staticmethod | |
174 def KillHost(): | |
175 forwarder.Forwarder.KillHost(Forwarder._GetBuildType()) | |
176 | |
177 @staticmethod | |
178 def KillDevice(adb): | |
179 forwarder.Forwarder.KillDevice(adb.Adb(), valgrind_tools.BaseTool()) | |
180 | |
181 @property | 172 @property |
182 def url(self): | 173 def url(self): |
183 assert self._forwarder | |
184 return 'http://localhost:%i' % self._host_port | 174 return 'http://localhost:%i' % self._host_port |
185 | 175 |
186 def Close(self): | 176 def Close(self): |
187 if self._forwarder: | 177 for (device_port, _) in self._port_pairs: |
188 self._forwarder.Close() | 178 forwarder.Forwarder.UnmapDevicePort(device_port, self._adb) |
189 self._forwarder = None | |
OLD | NEW |