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 argparse | 13 import argparse |
14 import logging | 14 import logging |
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.device import device_blacklist | 24 from pylib.device import device_blacklist |
25 from pylib.device import device_errors | 25 from pylib.device import device_errors |
26 from pylib.device import device_utils | 26 from pylib.device import device_utils |
27 from pylib.utils import run_tests_helper | 27 from pylib.utils import run_tests_helper |
28 from sets import Set | |
28 | 29 |
29 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, | 30 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, |
30 'third_party', 'android_testrunner')) | 31 'third_party', 'android_testrunner')) |
31 import errors | 32 import errors |
32 | 33 |
33 | 34 |
34 class _DEFAULT_TIMEOUTS(object): | 35 class _DEFAULT_TIMEOUTS(object): |
35 # L can take a while to reboot after a wipe. | 36 # L can take a while to reboot after a wipe. |
36 LOLLIPOP = 600 | 37 LOLLIPOP = 600 |
37 PRE_LOLLIPOP = 180 | 38 PRE_LOLLIPOP = 180 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 | 120 |
120 After wiping data on a device that has been authorized, adb can still | 121 After wiping data on a device that has been authorized, adb can still |
121 communicate with the device, but after reboot the device will need to be | 122 communicate with the device, but after reboot the device will need to be |
122 re-authorized because the adb keys file is stored in /data/misc/adb/. | 123 re-authorized because the adb keys file is stored in /data/misc/adb/. |
123 Thus, adb_keys file is rewritten so the device does not need to be | 124 Thus, adb_keys file is rewritten so the device does not need to be |
124 re-authorized. | 125 re-authorized. |
125 | 126 |
126 Arguments: | 127 Arguments: |
127 device: the device to wipe | 128 device: the device to wipe |
128 """ | 129 """ |
129 device_authorized = device.FileExists(constants.ADB_KEYS_FILE) | 130 adb_dir_exists = device.FileExists(os.path.dirname(constants.ADB_KEYS_FILE)) |
jbudorick
2015/02/24 23:44:49
I still think it'd be better to pass in a file via
navabi
2015/02/25 01:22:35
Done.
| |
130 if device_authorized: | 131 if adb_dir_exists: |
131 adb_keys = device.ReadFile(constants.ADB_KEYS_FILE, as_root=True) | 132 adb_key_files = [adb_key_file for adb_key_file in |
133 os.listdir('%s/.android' % os.environ['HOME']) | |
134 if adb_key_file.endswith('adbkey.pub')] | |
135 adb_keys = Set([]) | |
136 for adb_key_file in adb_key_files: | |
137 file_path = os.path.join(os.environ['HOME'], '.android', adb_key_file) | |
138 with open(file_path, 'r') as f: | |
139 adb_public_key = f.readlines() | |
140 adb_keys.add(''.join(adb_public_key)) | |
132 device.RunShellCommand('wipe data', as_root=True) | 141 device.RunShellCommand('wipe data', as_root=True) |
133 if device_authorized: | 142 if adb_dir_exists: |
134 path_list = constants.ADB_KEYS_FILE.split('/') | 143 path_list = constants.ADB_KEYS_FILE.split('/') |
135 dir_path = '/'.join(path_list[:len(path_list)-1]) | 144 dir_path = '/'.join(path_list[:len(path_list)-1]) |
136 device.RunShellCommand('mkdir -p %s' % dir_path, as_root=True) | 145 device.RunShellCommand('mkdir -p %s' % dir_path, as_root=True) |
137 device.RunShellCommand('restorecon %s' % dir_path, as_root=True) | 146 device.RunShellCommand('restorecon %s' % dir_path, as_root=True) |
138 device.WriteFile(constants.ADB_KEYS_FILE, adb_keys, as_root=True) | 147 adb_key_contents = '' |
148 for adb_key in adb_keys: | |
jbudorick
2015/02/24 23:44:49
this is just
adb_key_contents = ''.join('%s\n'
navabi
2015/02/25 01:22:35
Done.
| |
149 adb_key_contents = '%s\n%s' % (adb_key, adb_key_contents) | |
150 device.WriteFile(constants.ADB_KEYS_FILE, adb_key_contents, as_root=True) | |
139 device.RunShellCommand('restorecon %s' % constants.ADB_KEYS_FILE, | 151 device.RunShellCommand('restorecon %s' % constants.ADB_KEYS_FILE, |
140 as_root=True) | 152 as_root=True) |
141 | 153 |
142 | |
143 def WipeDeviceIfPossible(device, timeout): | 154 def WipeDeviceIfPossible(device, timeout): |
144 try: | 155 try: |
145 device.EnableRoot() | 156 device.EnableRoot() |
146 WipeDeviceData(device) | 157 WipeDeviceData(device) |
147 device.Reboot(True, timeout=timeout, retries=0) | 158 device.Reboot(True, timeout=timeout, retries=0) |
148 except (errors.DeviceUnresponsiveError, device_errors.CommandFailedError): | 159 except (errors.DeviceUnresponsiveError, device_errors.CommandFailedError): |
149 pass | 160 pass |
150 | 161 |
151 | 162 |
152 def ProvisionDevice(device, options): | 163 def ProvisionDevice(device, options): |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 help='push binary which will reboot the device on adb' | 288 help='push binary which will reboot the device on adb' |
278 ' disconnections') | 289 ' disconnections') |
279 args = parser.parse_args() | 290 args = parser.parse_args() |
280 constants.SetBuildType(args.target) | 291 constants.SetBuildType(args.target) |
281 | 292 |
282 return ProvisionDevices(args) | 293 return ProvisionDevices(args) |
283 | 294 |
284 | 295 |
285 if __name__ == '__main__': | 296 if __name__ == '__main__': |
286 sys.exit(main()) | 297 sys.exit(main()) |
OLD | NEW |