X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fbuild%2Fandroid%2Fprovision_devices.py;h=83c02a2a607a3fb75aed1c0258ac59571e9491bb;hb=004985e17e624662a4c85c76a7654039dc83f028;hp=53eb373ef8c43aa492bd1677c7b35fbb58c15c20;hpb=2f108dbacb161091e42a3479f4e171339b7e7623;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/build/android/provision_devices.py b/src/build/android/provision_devices.py index 53eb373..83c02a2 100755 --- a/src/build/android/provision_devices.py +++ b/src/build/android/provision_devices.py @@ -22,7 +22,7 @@ from pylib import android_commands from pylib import constants from pylib import device_settings from pylib.cmd_helper import GetCmdOutput - +from pylib.device import device_utils def KillHostHeartbeat(): ps = subprocess.Popen(['ps', 'aux'], stdout = subprocess.PIPE) @@ -52,24 +52,26 @@ def PushAndLaunchAdbReboot(devices, target): target : The build target (example, Debug or Release) which helps in locating the adb_reboot binary. """ - for device in devices: - print 'Will push and launch adb_reboot on %s' % device - android_cmd = android_commands.AndroidCommands(device) + for device_serial in devices: + print 'Will push and launch adb_reboot on %s' % device_serial + device = device_utils.DeviceUtils(device_serial) # Kill if adb_reboot is already running. - android_cmd.KillAllBlocking('adb_reboot', 2) + device.old_interface.KillAllBlocking('adb_reboot', 2) # Push adb_reboot print ' Pushing adb_reboot ...' adb_reboot = os.path.join(constants.DIR_SOURCE_ROOT, 'out/%s/adb_reboot' % target) - android_cmd.PushIfNeeded(adb_reboot, '/data/local/tmp/') + device.old_interface.PushIfNeeded(adb_reboot, '/data/local/tmp/') # Launch adb_reboot print ' Launching adb_reboot ...' - p = subprocess.Popen(['adb', '-s', device, 'shell'], stdin=subprocess.PIPE) + # TODO(jbudorick) Try to convert this to RunShellCommand. + p = subprocess.Popen(['adb', '-s', device_serial, 'shell'], + stdin=subprocess.PIPE) p.communicate('/data/local/tmp/adb_reboot; exit\n') LaunchHostHeartbeat() -def _ConfigureLocalProperties(adb): +def _ConfigureLocalProperties(device): """Set standard readonly testing device properties prior to reboot.""" local_props = [ 'ro.monkey=1', @@ -77,11 +79,14 @@ def _ConfigureLocalProperties(adb): 'ro.audio.silent=1', 'ro.setupwizard.mode=DISABLED', ] - adb.SetProtectedFileContents(android_commands.LOCAL_PROPERTIES_PATH, - '\n'.join(local_props)) + device.old_interface.SetProtectedFileContents( + constants.DEVICE_LOCAL_PROPERTIES_PATH, + '\n'.join(local_props)) # Android will not respect the local props file if it is world writable. - adb.RunShellCommandWithSU('chmod 644 %s' % - android_commands.LOCAL_PROPERTIES_PATH) + device.old_interface.RunShellCommandWithSU( + 'chmod 644 %s' % constants.DEVICE_LOCAL_PROPERTIES_PATH) + + # LOCAL_PROPERTIES_PATH = '/data/local.prop' def WipeDeviceData(device): @@ -90,25 +95,27 @@ def WipeDeviceData(device): After wiping data on a device that has been authorized, adb can still communicate with the device, but after reboot the device will need to be re-authorized because the adb keys file is stored in /data/misc/adb/. - Thus, before reboot the adb_keys file is rewritten so the device does not need - to be re-authorized. + Thus, adb_keys file is rewritten so the device does not need to be + re-authorized. Arguments: device: the device to wipe """ - android_cmd = android_commands.AndroidCommands(device) - device_authorized = android_cmd.FileExistsOnDevice(constants.ADB_KEYS_FILE) + device_authorized = device.old_interface.FileExistsOnDevice( + constants.ADB_KEYS_FILE) if device_authorized: - adb_keys = android_cmd.RunShellCommandWithSU( - 'cat %s' % constants.ADB_KEYS_FILE)[0] - android_cmd.RunShellCommandWithSU('wipe data') + adb_keys = device.old_interface.RunShellCommandWithSU( + 'cat %s' % constants.ADB_KEYS_FILE) + device.old_interface.RunShellCommandWithSU('wipe data') if device_authorized: path_list = constants.ADB_KEYS_FILE.split('/') dir_path = '/'.join(path_list[:len(path_list)-1]) - android_cmd.RunShellCommandWithSU('mkdir -p %s' % dir_path) - adb_keys = android_cmd.RunShellCommand( - 'echo %s > %s' % (adb_keys, constants.ADB_KEYS_FILE)) - android_cmd.Reboot() + device.old_interface.RunShellCommandWithSU('mkdir -p %s' % dir_path) + device.old_interface.RunShellCommand('echo %s > %s' % + (adb_keys[0], constants.ADB_KEYS_FILE)) + for adb_key in adb_keys[1:]: + device.old_interface.RunShellCommand( + 'echo %s >> %s' % (adb_key, constants.ADB_KEYS_FILE)) def ProvisionDevices(options): @@ -116,8 +123,9 @@ def ProvisionDevices(options): devices = [options.device] else: devices = android_commands.GetAttachedDevices() - for device in devices: - android_cmd = android_commands.AndroidCommands(device) + for device_serial in devices: + device = device_utils.DeviceUtils(device_serial) + device.old_interface.EnableAdbRoot() install_output = GetCmdOutput( ['%s/build/android/adb_install_apk.py' % constants.DIR_SOURCE_ROOT, '--apk', @@ -126,15 +134,18 @@ def ProvisionDevices(options): failure_string = 'Failure [INSTALL_FAILED_INSUFFICIENT_STORAGE]' if failure_string in install_output: WipeDeviceData(device) - _ConfigureLocalProperties(android_cmd) + _ConfigureLocalProperties(device) device_settings.ConfigureContentSettingsDict( - android_cmd, device_settings.DETERMINISTIC_DEVICE_SETTINGS) + device, device_settings.DETERMINISTIC_DEVICE_SETTINGS) # TODO(tonyg): We eventually want network on. However, currently radios # can cause perfbots to drain faster than they charge. if 'perf' in os.environ.get('BUILDBOT_BUILDERNAME', '').lower(): device_settings.ConfigureContentSettingsDict( - android_cmd, device_settings.NETWORK_DISABLED_SETTINGS) - android_cmd.RunShellCommandWithSU('date -u %f' % time.time()) + device, device_settings.NETWORK_DISABLED_SETTINGS) + device.old_interface.RunShellCommandWithSU('date -u %f' % time.time()) + (_, props) = device.old_interface.GetShellCommandStatusAndOutput('getprop') + for prop in props: + print prop if options.auto_reconnect: PushAndLaunchAdbReboot(devices, options.target) @@ -143,6 +154,8 @@ def main(argv): logging.basicConfig(level=logging.INFO) parser = optparse.OptionParser() + parser.add_option('-w', '--wipe', action='store_true', + help='Wipe device data from all attached devices.') parser.add_option('-d', '--device', help='The serial number of the device to be provisioned') parser.add_option('-t', '--target', default='Debug', help='The build target') @@ -156,7 +169,14 @@ def main(argv): print >> sys.stderr, 'Unused args %s' % args return 1 - ProvisionDevices(options) + if options.wipe: + devices = android_commands.GetAttachedDevices() + for device_serial in devices: + device = device_utils.DeviceUtils(device_serial) + WipeDeviceData(device) + device_utils.RebootDevices() + else: + ProvisionDevices(options) if __name__ == '__main__':