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.
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
27 parser
= optparse
.OptionParser()
28 test_options_parser
.AddInstallAPKOption(parser
)
29 options
, args
= parser
.parse_args(argv
)
30 test_options_parser
.ValidateInstallAPKOption(parser
, options
)
32 raise Exception('Error: Unknown argument:', args
[1:])
34 devices
= android_commands
.GetAttachedDevices()
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
),
49 if __name__
== '__main__':
50 sys
.exit(main(sys
.argv
))