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

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

Issue 333933003: [Android] Switch to DeviceUtils version of RunShellCommand. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 6 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 | « build/android/host_heartbeat.py ('k') | build/android/pylib/android_commands.py » ('j') | 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
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)
(...skipping 18 matching lines...) Expand all
166 if not device.old_interface.IsDeviceCharging(): 167 if not device.old_interface.IsDeviceCharging():
167 if device.old_interface.CanControlUsbCharging(): 168 if device.old_interface.CanControlUsbCharging():
168 device.old_interface.EnableUsbCharging() 169 device.old_interface.EnableUsbCharging()
169 else: 170 else:
170 logging.error('Device is not charging') 171 logging.error('Device is not charging')
171 break 172 break
172 logging.info('Waiting for device to charge. Current level=%s', 173 logging.info('Waiting for device to charge. Current level=%s',
173 battery_info.get('level', 0)) 174 battery_info.get('level', 0))
174 time.sleep(60) 175 time.sleep(60)
175 battery_info = device.old_interface.GetBatteryInfo() 176 battery_info = device.old_interface.GetBatteryInfo()
176 device.old_interface.RunShellCommandWithSU('date -u %f' % time.time()) 177 device.RunShellCommand('date -u %f' % time.time(), root=True)
177 try: 178 try:
178 device_utils.DeviceUtils.parallel(devices).Reboot(True) 179 device_utils.DeviceUtils.parallel(devices).Reboot(True)
179 except errors.DeviceUnresponsiveError: 180 except errors.DeviceUnresponsiveError:
180 pass 181 pass
181 for device_serial in devices: 182 for device_serial in devices:
182 device = device_utils.DeviceUtils(device_serial) 183 device = device_utils.DeviceUtils(device_serial)
183 device.WaitUntilFullyBooted(timeout=90) 184 device.WaitUntilFullyBooted(timeout=90)
184 (_, props) = device.old_interface.GetShellCommandStatusAndOutput('getprop') 185 (_, props) = device.old_interface.GetShellCommandStatusAndOutput('getprop')
185 for prop in props: 186 for prop in props:
186 print prop 187 print prop
(...skipping 18 matching lines...) Expand all
205 206
206 if args: 207 if args:
207 print >> sys.stderr, 'Unused args %s' % args 208 print >> sys.stderr, 'Unused args %s' % args
208 return 1 209 return 1
209 210
210 ProvisionDevices(options) 211 ProvisionDevices(options)
211 212
212 213
213 if __name__ == '__main__': 214 if __name__ == '__main__':
214 sys.exit(main(sys.argv)) 215 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « build/android/host_heartbeat.py ('k') | build/android/pylib/android_commands.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698