| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 from telemetry.internal.util import atexit_with_log | 5 from telemetry.internal.util import atexit_with_log |
| 6 import logging | 6 import logging |
| 7 import subprocess | 7 import subprocess |
| 8 | 8 |
| 9 from telemetry.internal import forwarders | 9 from telemetry.internal import forwarders |
| 10 | 10 |
| 11 try: | 11 try: |
| 12 from devil.android import forwarder | 12 from devil.android import forwarder |
| 13 except ImportError: | 13 except ImportError: |
| 14 forwarder = None | 14 forwarder = None |
| 15 | 15 |
| 16 | 16 |
| 17 class AndroidForwarderFactory(forwarders.ForwarderFactory): | 17 class AndroidForwarderFactory(forwarders.ForwarderFactory): |
| 18 | 18 |
| 19 def __init__(self, device): | 19 def __init__(self, device): |
| 20 super(AndroidForwarderFactory, self).__init__() | 20 super(AndroidForwarderFactory, self).__init__() |
| 21 self._device = device | 21 self._device = device |
| 22 | 22 |
| 23 def Create(self, port_pairs): | 23 def Create(self, port_pair): |
| 24 try: | 24 try: |
| 25 return AndroidForwarder(self._device, port_pairs) | 25 return AndroidForwarder(self._device, port_pair) |
| 26 except Exception: | 26 except Exception: |
| 27 try: | 27 try: |
| 28 logging.warning('Failed to create forwarder. ' | 28 logging.warning('Failed to create forwarder. ' |
| 29 'Currently forwarded connections:') | 29 'Currently forwarded connections:') |
| 30 for line in self._device.adb.ForwardList().splitlines(): | 30 for line in self._device.adb.ForwardList().splitlines(): |
| 31 logging.warning(' %s', line) | 31 logging.warning(' %s', line) |
| 32 except Exception: | 32 except Exception: |
| 33 logging.warning('Exception raised while listing forwarded connections.') | 33 logging.warning('Exception raised while listing forwarded connections.') |
| 34 | 34 |
| 35 logging.warning('Device tcp sockets in use:') | 35 logging.warning('Device tcp sockets in use:') |
| (...skipping 10 matching lines...) Expand all Loading... |
| 46 if 'webpagereplay' in line: | 46 if 'webpagereplay' in line: |
| 47 logging.warning(' %s', line) | 47 logging.warning(' %s', line) |
| 48 except Exception: | 48 except Exception: |
| 49 logging.warning('Exception raised while listing WPR intances.') | 49 logging.warning('Exception raised while listing WPR intances.') |
| 50 | 50 |
| 51 raise | 51 raise |
| 52 | 52 |
| 53 | 53 |
| 54 class AndroidForwarder(forwarders.Forwarder): | 54 class AndroidForwarder(forwarders.Forwarder): |
| 55 | 55 |
| 56 def __init__(self, device, port_pairs): | 56 def __init__(self, device, port_pair): |
| 57 super(AndroidForwarder, self).__init__(port_pairs) | 57 super(AndroidForwarder, self).__init__(port_pair) |
| 58 self._device = device | 58 self._device = device |
| 59 forwarder.Forwarder.Map([(p.remote_port, p.local_port) | 59 forwarder.Forwarder.Map( |
| 60 for p in port_pairs if p], self._device) | 60 [(port_pair.remote_port, port_pair.local_port)], self._device) |
| 61 self._port_pairs = forwarders.PortPairs(*[ | 61 self._port_pair = ( |
| 62 forwarders.PortPair( | 62 forwarders.PortPair( |
| 63 p.local_port, | 63 port_pair.local_port, |
| 64 forwarder.Forwarder.DevicePortForHostPort(p.local_port)) | 64 forwarder.Forwarder.DevicePortForHostPort(port_pair.local_port))) |
| 65 if p else None for p in port_pairs]) | |
| 66 atexit_with_log.Register(self.Close) | 65 atexit_with_log.Register(self.Close) |
| 67 # TODO(tonyg): Verify that each port can connect to host. | 66 # TODO(tonyg): Verify that each port can connect to host. |
| 68 | 67 |
| 69 def Close(self): | 68 def Close(self): |
| 70 if self._forwarding: | 69 if self._forwarding: |
| 71 for port_pair in self._port_pairs: | 70 forwarder.Forwarder.UnmapDevicePort( |
| 72 if port_pair: | 71 self._port_pair.remote_port, self._device) |
| 73 forwarder.Forwarder.UnmapDevicePort( | 72 super(AndroidForwarder, self).Close() |
| 74 port_pair.remote_port, self._device) | |
| 75 super(AndroidForwarder, self).Close() | |
| OLD | NEW |