Chromium Code Reviews| Index: build/android/devil/android/sdk/fastboot.py |
| diff --git a/build/android/devil/android/sdk/fastboot.py b/build/android/devil/android/sdk/fastboot.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ab84d0a42fed16ce2c9763ca60efcdd7a1c8bc2d |
| --- /dev/null |
| +++ b/build/android/devil/android/sdk/fastboot.py |
| @@ -0,0 +1,85 @@ |
| +# Copyright 2015 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +"""This module wraps Android's fastboot tool. |
| + |
| +This is a thin wrapper around the fastboot interface. Any additional complexity |
| +should be delegated to a higher level (ex. FastbootUtils). |
| +""" |
| + |
| +import os |
| + |
| +from devil.android import device_errors |
| +from devil.utils import cmd_helper |
| +from pylib import constants |
| + |
| +_FASTBOOT_CMD = os.path.join( |
| + constants.ANDROID_SDK_ROOT, 'platform-tools', 'fastboot') |
| + |
| + |
| +class Fastboot(object): |
| + |
| + def __init__(self, device_serial): |
| + """Initializes the FastbootWrapper. |
| + |
| + Args: |
| + device_serial: The device serial number as a string. |
| + """ |
| + if not device_serial: |
| + raise ValueError('A device serial must be specified') |
| + self._device_serial = str(device_serial) |
| + |
| + def _RunFastbootCommand(self, cmd): |
|
jbudorick
2015/10/29 13:29:22
Should any of these functions be timeout/retry dec
rnephew (Reviews Here)
2015/10/29 16:37:35
Since most of the commands are rebooting commands,
|
| + """Run a command line command using the fastboot android tool. |
| + |
| + Args: |
| + cmd: Command to run. Must be list of args, the first one being the command |
| + |
| + Returns: |
| + output of command. |
| + |
| + Raises: |
| + TypeError: If cmd is not of type list. |
| + """ |
| + if type(cmd) == list: |
| + cmd = [_FASTBOOT_CMD, '-s', self._device_serial] + cmd |
| + else: |
| + raise TypeError( |
| + 'Command for _RunFastbootCommand must be a list.') |
| + status, output = cmd_helper.GetCmdStatusAndOutput(cmd) |
| + if int(status) != 0: |
| + raise device_errors.FastbootCommandFailedError( |
| + cmd, output, status, self._device_serial) |
| + return output |
| + |
| + def Flash(self, partition, image): |
| + """Flash partition with img. |
| + |
| + Args: |
| + partition: Partition to be flashed. |
| + image: location of image to flash with. |
| + """ |
| + self._RunFastbootCommand(['flash', partition, image]) |
| + |
| + def Devices(self): |
| + """Outputs list of devices in fastboot mode.""" |
| + output = self._RunFastbootCommand(['devices']) |
| + return [line.split()[0] for line in output.splitlines()] |
| + |
| + def RebootBootloader(self): |
| + """Reboot from fastboot, into fastboot.""" |
| + self._RunFastbootCommand(['reboot-bootloader']) |
| + |
| + def Reboot(self): |
| + """Reboot from fastboot to normal usage""" |
| + self._RunFastbootCommand(['reboot']) |
| + |
| + def SetOemOffModeCharge(self, value): |
| + """Sets off mode charging |
| + |
| + Args: |
| + value: boolean value to set off-mode-charging on or off. |
| + """ |
| + self._RunFastbootCommand( |
| + ['oem', 'off-mode-charge', str(int(value))]) |