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

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

Issue 970573002: Move writing adb keys into the wipe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use --adb-keys-file argument only when wiping. Created 5 years, 9 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 118
119 def WriteAdbKeysFile(device, adb_keys_string): 119 def WriteAdbKeysFile(device, adb_keys_string):
120 dir_path = posixpath.dirname(constants.ADB_KEYS_FILE) 120 dir_path = posixpath.dirname(constants.ADB_KEYS_FILE)
121 device.RunShellCommand('mkdir -p %s' % dir_path, as_root=True) 121 device.RunShellCommand('mkdir -p %s' % dir_path, as_root=True)
122 device.RunShellCommand('restorecon %s' % dir_path, as_root=True) 122 device.RunShellCommand('restorecon %s' % dir_path, as_root=True)
123 device.WriteFile(constants.ADB_KEYS_FILE, adb_keys_string, as_root=True) 123 device.WriteFile(constants.ADB_KEYS_FILE, adb_keys_string, as_root=True)
124 device.RunShellCommand('restorecon %s' % constants.ADB_KEYS_FILE, 124 device.RunShellCommand('restorecon %s' % constants.ADB_KEYS_FILE,
125 as_root=True) 125 as_root=True)
126 126
127 127
128 def WipeDeviceData(device): 128 def WipeDeviceData(device, options):
129 """Wipes data from device, keeping only the adb_keys for authorization. 129 """Wipes data from device, keeping only the adb_keys for authorization.
130 130
131 After wiping data on a device that has been authorized, adb can still 131 After wiping data on a device that has been authorized, adb can still
132 communicate with the device, but after reboot the device will need to be 132 communicate with the device, but after reboot the device will need to be
133 re-authorized because the adb keys file is stored in /data/misc/adb/. 133 re-authorized because the adb keys file is stored in /data/misc/adb/.
134 Thus, adb_keys file is rewritten so the device does not need to be 134 Thus, adb_keys file is rewritten so the device does not need to be
135 re-authorized. 135 re-authorized.
136 136
137 Arguments: 137 Arguments:
138 device: the device to wipe 138 device: the device to wipe
139 """ 139 """
140 device_authorized = device.FileExists(constants.ADB_KEYS_FILE) 140 device_authorized = device.FileExists(constants.ADB_KEYS_FILE)
141 if device_authorized: 141 if device_authorized:
142 adb_keys = device.ReadFile(constants.ADB_KEYS_FILE, as_root=True) 142 adb_keys = device.ReadFile(constants.ADB_KEYS_FILE,
143 as_root=True).rstrip('\n').split('\n')
jbudorick 2015/03/02 16:13:00 nit: just do device.ReadFile(...).splitlines()
navabi 2015/03/02 16:36:43 Done.
143 device.RunShellCommand('wipe data', as_root=True) 144 device.RunShellCommand('wipe data', as_root=True)
144 if device_authorized: 145 if device_authorized:
145 WriteAdbKeysFile(device, adb_keys) 146 adb_keys_set = set(adb_keys)
147 if options.adb_key_files:
148 for adb_key_file in options.adb_key_files:
jbudorick 2015/03/02 16:13:00 nit: as luqui pointed out to me in another review,
navabi 2015/03/02 16:36:43 Done.
149 with open(adb_key_file, 'r') as f:
150 adb_public_keys = f.readlines()
151 adb_keys_set.update(adb_public_keys)
152 WriteAdbKeysFile(device, '\n'.join(adb_keys_set))
146 153
147 154
148 def WipeDeviceIfPossible(device, timeout): 155 def WipeDeviceIfPossible(device, timeout, options):
149 try: 156 try:
150 device.EnableRoot() 157 device.EnableRoot()
151 WipeDeviceData(device) 158 WipeDeviceData(device, options)
152 device.Reboot(True, timeout=timeout, retries=0) 159 device.Reboot(True, timeout=timeout, retries=0)
153 except (errors.DeviceUnresponsiveError, device_errors.CommandFailedError): 160 except (errors.DeviceUnresponsiveError, device_errors.CommandFailedError):
154 pass 161 pass
155 162
156 163
157 def ChargeDeviceToLevel(device, level): 164 def ChargeDeviceToLevel(device, level):
158 def device_charged(): 165 def device_charged():
159 battery_level = device.GetBatteryInfo().get('level') 166 battery_level = device.GetBatteryInfo().get('level')
160 if battery_level is None: 167 if battery_level is None:
161 logging.warning('Unable to find current battery level.') 168 logging.warning('Unable to find current battery level.')
162 battery_level = 100 169 battery_level = 100
163 else: 170 else:
164 logging.info('current battery level: %d', battery_level) 171 logging.info('current battery level: %d', battery_level)
165 battery_level = int(battery_level) 172 battery_level = int(battery_level)
166 return battery_level >= level 173 return battery_level >= level
167 174
168 timeout_retry.WaitFor(device_charged, wait_period=60) 175 timeout_retry.WaitFor(device_charged, wait_period=60)
169 176
170 177
171 def ProvisionDevice(device, options): 178 def ProvisionDevice(device, options):
172 if options.reboot_timeout: 179 if options.reboot_timeout:
173 reboot_timeout = options.reboot_timeout 180 reboot_timeout = options.reboot_timeout
174 elif (device.build_version_sdk >= 181 elif (device.build_version_sdk >=
175 constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP): 182 constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP):
176 reboot_timeout = _DEFAULT_TIMEOUTS.LOLLIPOP 183 reboot_timeout = _DEFAULT_TIMEOUTS.LOLLIPOP
177 else: 184 else:
178 reboot_timeout = _DEFAULT_TIMEOUTS.PRE_LOLLIPOP 185 reboot_timeout = _DEFAULT_TIMEOUTS.PRE_LOLLIPOP
179 186
180 if options.adb_key_files:
181 adb_keys = set()
182 for adb_key_file in options.adb_key_files:
183 with open(adb_key_file, 'r') as f:
184 adb_public_keys = f.readlines()
185 adb_keys.update(adb_public_keys)
186 WriteAdbKeysFile(device, '\n'.join(adb_keys))
187
188 try: 187 try:
189 if not options.skip_wipe: 188 if not options.skip_wipe:
190 WipeDeviceIfPossible(device, reboot_timeout) 189 WipeDeviceIfPossible(device, reboot_timeout, options)
191 try: 190 try:
192 device.EnableRoot() 191 device.EnableRoot()
193 except device_errors.CommandFailedError as e: 192 except device_errors.CommandFailedError as e:
194 logging.warning(str(e)) 193 logging.warning(str(e))
195 _ConfigureLocalProperties(device, options.enable_java_debug) 194 _ConfigureLocalProperties(device, options.enable_java_debug)
196 device_settings.ConfigureContentSettings( 195 device_settings.ConfigureContentSettings(
197 device, device_settings.DETERMINISTIC_DEVICE_SETTINGS) 196 device, device_settings.DETERMINISTIC_DEVICE_SETTINGS)
198 if options.disable_location: 197 if options.disable_location:
199 device_settings.ConfigureContentSettings( 198 device_settings.ConfigureContentSettings(
200 device, device_settings.DISABLE_LOCATION_SETTINGS) 199 device, device_settings.DISABLE_LOCATION_SETTINGS)
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 parser.add_argument('--adb-key-files', type=str, nargs='+', 293 parser.add_argument('--adb-key-files', type=str, nargs='+',
295 help='list of adb keys to push to device') 294 help='list of adb keys to push to device')
296 args = parser.parse_args() 295 args = parser.parse_args()
297 constants.SetBuildType(args.target) 296 constants.SetBuildType(args.target)
298 297
299 return ProvisionDevices(args) 298 return ProvisionDevices(args)
300 299
301 300
302 if __name__ == '__main__': 301 if __name__ == '__main__':
303 sys.exit(main()) 302 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