Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Unified Diff: build/android/devil/android/sdk/fastboot.py

Issue 1417373002: [Android] Add functionality to flash devices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..cfc566a67c292f8ee2e9f4d0d2df5bdf774acea8
--- /dev/null
+++ b/build/android/devil/android/sdk/fastboot.py
@@ -0,0 +1,98 @@
+# 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).
+"""
+# pylint: disable=unused-argument
+
+import os
+
+from devil.android import decorators
+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')
+_DEFAULT_TIMEOUT = 30
+_DEFAULT_RETRIES = 3
+_FLASH_TIMEOUT = _DEFAULT_TIMEOUT * 10
+
+class Fastboot(object):
+
+ def __init__(self, device_serial, default_timeout=_DEFAULT_TIMEOUT,
+ default_retries=_DEFAULT_RETRIES):
+ """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)
+ self._default_timeout = default_timeout
+ self._default_retries = default_retries
+
+ @decorators.WithTimeoutAndRetriesFromInstance()
+ def _RunFastbootCommand(self, cmd, timeout=None, retries=None):
+ """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
+
+ @decorators.WithTimeoutAndRetriesDefaults(_FLASH_TIMEOUT, 0)
+ def Flash(self, partition, image, timeout=None, retries=None):
+ """Flash partition with img.
+
+ Args:
+ partition: Partition to be flashed.
+ image: location of image to flash with.
+ """
+ self._RunFastbootCommand(['flash', partition, image])
+
+ @decorators.WithTimeoutAndRetriesFromInstance()
+ def Devices(self, timeout=None, retries=None):
+ """Outputs list of devices in fastboot mode."""
+ output = self._RunFastbootCommand(['devices'])
+ return [line.split()[0] for line in output.splitlines()]
+
+ @decorators.WithTimeoutAndRetriesFromInstance()
+ def RebootBootloader(self, timeout=None, retries=None):
+ """Reboot from fastboot, into fastboot."""
+ self._RunFastbootCommand(['reboot-bootloader'])
+
+ @decorators.WithTimeoutAndRetriesDefaults(_FLASH_TIMEOUT, 0)
+ def Reboot(self, timeout=None, retries=None):
+ """Reboot from fastboot to normal usage"""
+ self._RunFastbootCommand(['reboot'])
+
+ @decorators.WithTimeoutAndRetriesFromInstance()
+ def SetOemOffModeCharge(self, value, timeout=None, retries=None):
+ """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))])

Powered by Google App Engine
This is Rietveld 408576698