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

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: Use os.path.dirname and allow multiple keys in adb key files. 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>]
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 '\n'.join(local_props), as_root=True) 106 '\n'.join(local_props), as_root=True)
107 # Android will not respect the local props file if it is world writable. 107 # Android will not respect the local props file if it is world writable.
108 device.RunShellCommand( 108 device.RunShellCommand(
109 ['chmod', '644', constants.DEVICE_LOCAL_PROPERTIES_PATH], 109 ['chmod', '644', constants.DEVICE_LOCAL_PROPERTIES_PATH],
110 as_root=True) 110 as_root=True)
111 except device_errors.CommandFailedError as e: 111 except device_errors.CommandFailedError as e:
112 logging.warning(str(e)) 112 logging.warning(str(e))
113 113
114 # LOCAL_PROPERTIES_PATH = '/data/local.prop' 114 # LOCAL_PROPERTIES_PATH = '/data/local.prop'
115 115
116 def WriteAdbKeysFile(device, adb_keys_string):
117 dir_path = os.path.dirname(constants.ADB_KEYS_FILE)
jbudorick 2015/02/25 21:47:39 Since this is a device path, not a host path, I th
navabi 2015/02/25 23:02:09 Done. Using posixpath.
118 device.RunShellCommand('mkdir -p %s' % dir_path, as_root=True)
119 device.RunShellCommand('restorecon %s' % dir_path, as_root=True)
120 device.WriteFile(constants.ADB_KEYS_FILE, adb_keys_string, as_root=True)
121 device.RunShellCommand('restorecon %s' % constants.ADB_KEYS_FILE,
122 as_root=True)
123
116 124
117 def WipeDeviceData(device): 125 def WipeDeviceData(device):
118 """Wipes data from device, keeping only the adb_keys for authorization. 126 """Wipes data from device, keeping only the adb_keys for authorization.
119 127
120 After wiping data on a device that has been authorized, adb can still 128 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 129 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/. 130 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 131 Thus, adb_keys file is rewritten so the device does not need to be
124 re-authorized. 132 re-authorized.
125 133
126 Arguments: 134 Arguments:
127 device: the device to wipe 135 device: the device to wipe
128 """ 136 """
129 device_authorized = device.FileExists(constants.ADB_KEYS_FILE) 137 device_authorized = device.FileExists(constants.ADB_KEYS_FILE)
130 if device_authorized: 138 if device_authorized:
131 adb_keys = device.ReadFile(constants.ADB_KEYS_FILE, as_root=True) 139 adb_keys = device.ReadFile(constants.ADB_KEYS_FILE, as_root=True)
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 WriteAdbKeysFile(device, adb_keys)
135 dir_path = '/'.join(path_list[:len(path_list)-1])
136 device.RunShellCommand('mkdir -p %s' % dir_path, as_root=True)
137 device.RunShellCommand('restorecon %s' % dir_path, as_root=True)
138 device.WriteFile(constants.ADB_KEYS_FILE, adb_keys, as_root=True)
139 device.RunShellCommand('restorecon %s' % constants.ADB_KEYS_FILE,
140 as_root=True)
141 143
142 144
143 def WipeDeviceIfPossible(device, timeout): 145 def WipeDeviceIfPossible(device, timeout):
144 try: 146 try:
145 device.EnableRoot() 147 device.EnableRoot()
146 WipeDeviceData(device) 148 WipeDeviceData(device)
147 device.Reboot(True, timeout=timeout, retries=0) 149 device.Reboot(True, timeout=timeout, retries=0)
148 except (errors.DeviceUnresponsiveError, device_errors.CommandFailedError): 150 except (errors.DeviceUnresponsiveError, device_errors.CommandFailedError):
149 pass 151 pass
150 152
151 153
152 def ProvisionDevice(device, options): 154 def ProvisionDevice(device, options):
153 if options.reboot_timeout: 155 if options.reboot_timeout:
154 reboot_timeout = options.reboot_timeout 156 reboot_timeout = options.reboot_timeout
155 elif (device.build_version_sdk >= 157 elif (device.build_version_sdk >=
156 constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP): 158 constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP):
157 reboot_timeout = _DEFAULT_TIMEOUTS.LOLLIPOP 159 reboot_timeout = _DEFAULT_TIMEOUTS.LOLLIPOP
158 else: 160 else:
159 reboot_timeout = _DEFAULT_TIMEOUTS.PRE_LOLLIPOP 161 reboot_timeout = _DEFAULT_TIMEOUTS.PRE_LOLLIPOP
160 162
163 if options.adb_key_files:
164 adb_keys = set()
165 for adb_key_file in options.adb_key_files:
166 with open(adb_key_file, 'r') as f:
167 adb_public_keys = f.readlines()
168 adb_keys.update(adb_public_keys)
169 adb_key_contents = '\n'.join(adb_keys)
170 WriteAdbKeysFile(device, adb_key_contents)
jbudorick 2015/02/25 21:47:38 optional nit: these two lines could be collapsed i
navabi 2015/02/25 23:02:09 Done.
171
161 try: 172 try:
162 if not options.skip_wipe: 173 if not options.skip_wipe:
163 WipeDeviceIfPossible(device, reboot_timeout) 174 WipeDeviceIfPossible(device, reboot_timeout)
164 try: 175 try:
165 device.EnableRoot() 176 device.EnableRoot()
166 except device_errors.CommandFailedError as e: 177 except device_errors.CommandFailedError as e:
167 logging.warning(str(e)) 178 logging.warning(str(e))
168 _ConfigureLocalProperties(device, options.enable_java_debug) 179 _ConfigureLocalProperties(device, options.enable_java_debug)
169 device_settings.ConfigureContentSettings( 180 device_settings.ConfigureContentSettings(
170 device, device_settings.DETERMINISTIC_DEVICE_SETTINGS) 181 device, device_settings.DETERMINISTIC_DEVICE_SETTINGS)
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 parser.add_argument('--disable-network', action='store_true', 280 parser.add_argument('--disable-network', action='store_true',
270 help='disable network access on devices') 281 help='disable network access on devices')
271 parser.add_argument('--disable-java-debug', action='store_false', 282 parser.add_argument('--disable-java-debug', action='store_false',
272 dest='enable_java_debug', default=True, 283 dest='enable_java_debug', default=True,
273 help='disable Java property asserts and JNI checking') 284 help='disable Java property asserts and JNI checking')
274 parser.add_argument('-t', '--target', default='Debug', 285 parser.add_argument('-t', '--target', default='Debug',
275 help='the build target (default: %(default)s)') 286 help='the build target (default: %(default)s)')
276 parser.add_argument('-r', '--auto-reconnect', action='store_true', 287 parser.add_argument('-r', '--auto-reconnect', action='store_true',
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')
290 parser.add_argument('--adb-key-files', type=str, nargs='+',
291 help='list of adb keys to push to device')
279 args = parser.parse_args() 292 args = parser.parse_args()
280 constants.SetBuildType(args.target) 293 constants.SetBuildType(args.target)
281 294
282 return ProvisionDevices(args) 295 return ProvisionDevices(args)
283 296
284 297
285 if __name__ == '__main__': 298 if __name__ == '__main__':
286 sys.exit(main()) 299 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