Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: build/android/provision_devices.py

Issue 949323003: Write adb public key to devices during provision. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Write adb public keys from $HOME/.android/ Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
friedman1 2015/02/24 23:33:43 set is a python builtin
navabi 2015/02/25 01:22:35 Done.
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 device_authorized = device.FileExists(constants.ADB_KEYS_FILE)
130 if device_authorized: 131 if device_authorized:
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([])
friedman1 2015/02/24 23:33:43 adb_keys = set()
navabi 2015/02/25 01:22:35 Done.
136 for adb_key_file in adb_key_files:
137 with open(adb_key_file, 'r') as f:
138 adb_public_key = f.readlines()
139 adb_keys.add(adb_public_key)
132 device.RunShellCommand('wipe data', as_root=True) 140 device.RunShellCommand('wipe data', as_root=True)
133 if device_authorized: 141 if device_authorized:
134 path_list = constants.ADB_KEYS_FILE.split('/') 142 path_list = constants.ADB_KEYS_FILE.split('/')
135 dir_path = '/'.join(path_list[:len(path_list)-1]) 143 dir_path = '/'.join(path_list[:len(path_list)-1])
136 device.RunShellCommand('mkdir -p %s' % dir_path, as_root=True) 144 device.RunShellCommand('mkdir -p %s' % dir_path, as_root=True)
137 device.RunShellCommand('restorecon %s' % dir_path, as_root=True) 145 device.RunShellCommand('restorecon %s' % dir_path, as_root=True)
138 device.WriteFile(constants.ADB_KEYS_FILE, adb_keys, as_root=True) 146 adb_key_contents = ''
147 for adb_key in adb_keys:
148 adb_key_contents = '%s/n%s' % (adb_key_contents, adb_key)
friedman1 2015/02/24 23:33:43 \n I take it this is to avoid deailing with the e
149 device.WriteFile(constants.ADB_KEYS_FILE, adb_key_contents, as_root=True)
139 device.RunShellCommand('restorecon %s' % constants.ADB_KEYS_FILE, 150 device.RunShellCommand('restorecon %s' % constants.ADB_KEYS_FILE,
140 as_root=True) 151 as_root=True)
141 152
142
143 def WipeDeviceIfPossible(device, timeout): 153 def WipeDeviceIfPossible(device, timeout):
144 try: 154 try:
145 device.EnableRoot() 155 device.EnableRoot()
146 WipeDeviceData(device) 156 WipeDeviceData(device)
147 device.Reboot(True, timeout=timeout, retries=0) 157 device.Reboot(True, timeout=timeout, retries=0)
148 except (errors.DeviceUnresponsiveError, device_errors.CommandFailedError): 158 except (errors.DeviceUnresponsiveError, device_errors.CommandFailedError):
149 pass 159 pass
150 160
151 161
152 def ProvisionDevice(device, options): 162 def ProvisionDevice(device, options):
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 help='push binary which will reboot the device on adb' 287 help='push binary which will reboot the device on adb'
278 ' disconnections') 288 ' disconnections')
279 args = parser.parse_args() 289 args = parser.parse_args()
280 constants.SetBuildType(args.target) 290 constants.SetBuildType(args.target)
281 291
282 return ProvisionDevices(args) 292 return ProvisionDevices(args)
283 293
284 294
285 if __name__ == '__main__': 295 if __name__ == '__main__':
286 sys.exit(main()) 296 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698