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 logging |
14 import optparse | 14 import optparse |
15 import os | 15 import os |
16 import re | 16 import re |
17 import subprocess | 17 import subprocess |
18 import sys | 18 import sys |
19 import time | 19 import time |
20 | 20 |
21 from pylib import android_commands | 21 from pylib import android_commands |
22 from pylib import constants | 22 from pylib import constants |
23 from pylib import device_settings | 23 from pylib import device_settings |
24 from pylib.cmd_helper import GetCmdOutput | |
25 from pylib.device import device_utils | 24 from pylib.device import device_utils |
26 | 25 |
27 def KillHostHeartbeat(): | 26 def KillHostHeartbeat(): |
28 ps = subprocess.Popen(['ps', 'aux'], stdout = subprocess.PIPE) | 27 ps = subprocess.Popen(['ps', 'aux'], stdout = subprocess.PIPE) |
29 stdout, _ = ps.communicate() | 28 stdout, _ = ps.communicate() |
30 matches = re.findall('\\n.*host_heartbeat.*', stdout) | 29 matches = re.findall('\\n.*host_heartbeat.*', stdout) |
31 for match in matches: | 30 for match in matches: |
32 print 'An instance of host heart beart running... will kill' | 31 print 'An instance of host heart beart running... will kill' |
33 pid = re.findall('(\d+)', match)[1] | 32 pid = re.findall('(\d+)', match)[1] |
34 subprocess.call(['kill', str(pid)]) | 33 subprocess.call(['kill', str(pid)]) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 device.old_interface.SetProtectedFileContents( | 81 device.old_interface.SetProtectedFileContents( |
83 constants.DEVICE_LOCAL_PROPERTIES_PATH, | 82 constants.DEVICE_LOCAL_PROPERTIES_PATH, |
84 '\n'.join(local_props)) | 83 '\n'.join(local_props)) |
85 # Android will not respect the local props file if it is world writable. | 84 # Android will not respect the local props file if it is world writable. |
86 device.old_interface.RunShellCommandWithSU( | 85 device.old_interface.RunShellCommandWithSU( |
87 'chmod 644 %s' % constants.DEVICE_LOCAL_PROPERTIES_PATH) | 86 'chmod 644 %s' % constants.DEVICE_LOCAL_PROPERTIES_PATH) |
88 | 87 |
89 # LOCAL_PROPERTIES_PATH = '/data/local.prop' | 88 # LOCAL_PROPERTIES_PATH = '/data/local.prop' |
90 | 89 |
91 | 90 |
92 def WipeDeviceData(device): | 91 def WipeDeviceData(device, reboot=True): |
Dan Jacques
2014/04/26 01:11:26
Is this ever called with 'reboot=True'? If not, I
navabi
2014/04/26 01:15:36
Done.
| |
93 """Wipes data from device, keeping only the adb_keys for authorization. | 92 """Wipes data from device, keeping only the adb_keys for authorization. |
94 | 93 |
95 After wiping data on a device that has been authorized, adb can still | 94 After wiping data on a device that has been authorized, adb can still |
96 communicate with the device, but after reboot the device will need to be | 95 communicate with the device, but after reboot the device will need to be |
97 re-authorized because the adb keys file is stored in /data/misc/adb/. | 96 re-authorized because the adb keys file is stored in /data/misc/adb/. |
98 Thus, before reboot the adb_keys file is rewritten so the device does not need | 97 Thus, before reboot the adb_keys file is rewritten so the device does not need |
99 to be re-authorized. | 98 to be re-authorized. |
100 | 99 |
101 Arguments: | 100 Arguments: |
102 device: the device to wipe | 101 device: the device to wipe |
103 """ | 102 """ |
104 device_authorized = device.old_interface.FileExistsOnDevice( | 103 device_authorized = device.old_interface.FileExistsOnDevice( |
105 constants.ADB_KEYS_FILE) | 104 constants.ADB_KEYS_FILE) |
106 if device_authorized: | 105 if device_authorized: |
107 adb_keys = device.old_interface.RunShellCommandWithSU( | 106 adb_keys = device.old_interface.RunShellCommandWithSU( |
108 'cat %s' % constants.ADB_KEYS_FILE)[0] | 107 'cat %s' % constants.ADB_KEYS_FILE) |
109 device.old_interface.RunShellCommandWithSU('wipe data') | 108 device.old_interface.RunShellCommandWithSU('wipe data') |
110 if device_authorized: | 109 if device_authorized: |
111 path_list = constants.ADB_KEYS_FILE.split('/') | 110 path_list = constants.ADB_KEYS_FILE.split('/') |
112 dir_path = '/'.join(path_list[:len(path_list)-1]) | 111 dir_path = '/'.join(path_list[:len(path_list)-1]) |
113 device.old_interface.RunShellCommandWithSU('mkdir -p %s' % dir_path) | 112 device.old_interface.RunShellCommandWithSU('mkdir -p %s' % dir_path) |
114 adb_keys = device.old_interface.RunShellCommand( | 113 device.old_interface.RunShellCommandWithSU('touch %s' % |
115 'echo %s > %s' % (adb_keys, constants.ADB_KEYS_FILE)) | 114 constants.ADB_KEYS_FILE) |
116 device.old_interface.Reboot() | 115 for adb_key in adb_keys: |
116 device.old_interface.RunShellCommand( | |
117 'echo %s >> %s' % (adb_key, constants.ADB_KEYS_FILE)) | |
118 if reboot: | |
119 device.old_interface.Reboot() | |
117 | 120 |
118 | 121 |
119 def ProvisionDevices(options): | 122 def ProvisionDevices(options): |
120 if options.device is not None: | 123 if options.device is not None: |
121 devices = [options.device] | 124 devices = [options.device] |
122 else: | 125 else: |
123 devices = android_commands.GetAttachedDevices() | 126 devices = android_commands.GetAttachedDevices() |
124 for device_serial in devices: | 127 for device_serial in devices: |
125 device = device_utils.DeviceUtils(device_serial) | 128 device = device_utils.DeviceUtils(device_serial) |
126 install_output = GetCmdOutput( | 129 # Wipe device data, but don't reboot devices (takes too long) |
127 ['%s/build/android/adb_install_apk.py' % constants.DIR_SOURCE_ROOT, | 130 WipeDeviceData(device, reboot=False) |
128 '--apk', | |
129 '%s/build/android/CheckInstallApk-debug.apk' % constants.DIR_SOURCE_ROOT | |
130 ]) | |
131 failure_string = 'Failure [INSTALL_FAILED_INSUFFICIENT_STORAGE]' | |
132 if failure_string in install_output: | |
133 WipeDeviceData(device) | |
134 _ConfigureLocalProperties(device) | 131 _ConfigureLocalProperties(device) |
135 device_settings.ConfigureContentSettingsDict( | 132 device_settings.ConfigureContentSettingsDict( |
136 device, device_settings.DETERMINISTIC_DEVICE_SETTINGS) | 133 device, device_settings.DETERMINISTIC_DEVICE_SETTINGS) |
137 # TODO(tonyg): We eventually want network on. However, currently radios | 134 # TODO(tonyg): We eventually want network on. However, currently radios |
138 # can cause perfbots to drain faster than they charge. | 135 # can cause perfbots to drain faster than they charge. |
139 if 'perf' in os.environ.get('BUILDBOT_BUILDERNAME', '').lower(): | 136 if 'perf' in os.environ.get('BUILDBOT_BUILDERNAME', '').lower(): |
140 device_settings.ConfigureContentSettingsDict( | 137 device_settings.ConfigureContentSettingsDict( |
141 device, device_settings.NETWORK_DISABLED_SETTINGS) | 138 device, device_settings.NETWORK_DISABLED_SETTINGS) |
142 device.old_interface.RunShellCommandWithSU('date -u %f' % time.time()) | 139 device.old_interface.RunShellCommandWithSU('date -u %f' % time.time()) |
143 if options.auto_reconnect: | 140 if options.auto_reconnect: |
(...skipping 15 matching lines...) Expand all Loading... | |
159 | 156 |
160 if args: | 157 if args: |
161 print >> sys.stderr, 'Unused args %s' % args | 158 print >> sys.stderr, 'Unused args %s' % args |
162 return 1 | 159 return 1 |
163 | 160 |
164 ProvisionDevices(options) | 161 ProvisionDevices(options) |
165 | 162 |
166 | 163 |
167 if __name__ == '__main__': | 164 if __name__ == '__main__': |
168 sys.exit(main(sys.argv)) | 165 sys.exit(main(sys.argv)) |
OLD | NEW |