#!/usr/bin/env python
#
# Copyright (c) 2012 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.

from multiprocessing import Process
import optparse
import os
import sys

from pylib import android_commands
from pylib import test_options_parser


def InstallContentShell(device, build_type):
  apk_path = os.path.join(os.environ['CHROME_SRC'],
                          'out', build_type,
                          'content_shell', 'ContentShell-debug.apk')
  result = android_commands.AndroidCommands(device=device).ManagedInstall(
      apk_path, False, 'org.chromium.content_shell')
  print '-----  Installed on %s  -----' % device
  print result


parser = optparse.OptionParser()
test_options_parser.AddBuildTypeOption(parser)
options, args = parser.parse_args(sys.argv)

devices = android_commands.GetAttachedDevices()
if not devices:
  raise Exception('Error: no connected devices')

procs = []
for device in devices:
  p = Process(target=InstallContentShell, args=(device, options.build_type))
  p.start()
  procs += [p]

for p in procs:
  p.join()
