Makes ResourceProvider setup java on android
[chromium-blink-merge.git] / build / android / adb_install_apk.py
blob7bc634c7deb0188d412e0e7c188bfdaa0afeffd0
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 """Utility script to install APKs from the command line quickly."""
9 import optparse
10 import os
11 import sys
13 from pylib import constants
14 from pylib.device import device_utils
17 def AddInstallAPKOption(option_parser):
18 """Adds apk option used to install the APK to the OptionParser."""
19 option_parser.add_option('--apk',
20 help=('DEPRECATED The name of the apk containing the'
21 ' application (with the .apk extension).'))
22 option_parser.add_option('--apk_package',
23 help=('DEPRECATED The package name used by the apk '
24 'containing the application.'))
25 option_parser.add_option('--keep_data',
26 action='store_true',
27 default=False,
28 help=('Keep the package data when installing '
29 'the application.'))
30 option_parser.add_option('--debug', action='store_const', const='Debug',
31 dest='build_type',
32 default=os.environ.get('BUILDTYPE', 'Debug'),
33 help='If set, run test suites under out/Debug. '
34 'Default is env var BUILDTYPE or Debug')
35 option_parser.add_option('--release', action='store_const', const='Release',
36 dest='build_type',
37 help='If set, run test suites under out/Release. '
38 'Default is env var BUILDTYPE or Debug.')
39 option_parser.add_option('-d', '--device', dest='device',
40 help='Target device for apk to install on.')
43 def ValidateInstallAPKOption(option_parser, options, args):
44 """Validates the apk option and potentially qualifies the path."""
45 if not options.apk:
46 if len(args) > 1:
47 options.apk = args[1]
48 else:
49 option_parser.error('apk target not specified.')
51 if not options.apk.endswith('.apk'):
52 options.apk += '.apk'
54 if not os.path.exists(options.apk):
55 options.apk = os.path.join(constants.GetOutDirectory(), 'apks',
56 options.apk)
59 def main(argv):
60 parser = optparse.OptionParser()
61 parser.set_usage("usage: %prog [options] target")
62 AddInstallAPKOption(parser)
63 options, args = parser.parse_args(argv)
65 if len(args) > 1 and options.apk:
66 parser.error("Appending the apk as argument can't be used with --apk.")
67 elif len(args) > 2:
68 parser.error("Too many arguments.")
70 constants.SetBuildType(options.build_type)
71 ValidateInstallAPKOption(parser, options, args)
73 devices = device_utils.DeviceUtils.HealthyDevices()
75 if options.device:
76 device_serials = [d.adb.GetDeviceSerial() for d in devices]
77 if options.device not in device_serials:
78 raise Exception('Error: %s not in attached devices %s' % (options.device,
79 ','.join(device_serials)))
80 devices = [options.device]
82 if not devices:
83 raise Exception('Error: no connected devices')
85 device_utils.DeviceUtils.parallel(devices).Install(
86 options.apk, reinstall=options.keep_data)
89 if __name__ == '__main__':
90 sys.exit(main(sys.argv))