OLD | NEW |
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>] |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 88 |
89 # LOCAL_PROPERTIES_PATH = '/data/local.prop' | 89 # LOCAL_PROPERTIES_PATH = '/data/local.prop' |
90 | 90 |
91 | 91 |
92 def WipeDeviceData(device): | 92 def WipeDeviceData(device): |
93 """Wipes data from device, keeping only the adb_keys for authorization. | 93 """Wipes data from device, keeping only the adb_keys for authorization. |
94 | 94 |
95 After wiping data on a device that has been authorized, adb can still | 95 After wiping data on a device that has been authorized, adb can still |
96 communicate with the device, but after reboot the device will need to be | 96 communicate with the device, but after reboot the device will need to be |
97 re-authorized because the adb keys file is stored in /data/misc/adb/. | 97 re-authorized because the adb keys file is stored in /data/misc/adb/. |
98 Thus, before reboot the adb_keys file is rewritten so the device does not need | 98 Thus, adb_keys file is rewritten so the device does not need to be |
99 to be re-authorized. | 99 re-authorized. |
100 | 100 |
101 Arguments: | 101 Arguments: |
102 device: the device to wipe | 102 device: the device to wipe |
103 """ | 103 """ |
104 device_authorized = device.old_interface.FileExistsOnDevice( | 104 device_authorized = device.old_interface.FileExistsOnDevice( |
105 constants.ADB_KEYS_FILE) | 105 constants.ADB_KEYS_FILE) |
106 if device_authorized: | 106 if device_authorized: |
107 adb_keys = device.old_interface.RunShellCommandWithSU( | 107 adb_keys = device.old_interface.RunShellCommandWithSU( |
108 'cat %s' % constants.ADB_KEYS_FILE)[0] | 108 'cat %s' % constants.ADB_KEYS_FILE) |
109 device.old_interface.RunShellCommandWithSU('wipe data') | 109 device.old_interface.RunShellCommandWithSU('wipe data') |
110 if device_authorized: | 110 if device_authorized: |
111 path_list = constants.ADB_KEYS_FILE.split('/') | 111 path_list = constants.ADB_KEYS_FILE.split('/') |
112 dir_path = '/'.join(path_list[:len(path_list)-1]) | 112 dir_path = '/'.join(path_list[:len(path_list)-1]) |
113 device.old_interface.RunShellCommandWithSU('mkdir -p %s' % dir_path) | 113 device.old_interface.RunShellCommandWithSU('mkdir -p %s' % dir_path) |
114 adb_keys = device.old_interface.RunShellCommand( | 114 device.old_interface.RunShellCommand('echo %s > %s' % |
115 'echo %s > %s' % (adb_keys, constants.ADB_KEYS_FILE)) | 115 (adb_keys[0], constants.ADB_KEYS_FILE)) |
116 device.old_interface.Reboot() | 116 for adb_key in adb_keys[1:]: |
| 117 device.old_interface.RunShellCommand( |
| 118 'echo %s >> %s' % (adb_key, constants.ADB_KEYS_FILE)) |
117 | 119 |
118 | 120 |
119 def ProvisionDevices(options): | 121 def ProvisionDevices(options): |
120 if options.device is not None: | 122 if options.device is not None: |
121 devices = [options.device] | 123 devices = [options.device] |
122 else: | 124 else: |
123 devices = android_commands.GetAttachedDevices() | 125 devices = android_commands.GetAttachedDevices() |
124 for device_serial in devices: | 126 for device_serial in devices: |
125 device = device_utils.DeviceUtils(device_serial) | 127 device = device_utils.DeviceUtils(device_serial) |
126 device.old_interface.EnableAdbRoot() | 128 device.old_interface.EnableAdbRoot() |
(...skipping 18 matching lines...) Expand all Loading... |
145 for prop in props: | 147 for prop in props: |
146 print prop | 148 print prop |
147 if options.auto_reconnect: | 149 if options.auto_reconnect: |
148 PushAndLaunchAdbReboot(devices, options.target) | 150 PushAndLaunchAdbReboot(devices, options.target) |
149 | 151 |
150 | 152 |
151 def main(argv): | 153 def main(argv): |
152 logging.basicConfig(level=logging.INFO) | 154 logging.basicConfig(level=logging.INFO) |
153 | 155 |
154 parser = optparse.OptionParser() | 156 parser = optparse.OptionParser() |
| 157 parser.add_option('-w', '--wipe', action='store_true', |
| 158 help='Wipe device data from all attached devices.') |
155 parser.add_option('-d', '--device', | 159 parser.add_option('-d', '--device', |
156 help='The serial number of the device to be provisioned') | 160 help='The serial number of the device to be provisioned') |
157 parser.add_option('-t', '--target', default='Debug', help='The build target') | 161 parser.add_option('-t', '--target', default='Debug', help='The build target') |
158 parser.add_option( | 162 parser.add_option( |
159 '-r', '--auto-reconnect', action='store_true', | 163 '-r', '--auto-reconnect', action='store_true', |
160 help='Push binary which will reboot the device on adb disconnections.') | 164 help='Push binary which will reboot the device on adb disconnections.') |
161 options, args = parser.parse_args(argv[1:]) | 165 options, args = parser.parse_args(argv[1:]) |
162 constants.SetBuildType(options.target) | 166 constants.SetBuildType(options.target) |
163 | 167 |
164 if args: | 168 if args: |
165 print >> sys.stderr, 'Unused args %s' % args | 169 print >> sys.stderr, 'Unused args %s' % args |
166 return 1 | 170 return 1 |
167 | 171 |
168 ProvisionDevices(options) | 172 if options.wipe: |
| 173 devices = android_commands.GetAttachedDevices() |
| 174 for device_serial in devices: |
| 175 device = device_utils.DeviceUtils(device_serial) |
| 176 WipeDeviceData(device) |
| 177 device_utils.RebootDevices() |
| 178 else: |
| 179 ProvisionDevices(options) |
169 | 180 |
170 | 181 |
171 if __name__ == '__main__': | 182 if __name__ == '__main__': |
172 sys.exit(main(sys.argv)) | 183 sys.exit(main(sys.argv)) |
OLD | NEW |