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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: build/android/provision_devices.py
diff --git a/build/android/provision_devices.py b/build/android/provision_devices.py
new file mode 100755
index 0000000000000000000000000000000000000000..fc939ce44c21e58212c62078fd98c7909803141b
--- /dev/null
+++ b/build/android/provision_devices.py
@@ -0,0 +1,92 @@
+#!/usr/bin/env python
+#
+# Copyright (c) 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Provisions Android devices with settings required for bots.
+
+Usage:
+ ./provision_devices.py [-d <device serial number>]
+"""
+
+import optparse
+import os
+import re
+import subprocess
+import sys
+import time
+
+from pylib import android_commands
+from pylib import constants
+
+
+def PushAndLaunchAdbReboot(device, adb_reboot):
+ """Pushes and launches the adb_reboot binary on the device.
+
+ Arguments:
+ device: The serial number of the device to which the
+ adb_reboot binary should be pushed.
+ adb_reboot: The path to the adb_reboot binary.
+ """
+ print 'Will push and launch adb_reboot on %s' % device
+ android_cmd = android_commands.AndroidCommands(device)
+ # Kill if adb_reboot is already running.
+ android_cmd.KillAllBlocking('adb_reboot', 2)
+ # Push adb_reboot
+ print ' Pushing adb_reboot ...'
+ android_cmd.PushIfNeeded(adb_reboot, '/data/local/')
+ # Launch adb_reboot
+ print ' Launching adb_reboot ...'
+ p = subprocess.Popen(['adb', '-s', device, 'shell'], stdin=subprocess.PIPE)
+ p.communicate('/data/local/adb_reboot; exit\n')
+
+
+def LaunchHostHeartbeat():
+ ps = subprocess.Popen(['ps', 'aux'], stdout = subprocess.PIPE)
+ stdout, _ = ps.communicate()
+ matches = re.findall('\\n.*host_heartbeat.*', stdout)
+ for match in matches:
+ print 'An instance of host heart beart already running... will kill'
+ pid = re.findall('(\d+)', match)[1]
+ subprocess.call(['kill', '%s' % str(pid)])
Isaac (away) 2013/03/29 00:18:33 '%s' % <string> is a no-op. Just use <string> or
Siva Chandra 2013/03/29 01:47:06 Done.
+ # Launch a new host_heartbeat
+ print 'Spawing host heartbeat...'
+ subprocess.Popen([os.path.join(constants.CHROME_DIR,
+ 'build/android/host_heartbeat.py')])
+
+
+def ProvisionDevices(options):
+ if options.device is not None:
+ devices = [options.device]
+ else:
+ devices = android_commands.GetAttachedDevices()
+ for device in devices:
+ android_cmd = android_commands.AndroidCommands(device)
+ android_cmd.EnableAdbRoot()
Isaac (away) 2013/03/29 00:18:33 This will convert phone to root until the phone is
Siva Chandra 2013/03/29 01:47:06 Removed enabling root.
+ android_cmd.RunShellCommand('date -u %f' % time.time())
+ PushAndLaunchAdbReboot(device, options.adb_reboot)
+ LaunchHostHeartbeat()
+
+
+def main(argv):
+ parser = optparse.OptionParser()
+ parser.add_option('-d', '--device', dest='device',
Isaac (away) 2013/03/29 00:18:33 remove dest param, unneeded
Siva Chandra 2013/03/29 01:47:06 Done.
+ help='The serial number of the device to be provisioned')
+ parser.add_option('-a', '--adb-reboot', dest='adb_reboot',
Isaac (away) 2013/03/29 00:18:33 dest param unneded. Also I'd rather this script t
Siva Chandra 2013/03/29 01:47:06 Done.
+ help='Path to the adb_reboot binary')
+ options, args = parser.parse_args(argv[1:])
+
+ if args:
+ print >> sys.stderr, 'Unused args %s' % args
+ return 1
+
+ if not options.adb_reboot:
+ print >> sys.stderr, 'Path to adb_reboot not specified'
+ return 1
+
+ ProvisionDevices(options)
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))

Powered by Google App Engine
This is Rietveld 408576698