#!/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 logging
import sys

from mopy.config import Config
from mopy import android

def main():
  logging.basicConfig()

  parser = argparse.ArgumentParser("Helper for running mojo_shell")

  debug_group = parser.add_mutually_exclusive_group()
  debug_group.add_argument('--debug', help='Debug build (default)',
                           default=True, action='store_true')
  debug_group.add_argument('--release', help='Release build', default=False,
                           dest='debug', action='store_false')
  parser.add_argument('--target-cpu', help='CPU architecture to run for.',
                      choices=['x64', 'x86', 'arm'])
  parser.add_argument('--origin', help='Origin for mojo: URLs.')
  launcher_args, args = parser.parse_known_args()

  config = Config(target_os=Config.OS_ANDROID,
                  target_cpu=launcher_args.target_cpu,
                  is_debug=launcher_args.debug)

  extra_shell_args = android.PrepareShellRun(config, launcher_args.origin)
  args.extend(extra_shell_args)

  android.CleanLogs()
  p = android.ShowLogs()
  android.StartShell(args, sys.stdout, p.terminate)
  return 0


if __name__ == "__main__":
  sys.exit(main())

@@ -221,16 +221,54 @@
 rt sys%0A%0A
+from mopy.android import AndroidShell%0A
 from mop
@@ -299,24 +299,30 @@
 rom mopy
+.paths
  import 
 android%0A
@@ -313,23 +313,92 @@
  import 
-android
+Paths%0A%0AUSAGE = (%22android_mojo_shell.py %5B%3Cshell-and-app-args%3E%5D %5B%3Cmojo-app%3E%5D%22)
 %0A%0Adef ma
@@ -467,39 +467,19 @@
 ser(
-%22Helper for running mojo_shell%22
+usage=USAGE
 )%0A%0A 
@@ -994,16 +994,83 @@
 URLs.')%0A
+  parser.add_argument('--target-device', help='Device to run on.')%0A
   launch
@@ -1261,16 +1261,178 @@
 s.debug)
+%0A  paths = Paths(config)%0A  shell = AndroidShell(paths.target_mojo_shell_path, paths.build_dir,%0A                       paths.adb_path, launcher_args.target_device)
 %0A%0A  extr
@@ -1446,23 +1446,21 @@
 _args = 
-android
+shell
 .Prepare
@@ -1472,16 +1472,8 @@
 Run(
-config, 
 laun
@@ -1525,23 +1525,21 @@
 rgs)%0A%0A  
-android
+shell
 .CleanLo
@@ -1549,23 +1549,21 @@
 )%0A  p = 
-android
+shell
 .ShowLog
@@ -1568,23 +1568,21 @@
 ogs()%0A  
-android
+shell
 .StartSh

Update android_mojo_shell.py from the Mojo repository.