Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Unified Diff: mojo/tools/android_mojo_shell.py

Issue 803573002: Add a launcher script for the mojo shell on android. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Style fixes Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/tools/android_mojo_shell.py
diff --git a/mojo/tools/android_mojo_shell.py b/mojo/tools/android_mojo_shell.py
new file mode 100755
index 0000000000000000000000000000000000000000..b3c65e194db3d7f481bd19adbc1d47b23c37cb8e
--- /dev/null
+++ b/mojo/tools/android_mojo_shell.py
@@ -0,0 +1,96 @@
+#!/usr/bin/env python
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import argparse
+import atexit
+import logging
+import threading
+import os
+import sys
+
+import SimpleHTTPServer
+import SocketServer
+
+from mopy.config import Config
+from mopy.paths import Paths
+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
+
+sys.path.insert(0, os.path.join(paths.src_root, 'build', 'android'))
+from pylib import android_commands
+from pylib import constants
+from pylib import forwarder
+
+TAGS = [
+ 'AndroidHandler',
+ 'MojoMain',
+ 'MojoShellActivity',
+ 'MojoShellApplication',
+ 'chromium',
+]
+
+class MojoApplicationRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
+ """
+ Handle for SocketServer.TCPServer that will serve the files from the build
+ directory over http.
+ """
+
+ def translate_path(self, path):
+ path_from_current = (
+ SimpleHTTPServer.SimpleHTTPRequestHandler.translate_path(self, path))
+ return os.path.join(paths.build_dir, os.path.relpath(path_from_current))
+
+def main():
+ logging.basicConfig()
+ constants.SetOutputDirectort(paths.build_dir)
+
+ httpd = SocketServer.TCPServer(('127.0.0.1', 0),
+ MojoApplicationRequestHandler)
+ atexit.register(httpd.shutdown)
+ port = httpd.server_address[1]
+
+ http_thread = threading.Thread(target=httpd.serve_forever)
+ http_thread.daemon = True
+ http_thread.start()
+
+ device = android_commands.AndroidCommands(
+ android_commands.GetAttachedDevices()[0])
+ device.EnableAdbRoot()
+
+ atexit.register(forwarder.Forwarder.UnmapAllDevicePorts, device)
+ forwarder.Forwarder.Map([(0, port)], device)
+ device_port = forwarder.Forwarder.DevicePortForHostPort(port)
+
+ cmd = ('am start'
+ ' -W'
+ ' -S'
+ ' -a android.intent.action.VIEW'
+ ' -n org.chromium.mojo_shell_apk/.MojoShellActivity')
+
+ parameters = [
+ '--origin=http://127.0.0.1:%d/' % device_port
+ ]
+
+ 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
+ args = sys.argv[1:]
+ if len(args):
+ parameters += args[:-1]
+ if args[-1].startswith('--'):
+ parameters += [args[-1]]
+ else:
+ url = args[-1]
+
+ cmd += ' --esa parameters \"%s\"' % ','.join(parameters)
+
+ if url:
+ cmd += ' -d %s' % url
+
+ device.RunShellCommand('logcat -c')
+ device.RunShellCommand(cmd)
+ os.system("%s logcat -s %s" % (constants.GetAdbPath(), ' '.join(TAGS)))
+ device.RunShellCommand("am force-stop org.chromium.mojo_shell_apk")
+ return 0
+
+if __name__ == "__main__":
+ sys.exit(main())
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698