summaryrefslogtreecommitdiffstats
path: root/build/android/adb_install_apk.py
blob: ad694571e6b2fcfb43e46915e2424f842b77a129 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/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.

import multiprocessing
import optparse
import os
import sys

from pylib import android_commands
from pylib import constants
from pylib.utils import apk_helper
from pylib.utils import test_options_parser


def _InstallApk(args):
  apk_path, apk_package, keep_data, device = args
  result = android_commands.AndroidCommands(device=device).ManagedInstall(
      apk_path, keep_data, apk_package)
  print '-----  Installed on %s  -----' % device
  print result


def main(argv):
  parser = optparse.OptionParser()
  test_options_parser.AddInstallAPKOption(parser)
  options, args = parser.parse_args(argv)
  test_options_parser.ValidateInstallAPKOption(parser, options)
  if len(args) > 1:
    raise Exception('Error: Unknown argument:', args[1:])

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

  if not options.apk_package:
    options.apk_package = apk_helper.GetPackageName(options.apk)

  pool = multiprocessing.Pool(len(devices))
  # Send a tuple (apk_path, apk_package, device) per device.
  pool.map(_InstallApk, zip([options.apk] * len(devices),
                            [options.apk_package] * len(devices),
                            [options.keep_data] * len(devices),
                            devices))


if __name__ == '__main__':
  sys.exit(main(sys.argv))