Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 """This module wraps Android's split-select tool.""" | |
| 6 # pylint: disable=unused-argument | |
| 7 | |
| 8 import os | |
| 9 | |
| 10 from pylib import cmd_helper | |
| 11 from pylib import constants | |
| 12 from pylib.device import decorators | |
| 13 from pylib.device import device_errors | |
| 14 from pylib.utils import timeout_retry | |
| 15 | |
| 16 _SPLIT_SELECT_PATH = os.path.join(constants.ANDROID_SDK_TOOLS, 'split-select') | |
| 17 _DEFAULT_TIMEOUT = 30 | |
| 18 _DEFAULT_RETRIES = 2 | |
| 19 | |
| 20 @decorators.WithTimeoutAndRetries | |
| 21 def _RunSplitSelectCmd(args, timeout=None, retries=None, | |
| 22 check_error=True): | |
| 23 """Runs a split-select command. | |
| 24 | |
| 25 Args: | |
| 26 args: A list of arguments for split-select. | |
| 27 timeout: Timeout in seconds. | |
| 28 retries: Number of retries. | |
| 29 check_error: Check that the command doesn't return an error message. | |
| 30 | |
| 31 Returns: | |
| 32 The output of the command. | |
| 33 """ | |
| 34 cmd = [_SPLIT_SELECT_PATH] + args | |
| 35 status, output = cmd_helper.GetCmdStatusAndOutputWithTimeout( | |
| 36 cmd, timeout_retry.CurrentTimeoutThread().GetRemainingTime()) | |
| 37 if status != 0: | |
| 38 raise device_errors.CommandFailedError( | |
| 39 'Failed running command %s' % str(cmd)) | |
| 40 if check_error and output.startswith('error:'): | |
| 41 raise device_errors.CommandFailedError( | |
| 42 'Failed command %s with output %s' % (str(cmd), output)) | |
|
perezju
2015/06/18 09:30:17
I'm not sure if these are supposed to be "device"
mikecase (-- gone --)
2015/06/18 19:22:20
Changed to just raise an Exception.
| |
| 43 return output | |
| 44 | |
| 45 def _SplitConfig(device): | |
| 46 """Returns a config specifying which APK splits are required by the device. | |
| 47 | |
| 48 Args: | |
| 49 device: A DeviceUtils object. | |
| 50 """ | |
| 51 return ('%s-r%s-%s:%s' % | |
| 52 (device.langauge_setting, | |
| 53 device.country_setting, | |
| 54 device.screen_density, | |
| 55 device.product_cpu_abi)) | |
| 56 | |
| 57 def SelectSplits(device, base_apk, split_apks, | |
| 58 timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES): | |
| 59 """Determines which APK splits the device requires. | |
| 60 | |
| 61 Args: | |
| 62 device: A DeviceUtils object. | |
| 63 base_apk: The path of the base APK. | |
| 64 split_apks: A list of paths of APK splits. | |
| 65 timeout: Timeout in seconds. | |
| 66 retries: Number of retries. | |
| 67 | |
| 68 Returns: | |
| 69 The list of APK splits that the device requires. | |
| 70 """ | |
| 71 config = _SplitConfig(device) | |
| 72 args = ['--target', config, '--base', base_apk] | |
| 73 for split in split_apks: | |
| 74 args.extend(['--split', split]) | |
| 75 return _RunSplitSelectCmd(args, timeout=timeout, retries=retries).splitlines() | |
| OLD | NEW |