Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / build / android / adb_install_apk.py
blobad694571e6b2fcfb43e46915e2424f842b77a129
1 #!/usr/bin/env python
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
7 import multiprocessing
8 import optparse
9 import os
10 import sys
12 from pylib import android_commands
13 from pylib import constants
14 from pylib.utils import apk_helper
15 from pylib.utils import test_options_parser
18 def _InstallApk(args):
19 apk_path, apk_package, keep_data, device = args
20 result = android_commands.AndroidCommands(device=device).ManagedInstall(
21 apk_path, keep_data, apk_package)
22 print '----- Installed on %s -----' % device
23 print result
26 def main(argv):
27 parser = optparse.OptionParser()
28 test_options_parser.AddInstallAPKOption(parser)
29 options, args = parser.parse_args(argv)
30 test_options_parser.ValidateInstallAPKOption(parser, options)
31 if len(args) > 1:
32 raise Exception('Error: Unknown argument:', args[1:])
34 devices = android_commands.GetAttachedDevices()
35 if not devices:
36 raise Exception('Error: no connected devices')
38 if not options.apk_package:
39 options.apk_package = apk_helper.GetPackageName(options.apk)
41 pool = multiprocessing.Pool(len(devices))
42 # Send a tuple (apk_path, apk_package, device) per device.
43 pool.map(_InstallApk, zip([options.apk] * len(devices),
44 [options.apk_package] * len(devices),
45 [options.keep_data] * len(devices),
46 devices))
49 if __name__ == '__main__':
50 sys.exit(main(sys.argv))