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..416a6839cfcccb5c096497312468aec17408699b |
--- /dev/null |
+++ b/build/android/provision_devices.py |
@@ -0,0 +1,69 @@ |
+#!/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 sys |
+import thread |
+import time |
+ |
+from pylib import android_commands |
+ |
+ |
+def PushAndLaunchAdbReboot(device, adb_reboot): |
+ android_cmd = android_commands.AndroidCommands(device) |
+ # Check if adb_reboot is running. If yes, stop it. |
+ output = android_cmd.RunShellCommand('ps | grep adb_reboot') |
+ if output and 'adb_reboot' in output[0]: |
+ pid = re.findall('(\d+)', output[0])[0] |
+ android_cmd.RunShellCommand('kill %d' % pid) |
+ # Check if the exe is on the device. If yes, delete it. |
+ if android_cmd.FileExistsOnDevice('/data/local/adb_reboot'): |
+ android_cmd.RunShellCommand('rm /data/local/adb_reboot') |
+ # Push adb_reboot |
+ android_cmd.PushIfNeeded('%s' % adb_reboot, '/data/local/') |
+ # Launch adb_reboot |
+ cmd = 'echo "cd /data/local; ./adb_reboot; exit" | adb -s %s shell' % device |
+ thread.start_new_thread(os.system, (cmd,)) |
+ time.sleep(1) |
+ |
+ |
+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)) |