| 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 | 4 |
| 5 import fcntl | 5 import fcntl |
| 6 import logging | 6 import logging |
| 7 import os | 7 import os |
| 8 import psutil | 8 import psutil |
| 9 import re | 9 import re |
| 10 import sys | 10 import sys |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 """Unmaps all the previously forwarded ports for the provided device. | 132 """Unmaps all the previously forwarded ports for the provided device. |
| 133 | 133 |
| 134 Args: | 134 Args: |
| 135 adb: An AndroidCommands instance. | 135 adb: An AndroidCommands instance. |
| 136 port_pairs: A list of tuples (device_port, host_port) to unmap. | 136 port_pairs: A list of tuples (device_port, host_port) to unmap. |
| 137 """ | 137 """ |
| 138 with _FileLock(Forwarder._LOCK_PATH): | 138 with _FileLock(Forwarder._LOCK_PATH): |
| 139 port_map = Forwarder._GetInstanceLocked( | 139 port_map = Forwarder._GetInstanceLocked( |
| 140 None, None)._device_to_host_port_map | 140 None, None)._device_to_host_port_map |
| 141 adb_serial = adb.Adb().GetSerialNumber() | 141 adb_serial = adb.Adb().GetSerialNumber() |
| 142 for ((device_serial, device_port), _) in port_map: | 142 for (device_serial, device_port) in port_map.keys(): |
| 143 if adb_serial == device_serial: | 143 if adb_serial == device_serial: |
| 144 Forwarder._UnmapDevicePortLocked(device_port, adb) | 144 Forwarder._UnmapDevicePortLocked(device_port, adb) |
| 145 | 145 |
| 146 @staticmethod | 146 @staticmethod |
| 147 def DevicePortForHostPort(host_port): | 147 def DevicePortForHostPort(host_port): |
| 148 """Returns the device port that corresponds to a given host port.""" | 148 """Returns the device port that corresponds to a given host port.""" |
| 149 with _FileLock(Forwarder._LOCK_PATH): | 149 with _FileLock(Forwarder._LOCK_PATH): |
| 150 (device_serial, device_port) = Forwarder._GetInstanceLocked( | 150 (device_serial, device_port) = Forwarder._GetInstanceLocked( |
| 151 None, None)._host_to_device_port_map.get(host_port) | 151 None, None)._host_to_device_port_map.get(host_port) |
| 152 return device_port | 152 return device_port |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 Forwarder._DEVICE_FORWARDER_PATH)) | 313 Forwarder._DEVICE_FORWARDER_PATH)) |
| 314 # TODO(pliard): Remove the following call to KillAllBlocking() when we are | 314 # TODO(pliard): Remove the following call to KillAllBlocking() when we are |
| 315 # sure that the old version of device_forwarder (not supporting | 315 # sure that the old version of device_forwarder (not supporting |
| 316 # 'kill-server') is not running on the bots anymore. | 316 # 'kill-server') is not running on the bots anymore. |
| 317 timeout_sec = 5 | 317 timeout_sec = 5 |
| 318 processes_killed = adb.KillAllBlocking('device_forwarder', timeout_sec) | 318 processes_killed = adb.KillAllBlocking('device_forwarder', timeout_sec) |
| 319 if not processes_killed: | 319 if not processes_killed: |
| 320 pids = adb.ExtractPid('device_forwarder') | 320 pids = adb.ExtractPid('device_forwarder') |
| 321 if pids: | 321 if pids: |
| 322 raise Exception('Timed out while killing device_forwarder') | 322 raise Exception('Timed out while killing device_forwarder') |
| OLD | NEW |