3 # Copyright 2013 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 """Gets and writes the configurations of the attached devices.
9 This configuration is used by later build steps to determine which devices to
10 install to and what needs to be installed to those devices.
19 from util import build_utils
20 from util import build_device
22 BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..')
23 sys.path.append(BUILD_ANDROID_DIR)
25 from pylib.utils import apk_helper
29 parser = optparse.OptionParser()
30 parser.add_option('--stamp', action='store')
31 parser.add_option('--output', action='store')
32 options, _ = parser.parse_args(argv)
34 devices = build_device.GetAttachedDevices()
36 device_configurations = []
38 configuration, is_online, has_root = (
39 build_device.GetConfigurationForDevice(d))
42 build_utils.PrintBigWarning(
43 '%s is not online. Skipping managed install for this device. '
44 'Try rebooting the device to fix this warning.' % d)
48 build_utils.PrintBigWarning(
49 '"adb root" failed on device: %s\n'
50 'Skipping managed install for this device.'
51 % configuration['description'])
54 device_configurations.append(configuration)
56 if len(device_configurations) == 0:
57 build_utils.PrintBigWarning(
58 'No valid devices attached. Skipping managed install steps.')
59 elif len(devices) > 1:
60 # Note that this checks len(devices) and not len(device_configurations).
61 # This way, any time there are multiple devices attached it is
62 # explicitly stated which device we will install things to even if all but
63 # one device were rejected for other reasons (e.g. two devices attached,
65 build_utils.PrintBigWarning(
66 'Multiple devices attached. '
67 'Installing to the preferred device: '
68 '%(id)s (%(description)s)' % (device_configurations[0]))
71 build_device.WriteConfigurations(device_configurations, options.output)
74 if __name__ == '__main__':
75 sys.exit(main(sys.argv))