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

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

Issue 338353004: [Android] Switch KillAll, StartActivity, and BroadcastIntent to DeviceUtils. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address frankf comments 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
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 logging 13 import logging
14 import optparse 14 import optparse
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_errors
24 from pylib.device import device_utils 25 from pylib.device import device_utils
25 26
26 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, 27 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT,
27 'third_party', 'android_testrunner')) 28 'third_party', 'android_testrunner'))
28 import errors 29 import errors
29 30
30 def KillHostHeartbeat(): 31 def KillHostHeartbeat():
31 ps = subprocess.Popen(['ps', 'aux'], stdout = subprocess.PIPE) 32 ps = subprocess.Popen(['ps', 'aux'], stdout = subprocess.PIPE)
32 stdout, _ = ps.communicate() 33 stdout, _ = ps.communicate()
33 matches = re.findall('\\n.*host_heartbeat.*', stdout) 34 matches = re.findall('\\n.*host_heartbeat.*', stdout)
(...skipping 18 matching lines...) Expand all
52 Arguments: 53 Arguments:
53 devices: The list of serial numbers of the device to which the 54 devices: The list of serial numbers of the device to which the
54 adb_reboot binary should be pushed. 55 adb_reboot binary should be pushed.
55 target : The build target (example, Debug or Release) which helps in 56 target : The build target (example, Debug or Release) which helps in
56 locating the adb_reboot binary. 57 locating the adb_reboot binary.
57 """ 58 """
58 for device_serial in devices: 59 for device_serial in devices:
59 print 'Will push and launch adb_reboot on %s' % device_serial 60 print 'Will push and launch adb_reboot on %s' % device_serial
60 device = device_utils.DeviceUtils(device_serial) 61 device = device_utils.DeviceUtils(device_serial)
61 # Kill if adb_reboot is already running. 62 # Kill if adb_reboot is already running.
62 device.old_interface.KillAllBlocking('adb_reboot', 2) 63 try:
64 # Don't try to kill adb_reboot more than once. We don't expect it to be
65 # running at all.
66 device.KillAll('adb_reboot', blocking=True, timeout=2, retries=0)
67 except device_errors.CommandFailedError:
68 # We can safely ignore the exception because we don't expect adb_reboot
69 # to be running.
70 pass
63 # Push adb_reboot 71 # Push adb_reboot
64 print ' Pushing adb_reboot ...' 72 print ' Pushing adb_reboot ...'
65 adb_reboot = os.path.join(constants.DIR_SOURCE_ROOT, 73 adb_reboot = os.path.join(constants.DIR_SOURCE_ROOT,
66 'out/%s/adb_reboot' % target) 74 'out/%s/adb_reboot' % target)
67 device.old_interface.PushIfNeeded(adb_reboot, '/data/local/tmp/') 75 device.old_interface.PushIfNeeded(adb_reboot, '/data/local/tmp/')
68 # Launch adb_reboot 76 # Launch adb_reboot
69 print ' Launching adb_reboot ...' 77 print ' Launching adb_reboot ...'
70 device.old_interface.GetAndroidToolStatusAndOutput( 78 device.old_interface.GetAndroidToolStatusAndOutput(
71 '/data/local/tmp/adb_reboot') 79 '/data/local/tmp/adb_reboot')
72 LaunchHostHeartbeat() 80 LaunchHostHeartbeat()
73 81
74 82
75 def _ConfigureLocalProperties(device): 83 def _ConfigureLocalProperties(device):
76 """Set standard readonly testing device properties prior to reboot.""" 84 """Set standard readonly testing device properties prior to reboot."""
77 local_props = [ 85 local_props = [
78 'ro.monkey=1', 86 'ro.monkey=1',
79 'ro.test_harness=1', 87 'ro.test_harness=1',
80 'ro.audio.silent=1', 88 'ro.audio.silent=1',
81 'ro.setupwizard.mode=DISABLED', 89 'ro.setupwizard.mode=DISABLED',
82 ] 90 ]
83 device.old_interface.SetProtectedFileContents( 91 device.old_interface.SetProtectedFileContents(
84 constants.DEVICE_LOCAL_PROPERTIES_PATH, 92 constants.DEVICE_LOCAL_PROPERTIES_PATH,
85 '\n'.join(local_props)) 93 '\n'.join(local_props))
86 # Android will not respect the local props file if it is world writable. 94 # Android will not respect the local props file if it is world writable.
87 device.RunShellCommand( 95 device.RunShellCommand(
88 'chmod 644 %s' % constants.DEVICE_LOCAL_PROPERTIES_PATH, 96 'chmod 644 %s' % constants.DEVICE_LOCAL_PROPERTIES_PATH,
89 root=True) 97 as_root=True)
90 98
91 # LOCAL_PROPERTIES_PATH = '/data/local.prop' 99 # LOCAL_PROPERTIES_PATH = '/data/local.prop'
92 100
93 101
94 def WipeDeviceData(device): 102 def WipeDeviceData(device):
95 """Wipes data from device, keeping only the adb_keys for authorization. 103 """Wipes data from device, keeping only the adb_keys for authorization.
96 104
97 After wiping data on a device that has been authorized, adb can still 105 After wiping data on a device that has been authorized, adb can still
98 communicate with the device, but after reboot the device will need to be 106 communicate with the device, but after reboot the device will need to be
99 re-authorized because the adb keys file is stored in /data/misc/adb/. 107 re-authorized because the adb keys file is stored in /data/misc/adb/.
100 Thus, adb_keys file is rewritten so the device does not need to be 108 Thus, adb_keys file is rewritten so the device does not need to be
101 re-authorized. 109 re-authorized.
102 110
103 Arguments: 111 Arguments:
104 device: the device to wipe 112 device: the device to wipe
105 """ 113 """
106 device_authorized = device.old_interface.FileExistsOnDevice( 114 device_authorized = device.old_interface.FileExistsOnDevice(
107 constants.ADB_KEYS_FILE) 115 constants.ADB_KEYS_FILE)
108 if device_authorized: 116 if device_authorized:
109 adb_keys = device.RunShellCommand('cat %s' % constants.ADB_KEYS_FILE, 117 adb_keys = device.RunShellCommand('cat %s' % constants.ADB_KEYS_FILE,
110 root=True) 118 as_root=True)
111 device.RunShellCommand('wipe data', root=True) 119 device.RunShellCommand('wipe data', as_root=True)
112 if device_authorized: 120 if device_authorized:
113 path_list = constants.ADB_KEYS_FILE.split('/') 121 path_list = constants.ADB_KEYS_FILE.split('/')
114 dir_path = '/'.join(path_list[:len(path_list)-1]) 122 dir_path = '/'.join(path_list[:len(path_list)-1])
115 device.RunShellCommand('mkdir -p %s' % dir_path, root=True) 123 device.RunShellCommand('mkdir -p %s' % dir_path, as_root=True)
116 device.RunShellCommand('echo %s > %s' % 124 device.RunShellCommand('echo %s > %s' %
117 (adb_keys[0], constants.ADB_KEYS_FILE)) 125 (adb_keys[0], constants.ADB_KEYS_FILE))
118 for adb_key in adb_keys[1:]: 126 for adb_key in adb_keys[1:]:
119 device.RunShellCommand( 127 device.RunShellCommand(
120 'echo %s >> %s' % (adb_key, constants.ADB_KEYS_FILE)) 128 'echo %s >> %s' % (adb_key, constants.ADB_KEYS_FILE))
121 129
122 130
123 def ProvisionDevices(options): 131 def ProvisionDevices(options):
124 # TODO(jbudorick): Parallelize provisioning of all attached devices after 132 # TODO(jbudorick): Parallelize provisioning of all attached devices after
125 # switching from AndroidCommands. 133 # switching from AndroidCommands.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 if not device.old_interface.IsDeviceCharging(): 179 if not device.old_interface.IsDeviceCharging():
172 if device.old_interface.CanControlUsbCharging(): 180 if device.old_interface.CanControlUsbCharging():
173 device.old_interface.EnableUsbCharging() 181 device.old_interface.EnableUsbCharging()
174 else: 182 else:
175 logging.error('Device is not charging') 183 logging.error('Device is not charging')
176 break 184 break
177 logging.info('Waiting for device to charge. Current level=%s', 185 logging.info('Waiting for device to charge. Current level=%s',
178 battery_info.get('level', 0)) 186 battery_info.get('level', 0))
179 time.sleep(60) 187 time.sleep(60)
180 battery_info = device.old_interface.GetBatteryInfo() 188 battery_info = device.old_interface.GetBatteryInfo()
181 device.RunShellCommand('date -u %f' % time.time(), root=True) 189 device.RunShellCommand('date -u %f' % time.time(), as_root=True)
182 try: 190 try:
183 device_utils.DeviceUtils.parallel(devices).Reboot(True) 191 device_utils.DeviceUtils.parallel(devices).Reboot(True)
184 except errors.DeviceUnresponsiveError: 192 except errors.DeviceUnresponsiveError:
185 pass 193 pass
186 for device_serial in devices: 194 for device_serial in devices:
187 device = device_utils.DeviceUtils(device_serial) 195 device = device_utils.DeviceUtils(device_serial)
188 device.WaitUntilFullyBooted(timeout=90) 196 device.WaitUntilFullyBooted(timeout=90)
189 (_, props) = device.old_interface.GetShellCommandStatusAndOutput('getprop') 197 (_, props) = device.old_interface.GetShellCommandStatusAndOutput('getprop')
190 for prop in props: 198 for prop in props:
191 print prop 199 print prop
(...skipping 20 matching lines...) Expand all
212 220
213 if args: 221 if args:
214 print >> sys.stderr, 'Unused args %s' % args 222 print >> sys.stderr, 'Unused args %s' % args
215 return 1 223 return 1
216 224
217 ProvisionDevices(options) 225 ProvisionDevices(options)
218 226
219 227
220 if __name__ == '__main__': 228 if __name__ == '__main__':
221 sys.exit(main(sys.argv)) 229 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « no previous file | build/android/pylib/android_commands.py » ('j') | build/android/pylib/device/device_utils.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698