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.utils import timeout_retry |
| 13 |
| 14 _SPLIT_SELECT_PATH = os.path.join(constants.ANDROID_SDK_TOOLS, 'split-select') |
| 15 _DEFAULT_TIMEOUT = 30 |
| 16 _DEFAULT_RETRIES = 2 |
| 17 |
| 18 def _RunSplitSelectCmd(args, timeout=None, retries=None): |
| 19 """Runs a split-select command. |
| 20 |
| 21 Args: |
| 22 args: A list of arguments for split-select. |
| 23 timeout: Timeout in seconds. |
| 24 retries: Number of retries. |
| 25 |
| 26 Returns: |
| 27 The output of the command. |
| 28 """ |
| 29 cmd = [_SPLIT_SELECT_PATH] + args |
| 30 status, output = cmd_helper.GetCmdStatusAndOutputWithTimeout( |
| 31 cmd, timeout_retry.CurrentTimeoutThread().GetRemainingTime()) |
| 32 if status != 0: |
| 33 raise Exception('Failed running command %s' % str(cmd)) |
| 34 return output |
| 35 |
| 36 def _SplitConfig(device): |
| 37 """Returns a config specifying which APK splits are required by the device. |
| 38 |
| 39 Args: |
| 40 device: A DeviceUtils object. |
| 41 """ |
| 42 return ('%s-r%s-%s:%s' % |
| 43 (device.language, |
| 44 device.country, |
| 45 device.screen_density, |
| 46 device.product_cpu_abi)) |
| 47 |
| 48 def SelectSplits(device, base_apk, split_apks, |
| 49 timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES): |
| 50 """Determines which APK splits the device requires. |
| 51 |
| 52 Args: |
| 53 device: A DeviceUtils object. |
| 54 base_apk: The path of the base APK. |
| 55 split_apks: A list of paths of APK splits. |
| 56 timeout: Timeout in seconds. |
| 57 retries: Number of retries. |
| 58 |
| 59 Returns: |
| 60 The list of APK splits that the device requires. |
| 61 """ |
| 62 config = _SplitConfig(device) |
| 63 args = ['--target', config, '--base', base_apk] |
| 64 for split in split_apks: |
| 65 args.extend(['--split', split]) |
| 66 return _RunSplitSelectCmd(args, timeout=timeout, retries=retries).splitlines() |
OLD | NEW |