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..fb924920985183a2ff4baa760dc702be98c945e4 |
--- /dev/null |
+++ b/build/android/provision_devices.py |
@@ -0,0 +1,75 @@ |
+#!/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 |
+ |
+ |
+def PushAndLaunchAdbReboot(device, adb_reboot): |
+ print 'Will push and launch adb_reboot on %s' % device |
+ android_cmd = android_commands.AndroidCommands(device) |
+ # Check if adb_reboot is running. If yes, stop it. |
+ dev_procs = android_cmd.RunShellCommand('ps') |
+ for dev_proc in dev_procs: |
+ if 'adb_reboot' in dev_proc: |
+ print ' adb_reboot running. Killing ...' |
+ pid = re.findall('(\d+)', dev_proc)[0] |
+ android_cmd.RunShellCommand('kill %s' % pid) |
+ # Check if the exe is on the device. If yes, delete it. |
+ if android_cmd.FileExistsOnDevice('/data/local/adb_reboot'): |
+ print ' adb_reboot exists on device. Deleting ...' |
+ android_cmd.RunShellCommand('rm /data/local/adb_reboot') |
+ # Push adb_reboot |
+ print ' Pushing adb_reboot ...' |
+ android_cmd.PushIfNeeded('%s' % adb_reboot, '/data/local/') |
+ # Launch adb_reboot |
+ print ' Launching adb_reboot ...' |
+ p1 = subprocess.Popen(['echo', 'cd /data/local; ./adb_reboot; exit'], |
+ stdout=subprocess.PIPE) |
+ subprocess.call(['adb', '-s', device, 'shell'], stdin=p1.stdout) |
+ |
+ |
+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() |
+ android_cmd.RunShellCommand('date -u %f' % time.time()) |
+ PushAndLaunchAdbReboot(device, options.adb_reboot) |
+ |
+ |
+def main(argv): |
+ parser = optparse.OptionParser() |
+ parser.add_option('-d', '--device', dest='device', default=None, |
+ help='The serial number of the device to be provisioned') |
+ parser.add_option('-a', '--adb_reboot', dest='adb_reboot', default=None, |
+ help='Path to the adb_reboot binary') |
+ options, _ = parser.parse_args(argv) |
+ |
+ 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)) |