OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
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 | |
4 # found in the LICENSE file. | |
5 | |
6 import argparse | |
7 import atexit | |
8 import logging | |
9 import threading | |
10 import os | |
11 import sys | |
12 | |
13 import SimpleHTTPServer | |
14 import SocketServer | |
15 | |
16 from mopy.config import Config | |
17 from mopy.paths import Paths | |
18 paths = Paths(Config(target_os=Config.OS_ANDROID)) | |
sky
2014/12/12 17:54:07
Don't you need to support build type, eg debug/rel
| |
19 | |
20 sys.path.insert(0, os.path.join(paths.src_root, 'build', 'android')) | |
21 from pylib import android_commands | |
22 from pylib import constants | |
23 from pylib import forwarder | |
24 | |
25 TAGS = [ | |
26 'AndroidHandler', | |
27 'MojoMain', | |
28 'MojoShellActivity', | |
29 'MojoShellApplication', | |
30 'chromium', | |
31 ] | |
32 | |
33 class MojoApplicationRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): | |
34 """ | |
35 Handle for SocketServer.TCPServer that will serve the files from the build | |
36 directory over http. | |
37 """ | |
38 | |
39 def translate_path(self, path): | |
40 path_from_current = ( | |
41 SimpleHTTPServer.SimpleHTTPRequestHandler.translate_path(self, path)) | |
42 return os.path.join(paths.build_dir, os.path.relpath(path_from_current)) | |
43 | |
44 def main(): | |
45 logging.basicConfig() | |
46 constants.SetOutputDirectort(paths.build_dir) | |
47 | |
48 httpd = SocketServer.TCPServer(('127.0.0.1', 0), | |
49 MojoApplicationRequestHandler) | |
50 atexit.register(httpd.shutdown) | |
51 port = httpd.server_address[1] | |
52 | |
53 http_thread = threading.Thread(target=httpd.serve_forever) | |
54 http_thread.daemon = True | |
55 http_thread.start() | |
56 | |
57 device = android_commands.AndroidCommands( | |
58 android_commands.GetAttachedDevices()[0]) | |
59 device.EnableAdbRoot() | |
60 | |
61 atexit.register(forwarder.Forwarder.UnmapAllDevicePorts, device) | |
62 forwarder.Forwarder.Map([(0, port)], device) | |
63 device_port = forwarder.Forwarder.DevicePortForHostPort(port) | |
64 | |
65 cmd = ('am start' | |
66 ' -W' | |
67 ' -S' | |
68 ' -a android.intent.action.VIEW' | |
69 ' -n org.chromium.mojo_shell_apk/.MojoShellActivity') | |
70 | |
71 parameters = [ | |
72 '--origin=http://127.0.0.1:%d/' % device_port | |
73 ] | |
74 | |
75 url = None | |
sky
2014/12/12 17:54:07
One problem I have with this is that it isn't read
qsr
2014/12/15 14:11:22
The main reason I didn't do anything like this is
| |
76 args = sys.argv[1:] | |
77 if len(args): | |
78 parameters += args[:-1] | |
79 if args[-1].startswith('--'): | |
80 parameters += [args[-1]] | |
81 else: | |
82 url = args[-1] | |
83 | |
84 cmd += ' --esa parameters \"%s\"' % ','.join(parameters) | |
85 | |
86 if url: | |
87 cmd += ' -d %s' % url | |
88 | |
89 device.RunShellCommand('logcat -c') | |
90 device.RunShellCommand(cmd) | |
91 os.system("%s logcat -s %s" % (constants.GetAdbPath(), ' '.join(TAGS))) | |
92 device.RunShellCommand("am force-stop org.chromium.mojo_shell_apk") | |
93 return 0 | |
94 | |
95 if __name__ == "__main__": | |
96 sys.exit(main()) | |
OLD | NEW |