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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 device.old_interface.SetProtectedFileContents( | 83 device.old_interface.SetProtectedFileContents( |
84 constants.DEVICE_LOCAL_PROPERTIES_PATH, | 84 constants.DEVICE_LOCAL_PROPERTIES_PATH, |
85 '\n'.join(local_props)) | 85 '\n'.join(local_props)) |
86 # Android will not respect the local props file if it is world writable. | 86 # Android will not respect the local props file if it is world writable. |
87 device.old_interface.RunShellCommandWithSU( | 87 device.RunShellCommand( |
88 'chmod 644 %s' % constants.DEVICE_LOCAL_PROPERTIES_PATH) | 88 'chmod 644 %s' % constants.DEVICE_LOCAL_PROPERTIES_PATH, |
| 89 root=True) |
89 | 90 |
90 # LOCAL_PROPERTIES_PATH = '/data/local.prop' | 91 # LOCAL_PROPERTIES_PATH = '/data/local.prop' |
91 | 92 |
92 | 93 |
93 def WipeDeviceData(device): | 94 def WipeDeviceData(device): |
94 """Wipes data from device, keeping only the adb_keys for authorization. | 95 """Wipes data from device, keeping only the adb_keys for authorization. |
95 | 96 |
96 After wiping data on a device that has been authorized, adb can still | 97 After wiping data on a device that has been authorized, adb can still |
97 communicate with the device, but after reboot the device will need to be | 98 communicate with the device, but after reboot the device will need to be |
98 re-authorized because the adb keys file is stored in /data/misc/adb/. | 99 re-authorized because the adb keys file is stored in /data/misc/adb/. |
99 Thus, adb_keys file is rewritten so the device does not need to be | 100 Thus, adb_keys file is rewritten so the device does not need to be |
100 re-authorized. | 101 re-authorized. |
101 | 102 |
102 Arguments: | 103 Arguments: |
103 device: the device to wipe | 104 device: the device to wipe |
104 """ | 105 """ |
105 device_authorized = device.old_interface.FileExistsOnDevice( | 106 device_authorized = device.old_interface.FileExistsOnDevice( |
106 constants.ADB_KEYS_FILE) | 107 constants.ADB_KEYS_FILE) |
107 if device_authorized: | 108 if device_authorized: |
108 adb_keys = device.old_interface.RunShellCommandWithSU( | 109 adb_keys = device.RunShellCommand('cat %s' % constants.ADB_KEYS_FILE, |
109 'cat %s' % constants.ADB_KEYS_FILE) | 110 root=True) |
110 device.old_interface.RunShellCommandWithSU('wipe data') | 111 device.RunShellCommand('wipe data', root=True) |
111 if device_authorized: | 112 if device_authorized: |
112 path_list = constants.ADB_KEYS_FILE.split('/') | 113 path_list = constants.ADB_KEYS_FILE.split('/') |
113 dir_path = '/'.join(path_list[:len(path_list)-1]) | 114 dir_path = '/'.join(path_list[:len(path_list)-1]) |
114 device.old_interface.RunShellCommandWithSU('mkdir -p %s' % dir_path) | 115 device.RunShellCommand('mkdir -p %s' % dir_path, root=True) |
115 device.old_interface.RunShellCommand('echo %s > %s' % | 116 device.RunShellCommand('echo %s > %s' % |
116 (adb_keys[0], constants.ADB_KEYS_FILE)) | 117 (adb_keys[0], constants.ADB_KEYS_FILE)) |
117 for adb_key in adb_keys[1:]: | 118 for adb_key in adb_keys[1:]: |
118 device.old_interface.RunShellCommand( | 119 device.RunShellCommand( |
119 'echo %s >> %s' % (adb_key, constants.ADB_KEYS_FILE)) | 120 'echo %s >> %s' % (adb_key, constants.ADB_KEYS_FILE)) |
120 | 121 |
121 | 122 |
122 def ProvisionDevices(options): | 123 def ProvisionDevices(options): |
123 # TODO(jbudorick): Parallelize provisioning of all attached devices after | 124 # TODO(jbudorick): Parallelize provisioning of all attached devices after |
124 # swithcing from AndroidCommands. | 125 # switching from AndroidCommands. |
125 if options.device is not None: | 126 if options.device is not None: |
126 devices = [options.device] | 127 devices = [options.device] |
127 else: | 128 else: |
128 devices = android_commands.GetAttachedDevices() | 129 devices = android_commands.GetAttachedDevices() |
129 | 130 |
130 # Wipe devices (unless --skip-wipe was specified) | 131 # Wipe devices (unless --skip-wipe was specified) |
131 if not options.skip_wipe: | 132 if not options.skip_wipe: |
132 for device_serial in devices: | 133 for device_serial in devices: |
133 device = device_utils.DeviceUtils(device_serial) | 134 device = device_utils.DeviceUtils(device_serial) |
134 device.old_interface.EnableAdbRoot() | 135 device.old_interface.EnableAdbRoot() |
135 WipeDeviceData(device) | 136 WipeDeviceData(device) |
136 try: | 137 try: |
137 device_utils.DeviceUtils.parallel(devices).old_interface.Reboot(True) | 138 device_utils.DeviceUtils.parallel(devices).Reboot(True) |
138 except errors.DeviceUnresponsiveError: | 139 except errors.DeviceUnresponsiveError: |
139 pass | 140 pass |
140 for device_serial in devices: | 141 for device_serial in devices: |
141 device.WaitUntilFullyBooted(timeout=90) | 142 device.WaitUntilFullyBooted(timeout=90) |
142 | 143 |
143 # Provision devices | 144 # Provision devices |
144 for device_serial in devices: | 145 for device_serial in devices: |
145 device = device_utils.DeviceUtils(device_serial) | 146 device = device_utils.DeviceUtils(device_serial) |
146 device.old_interface.EnableAdbRoot() | 147 device.old_interface.EnableAdbRoot() |
147 _ConfigureLocalProperties(device) | 148 _ConfigureLocalProperties(device) |
148 device_settings.ConfigureContentSettingsDict( | 149 device_settings.ConfigureContentSettingsDict( |
149 device, device_settings.DETERMINISTIC_DEVICE_SETTINGS) | 150 device, device_settings.DETERMINISTIC_DEVICE_SETTINGS) |
150 # TODO(tonyg): We eventually want network on. However, currently radios | 151 # TODO(tonyg): We eventually want network on. However, currently radios |
151 # can cause perfbots to drain faster than they charge. | 152 # can cause perfbots to drain faster than they charge. |
152 if 'perf' in os.environ.get('BUILDBOT_BUILDERNAME', '').lower(): | 153 if 'perf' in os.environ.get('BUILDBOT_BUILDERNAME', '').lower(): |
153 device_settings.ConfigureContentSettingsDict( | 154 device_settings.ConfigureContentSettingsDict( |
154 device, device_settings.NETWORK_DISABLED_SETTINGS) | 155 device, device_settings.NETWORK_DISABLED_SETTINGS) |
155 device.old_interface.RunShellCommandWithSU('date -u %f' % time.time()) | 156 device.RunShellCommand('date -u %f' % time.time(), root=True) |
156 try: | 157 try: |
157 device_utils.DeviceUtils.parallel(devices).Reboot(True) | 158 device_utils.DeviceUtils.parallel(devices).Reboot(True) |
158 except errors.DeviceUnresponsiveError: | 159 except errors.DeviceUnresponsiveError: |
159 pass | 160 pass |
160 for device_serial in devices: | 161 for device_serial in devices: |
161 device = device_utils.DeviceUtils(device_serial) | 162 device = device_utils.DeviceUtils(device_serial) |
162 device.WaitUntilFullyBooted(timeout=90) | 163 device.WaitUntilFullyBooted(timeout=90) |
163 (_, props) = device.old_interface.GetShellCommandStatusAndOutput('getprop') | 164 (_, props) = device.old_interface.GetShellCommandStatusAndOutput('getprop') |
164 for prop in props: | 165 for prop in props: |
165 print prop | 166 print prop |
(...skipping 18 matching lines...) Expand all Loading... |
184 | 185 |
185 if args: | 186 if args: |
186 print >> sys.stderr, 'Unused args %s' % args | 187 print >> sys.stderr, 'Unused args %s' % args |
187 return 1 | 188 return 1 |
188 | 189 |
189 ProvisionDevices(options) | 190 ProvisionDevices(options) |
190 | 191 |
191 | 192 |
192 if __name__ == '__main__': | 193 if __name__ == '__main__': |
193 sys.exit(main(sys.argv)) | 194 sys.exit(main(sys.argv)) |
OLD | NEW |