OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import argparse | 6 import argparse |
7 import atexit | 7 import atexit |
8 import logging | 8 import logging |
9 import threading | 9 import threading |
10 import os | 10 import os |
(...skipping 18 matching lines...) Expand all Loading... |
29 'chromium', | 29 'chromium', |
30 ] | 30 ] |
31 | 31 |
32 USAGE = ("android_mojo_shell.py " | 32 USAGE = ("android_mojo_shell.py " |
33 "[--args-for=<mojo-app>] " | 33 "[--args-for=<mojo-app>] " |
34 "[--content-handlers=<handlers>] " | 34 "[--content-handlers=<handlers>] " |
35 "[--enable-external-applications] " | 35 "[--enable-external-applications] " |
36 "[--disable-cache] " | 36 "[--disable-cache] " |
37 "[--enable-multiprocess] " | 37 "[--enable-multiprocess] " |
38 "[--url-mappings=from1=to1,from2=to2] " | 38 "[--url-mappings=from1=to1,from2=to2] " |
39 "[<mojo-app> | --no-url] " | 39 "[<mojo-app>] " |
40 """ | 40 """ |
41 | 41 |
42 A <mojo-app> is a Mojo URL or a Mojo URL and arguments within quotes. | 42 A <mojo-app> is a Mojo URL or a Mojo URL and arguments within quotes. |
43 Example: mojo_shell "mojo:js_standalone test.js". | 43 Example: mojo_shell "mojo:js_standalone test.js". |
44 <url-lib-path> is searched for shared libraries named by mojo URLs. | 44 <url-lib-path> is searched for shared libraries named by mojo URLs. |
45 The value of <handlers> is a comma separated list like: | 45 The value of <handlers> is a comma separated list like: |
46 text/html,mojo:html_viewer,application/javascript,mojo:js_content_handler | 46 text/html,mojo:html_viewer,application/javascript,mojo:js_content_handler |
47 """) | 47 """) |
48 | 48 |
49 def GetHandlerForPath(base_path): | 49 def GetHandlerForPath(base_path): |
(...skipping 13 matching lines...) Expand all Loading... |
63 def main(): | 63 def main(): |
64 logging.basicConfig() | 64 logging.basicConfig() |
65 | 65 |
66 parser = argparse.ArgumentParser(usage=USAGE) | 66 parser = argparse.ArgumentParser(usage=USAGE) |
67 | 67 |
68 debug_group = parser.add_mutually_exclusive_group() | 68 debug_group = parser.add_mutually_exclusive_group() |
69 debug_group.add_argument('--debug', help='Debug build (default)', | 69 debug_group.add_argument('--debug', help='Debug build (default)', |
70 default=True, action='store_true') | 70 default=True, action='store_true') |
71 debug_group.add_argument('--release', help='Release build', default=False, | 71 debug_group.add_argument('--release', help='Release build', default=False, |
72 dest='debug', action='store_false') | 72 dest='debug', action='store_false') |
73 parser.add_argument('--no-url', | |
74 help='Allows not to provide a application URL', | |
75 action='store_true') | |
76 launcher_args, args = parser.parse_known_args() | 73 launcher_args, args = parser.parse_known_args() |
77 | 74 |
78 paths = Paths(Config(target_os=Config.OS_ANDROID, | 75 paths = Paths(Config(target_os=Config.OS_ANDROID, |
79 is_debug=launcher_args.debug)) | 76 is_debug=launcher_args.debug)) |
80 constants.SetOutputDirectort(paths.build_dir) | 77 constants.SetOutputDirectort(paths.build_dir) |
81 | 78 |
82 httpd = SocketServer.TCPServer(('127.0.0.1', 0), | 79 httpd = SocketServer.TCPServer(('127.0.0.1', 0), |
83 GetHandlerForPath(paths.build_dir)) | 80 GetHandlerForPath(paths.build_dir)) |
84 atexit.register(httpd.shutdown) | 81 atexit.register(httpd.shutdown) |
85 port = httpd.server_address[1] | 82 port = httpd.server_address[1] |
(...skipping 12 matching lines...) Expand all Loading... |
98 | 95 |
99 cmd = ('am start' | 96 cmd = ('am start' |
100 ' -W' | 97 ' -W' |
101 ' -S' | 98 ' -S' |
102 ' -a android.intent.action.VIEW' | 99 ' -a android.intent.action.VIEW' |
103 ' -n org.chromium.mojo_shell_apk/.MojoShellActivity') | 100 ' -n org.chromium.mojo_shell_apk/.MojoShellActivity') |
104 | 101 |
105 parameters = [ | 102 parameters = [ |
106 '--origin=http://127.0.0.1:%d/' % device_port | 103 '--origin=http://127.0.0.1:%d/' % device_port |
107 ] | 104 ] |
108 | 105 parameters += args |
109 url = None | |
110 if launcher_args.no_url: | |
111 parameters += args | |
112 else: | |
113 url = args[-1] | |
114 parameters += args[:-1] | |
115 | |
116 cmd += ' --esa parameters \"%s\"' % ','.join(parameters) | 106 cmd += ' --esa parameters \"%s\"' % ','.join(parameters) |
117 | 107 |
118 if url: | |
119 cmd += ' -d %s' % url | |
120 | |
121 device.RunShellCommand('logcat -c') | 108 device.RunShellCommand('logcat -c') |
122 device.RunShellCommand(cmd) | 109 device.RunShellCommand(cmd) |
123 os.system("%s logcat -s %s" % (constants.GetAdbPath(), ' '.join(TAGS))) | 110 os.system("%s logcat -s %s" % (constants.GetAdbPath(), ' '.join(TAGS))) |
124 device.RunShellCommand("am force-stop org.chromium.mojo_shell_apk") | 111 device.RunShellCommand("am force-stop org.chromium.mojo_shell_apk") |
125 return 0 | 112 return 0 |
126 | 113 |
127 if __name__ == "__main__": | 114 if __name__ == "__main__": |
128 sys.exit(main()) | 115 sys.exit(main()) |
OLD | NEW |