cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / build / android / adb_reverse_forwarder.py
blob0ebe56d094145f74fd53a5e3aa4a0164acf04cf7
1 #!/usr/bin/env python
3 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
7 """Command line tool for forwarding ports from a device to the host.
9 Allows an Android device to connect to services running on the host machine,
10 i.e., "adb forward" in reverse. Requires |host_forwarder| and |device_forwarder|
11 to be built.
12 """
14 import logging
15 import optparse
16 import sys
17 import time
19 from devil.android import device_blacklist
20 from devil.android import device_errors
21 from devil.android import device_utils
22 from devil.utils import run_tests_helper
23 from pylib import constants
24 from pylib import forwarder
27 def main(argv):
28 parser = optparse.OptionParser(usage='Usage: %prog [options] device_port '
29 'host_port [device_port_2 host_port_2] ...',
30 description=__doc__)
31 parser.add_option('-v',
32 '--verbose',
33 dest='verbose_count',
34 default=0,
35 action='count',
36 help='Verbose level (multiple times for more)')
37 parser.add_option('--device',
38 help='Serial number of device we should use.')
39 parser.add_option('--blacklist-file', help='Device blacklist JSON file.')
40 parser.add_option('--debug', action='store_const', const='Debug',
41 dest='build_type', default='Release',
42 help='Use Debug build of host tools instead of Release.')
44 options, args = parser.parse_args(argv)
45 run_tests_helper.SetLogLevel(options.verbose_count)
47 if len(args) < 2 or not len(args) % 2:
48 parser.error('Need even number of port pairs')
49 sys.exit(1)
51 try:
52 port_pairs = [int(a) for a in args[1:]]
53 port_pairs = zip(port_pairs[::2], port_pairs[1::2])
54 except ValueError:
55 parser.error('Bad port number')
56 sys.exit(1)
58 if options.blacklist_file:
59 blacklist = device_blacklist.Blacklist(options.blacklist_file)
60 else:
61 blacklist = None
63 devices = device_utils.DeviceUtils.HealthyDevices(blacklist)
65 if options.device:
66 device = next((d for d in devices if d == options.device), None)
67 if not device:
68 raise device_errors.DeviceUnreachableError(options.device)
69 elif devices:
70 device = devices[0]
71 logging.info('No device specified. Defaulting to %s', devices[0])
72 else:
73 raise device_errors.NoDevicesError()
75 constants.SetBuildType(options.build_type)
76 try:
77 forwarder.Forwarder.Map(port_pairs, device)
78 while True:
79 time.sleep(60)
80 except KeyboardInterrupt:
81 sys.exit(0)
82 finally:
83 forwarder.Forwarder.UnmapAllDevicePorts(device)
85 if __name__ == '__main__':
86 main(sys.argv)