| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Provisions Android devices with settings required for bots. | 7 """Provisions Android devices with settings required for bots. |
| 8 | 8 |
| 9 Usage: | 9 Usage: |
| 10 ./provision_devices.py [-d <device serial number>] | 10 ./provision_devices.py [-d <device serial number>] |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 adb_reboot = os.path.join(constants.DIR_SOURCE_ROOT, | 65 adb_reboot = os.path.join(constants.DIR_SOURCE_ROOT, |
| 66 'out/%s/adb_reboot' % target) | 66 'out/%s/adb_reboot' % target) |
| 67 device.old_interface.PushIfNeeded(adb_reboot, '/data/local/tmp/') | 67 device.old_interface.PushIfNeeded(adb_reboot, '/data/local/tmp/') |
| 68 # Launch adb_reboot | 68 # Launch adb_reboot |
| 69 print ' Launching adb_reboot ...' | 69 print ' Launching adb_reboot ...' |
| 70 device.old_interface.GetAndroidToolStatusAndOutput( | 70 device.old_interface.GetAndroidToolStatusAndOutput( |
| 71 '/data/local/tmp/adb_reboot') | 71 '/data/local/tmp/adb_reboot') |
| 72 LaunchHostHeartbeat() | 72 LaunchHostHeartbeat() |
| 73 | 73 |
| 74 | 74 |
| 75 def _ConfigureLocalProperties(device): | 75 def _ConfigureLocalProperties(device, is_perf): |
| 76 """Set standard readonly testing device properties prior to reboot.""" | 76 """Set standard readonly testing device properties prior to reboot.""" |
| 77 local_props = [ | 77 local_props = [ |
| 78 'ro.monkey=1', | 78 'ro.monkey=1', |
| 79 'ro.test_harness=1', | 79 'ro.test_harness=1', |
| 80 'ro.audio.silent=1', | 80 'ro.audio.silent=1', |
| 81 'ro.setupwizard.mode=DISABLED', | 81 'ro.setupwizard.mode=DISABLED', |
| 82 ] | 82 ] |
| 83 if not is_perf: |
| 84 local_props.append('%s=all' % android_commands.JAVA_ASSERT_PROPERTY) |
| 85 local_props.append('debug.checkjni=1') |
| 83 device.old_interface.SetProtectedFileContents( | 86 device.old_interface.SetProtectedFileContents( |
| 84 constants.DEVICE_LOCAL_PROPERTIES_PATH, | 87 constants.DEVICE_LOCAL_PROPERTIES_PATH, |
| 85 '\n'.join(local_props)) | 88 '\n'.join(local_props)) |
| 86 # Android will not respect the local props file if it is world writable. | 89 # Android will not respect the local props file if it is world writable. |
| 87 device.RunShellCommand( | 90 device.RunShellCommand( |
| 88 'chmod 644 %s' % constants.DEVICE_LOCAL_PROPERTIES_PATH, | 91 'chmod 644 %s' % constants.DEVICE_LOCAL_PROPERTIES_PATH, |
| 89 root=True) | 92 root=True) |
| 90 | 93 |
| 91 # LOCAL_PROPERTIES_PATH = '/data/local.prop' | 94 # LOCAL_PROPERTIES_PATH = '/data/local.prop' |
| 92 | 95 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 114 dir_path = '/'.join(path_list[:len(path_list)-1]) | 117 dir_path = '/'.join(path_list[:len(path_list)-1]) |
| 115 device.RunShellCommand('mkdir -p %s' % dir_path, root=True) | 118 device.RunShellCommand('mkdir -p %s' % dir_path, root=True) |
| 116 device.RunShellCommand('echo %s > %s' % | 119 device.RunShellCommand('echo %s > %s' % |
| 117 (adb_keys[0], constants.ADB_KEYS_FILE)) | 120 (adb_keys[0], constants.ADB_KEYS_FILE)) |
| 118 for adb_key in adb_keys[1:]: | 121 for adb_key in adb_keys[1:]: |
| 119 device.RunShellCommand( | 122 device.RunShellCommand( |
| 120 'echo %s >> %s' % (adb_key, constants.ADB_KEYS_FILE)) | 123 'echo %s >> %s' % (adb_key, constants.ADB_KEYS_FILE)) |
| 121 | 124 |
| 122 | 125 |
| 123 def ProvisionDevices(options): | 126 def ProvisionDevices(options): |
| 127 is_perf = 'perf' in os.environ.get('BUILDBOT_BUILDERNAME', '').lower() |
| 124 # TODO(jbudorick): Parallelize provisioning of all attached devices after | 128 # TODO(jbudorick): Parallelize provisioning of all attached devices after |
| 125 # switching from AndroidCommands. | 129 # switching from AndroidCommands. |
| 126 if options.device is not None: | 130 if options.device is not None: |
| 127 devices = [options.device] | 131 devices = [options.device] |
| 128 else: | 132 else: |
| 129 devices = android_commands.GetAttachedDevices() | 133 devices = android_commands.GetAttachedDevices() |
| 130 | 134 |
| 131 # Wipe devices (unless --skip-wipe was specified) | 135 # Wipe devices (unless --skip-wipe was specified) |
| 132 if not options.skip_wipe: | 136 if not options.skip_wipe: |
| 133 for device_serial in devices: | 137 for device_serial in devices: |
| 134 device = device_utils.DeviceUtils(device_serial) | 138 device = device_utils.DeviceUtils(device_serial) |
| 135 device.old_interface.EnableAdbRoot() | 139 device.old_interface.EnableAdbRoot() |
| 136 WipeDeviceData(device) | 140 WipeDeviceData(device) |
| 137 try: | 141 try: |
| 138 device_utils.DeviceUtils.parallel(devices).Reboot(True) | 142 device_utils.DeviceUtils.parallel(devices).Reboot(True) |
| 139 except errors.DeviceUnresponsiveError: | 143 except errors.DeviceUnresponsiveError: |
| 140 pass | 144 pass |
| 141 for device_serial in devices: | 145 for device_serial in devices: |
| 142 device.WaitUntilFullyBooted(timeout=90) | 146 device.WaitUntilFullyBooted(timeout=90) |
| 143 | 147 |
| 144 # Provision devices | 148 # Provision devices |
| 145 for device_serial in devices: | 149 for device_serial in devices: |
| 146 device = device_utils.DeviceUtils(device_serial) | 150 device = device_utils.DeviceUtils(device_serial) |
| 147 device.old_interface.EnableAdbRoot() | 151 device.old_interface.EnableAdbRoot() |
| 148 _ConfigureLocalProperties(device) | 152 _ConfigureLocalProperties(device, is_perf) |
| 149 device_settings_map = device_settings.DETERMINISTIC_DEVICE_SETTINGS | 153 device_settings_map = device_settings.DETERMINISTIC_DEVICE_SETTINGS |
| 150 if options.disable_location: | 154 if options.disable_location: |
| 151 device_settings_map.update(device_settings.DISABLE_LOCATION_SETTING) | 155 device_settings_map.update(device_settings.DISABLE_LOCATION_SETTING) |
| 152 else: | 156 else: |
| 153 device_settings_map.update(device_settings.ENABLE_LOCATION_SETTING) | 157 device_settings_map.update(device_settings.ENABLE_LOCATION_SETTING) |
| 154 device_settings.ConfigureContentSettingsDict(device, device_settings_map) | 158 device_settings.ConfigureContentSettingsDict(device, device_settings_map) |
| 155 if 'perf' in os.environ.get('BUILDBOT_BUILDERNAME', '').lower(): | 159 if is_perf: |
| 156 # TODO(tonyg): We eventually want network on. However, currently radios | 160 # TODO(tonyg): We eventually want network on. However, currently radios |
| 157 # can cause perfbots to drain faster than they charge. | 161 # can cause perfbots to drain faster than they charge. |
| 158 device_settings.ConfigureContentSettingsDict( | 162 device_settings.ConfigureContentSettingsDict( |
| 159 device, device_settings.NETWORK_DISABLED_SETTINGS) | 163 device, device_settings.NETWORK_DISABLED_SETTINGS) |
| 160 # Some perf bots run benchmarks with USB charging disabled which leads | 164 # Some perf bots run benchmarks with USB charging disabled which leads |
| 161 # to gradual draining of the battery. We must wait for a full charge | 165 # to gradual draining of the battery. We must wait for a full charge |
| 162 # before starting a run in order to keep the devices online. | 166 # before starting a run in order to keep the devices online. |
| 163 try: | 167 try: |
| 164 battery_info = device.old_interface.GetBatteryInfo() | 168 battery_info = device.old_interface.GetBatteryInfo() |
| 165 except Exception as e: | 169 except Exception as e: |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 | 216 |
| 213 if args: | 217 if args: |
| 214 print >> sys.stderr, 'Unused args %s' % args | 218 print >> sys.stderr, 'Unused args %s' % args |
| 215 return 1 | 219 return 1 |
| 216 | 220 |
| 217 ProvisionDevices(options) | 221 ProvisionDevices(options) |
| 218 | 222 |
| 219 | 223 |
| 220 if __name__ == '__main__': | 224 if __name__ == '__main__': |
| 221 sys.exit(main(sys.argv)) | 225 sys.exit(main(sys.argv)) |
| OLD | NEW |