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>] |
11 """ | 11 """ |
12 | 12 |
| 13 import logging |
13 import optparse | 14 import optparse |
14 import os | 15 import os |
15 import re | 16 import re |
16 import subprocess | 17 import subprocess |
17 import sys | 18 import sys |
18 import time | 19 import time |
19 | 20 |
20 from pylib import android_commands | 21 from pylib import android_commands |
21 from pylib import constants | 22 from pylib import constants |
| 23 from pylib import device_settings |
| 24 |
22 | 25 |
23 def KillHostHeartbeat(): | 26 def KillHostHeartbeat(): |
24 ps = subprocess.Popen(['ps', 'aux'], stdout = subprocess.PIPE) | 27 ps = subprocess.Popen(['ps', 'aux'], stdout = subprocess.PIPE) |
25 stdout, _ = ps.communicate() | 28 stdout, _ = ps.communicate() |
26 matches = re.findall('\\n.*host_heartbeat.*', stdout) | 29 matches = re.findall('\\n.*host_heartbeat.*', stdout) |
27 for match in matches: | 30 for match in matches: |
28 print 'An instance of host heart beart running... will kill' | 31 print 'An instance of host heart beart running... will kill' |
29 pid = re.findall('(\d+)', match)[1] | 32 pid = re.findall('(\d+)', match)[1] |
30 subprocess.call(['kill', str(pid)]) | 33 subprocess.call(['kill', str(pid)]) |
31 | 34 |
(...skipping 26 matching lines...) Expand all Loading... |
58 adb_reboot = os.path.join(constants.DIR_SOURCE_ROOT, | 61 adb_reboot = os.path.join(constants.DIR_SOURCE_ROOT, |
59 'out/%s/adb_reboot' % target) | 62 'out/%s/adb_reboot' % target) |
60 android_cmd.PushIfNeeded(adb_reboot, '/data/local/tmp/') | 63 android_cmd.PushIfNeeded(adb_reboot, '/data/local/tmp/') |
61 # Launch adb_reboot | 64 # Launch adb_reboot |
62 print ' Launching adb_reboot ...' | 65 print ' Launching adb_reboot ...' |
63 p = subprocess.Popen(['adb', '-s', device, 'shell'], stdin=subprocess.PIPE) | 66 p = subprocess.Popen(['adb', '-s', device, 'shell'], stdin=subprocess.PIPE) |
64 p.communicate('/data/local/tmp/adb_reboot; exit\n') | 67 p.communicate('/data/local/tmp/adb_reboot; exit\n') |
65 LaunchHostHeartbeat() | 68 LaunchHostHeartbeat() |
66 | 69 |
67 | 70 |
| 71 def _ConfigureLocalProperties(adb): |
| 72 """Set standard readonly testing device properties prior to reboot.""" |
| 73 local_props = [ |
| 74 'ro.monkey=1', |
| 75 'ro.test_harness=1', |
| 76 'ro.audio.silent=1', |
| 77 'ro.setupwizard.mode=DISABLED', |
| 78 ] |
| 79 adb.SetProtectedFileContents(android_commands.LOCAL_PROPERTIES_PATH, |
| 80 '\n'.join(local_props)) |
| 81 # Android will not respect the local props file if it is world writable. |
| 82 adb.RunShellCommandWithSU('chmod 644 %s' % |
| 83 android_commands.LOCAL_PROPERTIES_PATH) |
| 84 |
| 85 |
68 def ProvisionDevices(options): | 86 def ProvisionDevices(options): |
69 if options.device is not None: | 87 if options.device is not None: |
70 devices = [options.device] | 88 devices = [options.device] |
71 else: | 89 else: |
72 devices = android_commands.GetAttachedDevices() | 90 devices = android_commands.GetAttachedDevices() |
73 for device in devices: | 91 for device in devices: |
74 android_cmd = android_commands.AndroidCommands(device) | 92 android_cmd = android_commands.AndroidCommands(device) |
| 93 _ConfigureLocalProperties(android_cmd) |
| 94 device_settings.ConfigureContentSettingsDict( |
| 95 android_cmd, device_settings.DETERMINISTIC_DEVICE_SETTINGS) |
| 96 # TODO(tonyg): We eventually want network on. However, currently radios |
| 97 # can cause perfbots to drain faster than they charge. |
| 98 if 'perf' in os.environ.get('BUILDBOT_BUILDERNAME', '').lower(): |
| 99 device_settings.ConfigureContentSettingsDict( |
| 100 android_cmd, device_settings.NETWORK_DISABLED_SETTINGS) |
75 android_cmd.RunShellCommandWithSU('date -u %f' % time.time()) | 101 android_cmd.RunShellCommandWithSU('date -u %f' % time.time()) |
76 if options.auto_reconnect: | 102 if options.auto_reconnect: |
77 PushAndLaunchAdbReboot(devices, options.target) | 103 PushAndLaunchAdbReboot(devices, options.target) |
78 | 104 |
79 | 105 |
80 def main(argv): | 106 def main(argv): |
| 107 logging.basicConfig(level=logging.INFO) |
| 108 |
81 parser = optparse.OptionParser() | 109 parser = optparse.OptionParser() |
82 parser.add_option('-d', '--device', | 110 parser.add_option('-d', '--device', |
83 help='The serial number of the device to be provisioned') | 111 help='The serial number of the device to be provisioned') |
84 parser.add_option('-t', '--target', default='Debug', help='The build target') | 112 parser.add_option('-t', '--target', default='Debug', help='The build target') |
85 parser.add_option( | 113 parser.add_option( |
86 '-r', '--auto-reconnect', action='store_true', | 114 '-r', '--auto-reconnect', action='store_true', |
87 help='Push binary which will reboot the device on adb disconnections.') | 115 help='Push binary which will reboot the device on adb disconnections.') |
88 options, args = parser.parse_args(argv[1:]) | 116 options, args = parser.parse_args(argv[1:]) |
89 constants.SetBuildType(options.target) | 117 constants.SetBuildType(options.target) |
90 | 118 |
91 if args: | 119 if args: |
92 print >> sys.stderr, 'Unused args %s' % args | 120 print >> sys.stderr, 'Unused args %s' % args |
93 return 1 | 121 return 1 |
94 | 122 |
95 ProvisionDevices(options) | 123 ProvisionDevices(options) |
96 | 124 |
97 | 125 |
98 if __name__ == '__main__': | 126 if __name__ == '__main__': |
99 sys.exit(main(sys.argv)) | 127 sys.exit(main(sys.argv)) |
OLD | NEW |