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