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

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

Issue 12733012: Provision Android devices after the 'device_status_check' step. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address ilevy's comments Created 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
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
5 # found in the LICENSE file.
6
7 """Provisions Android devices with settings required for bots.
8
9 Usage:
10 ./provision_devices.py [-d <device serial number>]
11 """
12
13 import optparse
14 import os
15 import re
16 import subprocess
17 import sys
18 import time
19
20 from pylib import android_commands
21
22
23 def PushAndLaunchAdbReboot(device, adb_reboot):
24 print 'Will push and launch adb_reboot on %s' % device
25 android_cmd = android_commands.AndroidCommands(device)
26 # Check if adb_reboot is running. If yes, stop it.
27 dev_procs = android_cmd.RunShellCommand('ps')
28 for dev_proc in dev_procs:
29 if 'adb_reboot' in dev_proc:
30 print ' adb_reboot running. Killing ...'
31 pid = re.findall('(\d+)', dev_proc)[0]
32 android_cmd.RunShellCommand('kill %s' % pid)
33 # Check if the exe is on the device. If yes, delete it.
34 if android_cmd.FileExistsOnDevice('/data/local/adb_reboot'):
35 print ' adb_reboot exists on device. Deleting ...'
36 android_cmd.RunShellCommand('rm /data/local/adb_reboot')
37 # Push adb_reboot
38 print ' Pushing adb_reboot ...'
39 android_cmd.PushIfNeeded('%s' % adb_reboot, '/data/local/')
40 # Launch adb_reboot
41 print ' Launching adb_reboot ...'
42 p1 = subprocess.Popen(['echo', 'cd /data/local; ./adb_reboot; exit'],
43 stdout=subprocess.PIPE)
44 subprocess.call(['adb', '-s', device, 'shell'], stdin=p1.stdout)
45
46
47 def ProvisionDevices(options):
48 if options.device is not None:
49 devices = [options.device]
50 else:
51 devices = android_commands.GetAttachedDevices()
52 for device in devices:
53 android_cmd = android_commands.AndroidCommands(device)
54 android_cmd.EnableAdbRoot()
55 android_cmd.RunShellCommand('date -u %f' % time.time())
56 PushAndLaunchAdbReboot(device, options.adb_reboot)
57
58
59 def main(argv):
60 parser = optparse.OptionParser()
61 parser.add_option('-d', '--device', dest='device', default=None,
62 help='The serial number of the device to be provisioned')
63 parser.add_option('-a', '--adb_reboot', dest='adb_reboot', default=None,
64 help='Path to the adb_reboot binary')
65 options, _ = parser.parse_args(argv)
66
67 if not options.adb_reboot:
68 print >> sys.stderr, 'Path to adb_reboot not specified'
69 return -1
70
71 ProvisionDevices(options)
72
73
74 if __name__ == '__main__':
75 sys.exit(main(sys.argv))
OLDNEW
« build/android/buildbot/bb_device_steps.py ('K') | « build/android/buildbot/bb_device_steps.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698