Index: build/android/pylib/device/device_utils.py |
diff --git a/build/android/pylib/device/device_utils.py b/build/android/pylib/device/device_utils.py |
index 4adde1d47b273da180277eb0fcb8906c94e92fb6..a6b705f4c1d92e2e107a93152ba9919eccdb24fe 100644 |
--- a/build/android/pylib/device/device_utils.py |
+++ b/build/android/pylib/device/device_utils.py |
@@ -15,6 +15,7 @@ import pylib.android_commands |
from pylib.device import adb_wrapper |
from pylib.device import decorators |
from pylib.device import device_errors |
+from pylib.utils import apk_helper |
from pylib.utils import parallelizer |
_DEFAULT_TIMEOUT = 30 |
@@ -154,6 +155,48 @@ class DeviceUtils(object): |
self.old_interface.RunShellCommand('dumpsys wifi')): |
time.sleep(0.1) |
+ @decorators.WithTimeoutAndRetriesFromInstance() |
+ def Reboot(self, block=True, timeout=None, retries=None): |
+ """ Reboot the device. |
frankf
2014/05/24 00:22:39
no space after quotation mark. Also you didn't fix
jbudorick
2014/05/27 20:58:35
Done wrt no space. There's only one one liner docs
frankf
2014/05/27 21:12:10
Multi-line:
"""Line One.
Line2.
"""
Single line
jbudorick
2014/05/27 21:44:14
Right, my point was that all of the docstrings in
|
+ |
+ Args: |
+ block: A boolean indicating if we should wait for the reboot to complete. |
+ timeout: Same as for |IsOnline|. |
+ retries: Same as for |IsOnline|. |
+ """ |
+ self.old_interface.Reboot() |
+ if block: |
+ self.WaitUntilFullyBooted() |
+ |
+ @decorators.WithTimeoutAndRetriesDefaults( |
+ 4 * _DEFAULT_TIMEOUT, |
+ _DEFAULT_RETRIES) |
+ def Install(self, apk_path, timeout=None, retries=None): |
+ """ Install an APK. Noop if an identical APK is already installed. |
+ |
+ Args: |
+ apk_path: A string containing the path to the APK to install. |
+ timeout: Same as for |IsOnline|. |
+ retries: Same as for |IsOnline|. |
+ Raises: |
+ CommandFailedError if the installation fails. |
+ CommandTimeoutError if the installation times out. |
+ """ |
+ package_name = apk_helper.GetPackageName(apk_path) |
+ device_path = self.old_interface.GetApplicationPath(package_name) |
+ if not device_path or len(self.old_interface.GetFilesChanged( |
+ apk_path, device_path, ignore_filenames=True) > 0): |
frankf
2014/05/24 00:22:39
I'd create a variable to hold len(...) to make thi
jbudorick
2014/05/27 20:58:35
Done.
|
+ try: |
+ if device_path: |
+ self.old_interface.Uninstall(package_name) |
+ out = self.old_interface.Install(apk_path, reinstall=bool(device_path)) |
+ for line in out.split('\n'): |
+ if 'Failure' in line: |
+ raise device_errors.CommandFailedError( |
+ ['adb' ,'install', apk_path], line.strip()) |
+ except AssertionError as e: |
+ raise device_errors.CommandFailedError(str(e)) |
+ |
def __str__(self): |
"""Returns the device serial.""" |
return self.old_interface.GetDevice() |