Index: build/android/pylib/android_commands.py |
diff --git a/build/android/pylib/android_commands.py b/build/android/pylib/android_commands.py |
index da87f39f4dae86130a6507681404fa322fc808f0..3b38ab4e29a218e21ac14b0f174ef1d4a9149005 100644 |
--- a/build/android/pylib/android_commands.py |
+++ b/build/android/pylib/android_commands.py |
@@ -286,12 +286,14 @@ class AndroidCommands(object): |
if os.environ.get('USING_HIVE'): |
logging.warning('Ignoring reboot request as we are on hive') |
return |
- if full_reboot: |
+ if full_reboot or not self.IsRootEnabled(): |
self._adb.SendCommand('reboot') |
+ timeout = 300 |
else: |
self.RestartShell() |
+ timeout = 120 |
self.WaitForDevicePm() |
- self.StartMonitoringLogcat(timeout=120) |
+ self.StartMonitoringLogcat(timeout=timeout) |
self.WaitForLogMatch(BOOT_COMPLETE_RE, None) |
def Uninstall(self, package): |
@@ -305,24 +307,58 @@ class AndroidCommands(object): |
""" |
uninstall_command = 'uninstall %s' % package |
- logging.info('>>> $' + uninstall_command) |
- return self._adb.SendCommand(uninstall_command, timeout_time=60) |
+ return self._adb.SendCommand(uninstall_command, timeout_time=60, |
+ cmd_logger=logging) |
- def Install(self, package_file_path): |
+ def Install(self, package_file_path, reinstall=False, retry_count=3): |
"""Installs the specified package to the device. |
Args: |
package_file_path: Path to .apk file to install. |
+ reinstall: Whether to reinstall over existing package |
bulach
2012/08/09 12:36:52
nit: remove retry_count from 313, since it's undoc
|
Returns: |
A status string returned by adb install |
""" |
assert os.path.isfile(package_file_path) |
- install_command = 'install %s' % package_file_path |
+ if reinstall: |
+ install_cmd = 'install -r %s' |
+ else: |
+ install_cmd = 'install %s' |
+ |
+ return self._adb.SendCommand(install_cmd % package_file_path, |
+ timeout_time=2*60, cmd_logger=logging, |
bulach
2012/08/09 12:36:52
nit: I think it needs space around *, timeout_time
Isaac (away)
2012/08/10 04:44:35
It's like this a couple other places in this file.
|
+ retry_count=3) |
+ |
+ def ManagedInstall(self, apk_path, keep_data, package_name=None, |
+ reboots_on_failure=2): |
+ """Installs the specified package to the device. Reboots the device on |
+ package manager timeouts. |
- logging.info('>>> $' + install_command) |
- return self._adb.SendCommand(install_command, timeout_time=2*60) |
+ Args: |
+ apk_path: Path to .apk file to install. |
+ keep_data: Whether to keep data if package already exists |
+ package_name: Package name (only needed if keep_data=False |
bulach
2012/08/09 12:36:52
nit: )
|
+ reboots_on_failure: number of time to reboot if package manager is frozen. |
+ |
+ Returns: |
+ A status string returned by adb install |
+ """ |
+ reboots_left = reboots_on_failure |
+ while True: |
+ try: |
+ if not keep_data: |
+ self.Uninstall(package_name) |
+ install_status = self.Install(apk_path, keep_data, retry_count=0) |
+ if 'Success' in install_status: |
+ return install_status |
+ except errors.WaitForResponseTimedOutError: |
+ if reboots_left < 0: |
bulach
2012/08/09 12:36:52
nit: seems that this should be <= 0, that is, pass
|
+ raise |
+ # Force a hard reboot on last attempt |
+ self.Reboot(full_reboot=(reboots_left==0)) |
bulach
2012/08/09 12:36:52
nit: space around ==
|
+ reboots_left -= 1 |
def MakeSystemFolderWritable(self): |
"""Remounts the /system folder rw. """ |
@@ -385,7 +421,6 @@ class AndroidCommands(object): |
logging.info('Waiting for SD card ready...') |
sdcard_ready = False |
attempts = 0 |
- wait_period = 5 |
while not sdcard_ready and attempts * wait_period < timeout_time: |
output = self.RunShellCommand('ls /sdcard/') |
if len(output) > 0: |
@@ -415,10 +450,9 @@ class AndroidCommands(object): |
Returns: |
list containing the lines of output received from running the command |
""" |
- logging.info('>>> $' + command) |
if "'" in command: logging.warning(command + " contains ' quotes") |
- result = self._adb.SendShellCommand("'%s'" % command, |
- timeout_time).splitlines() |
+ result = self._adb.SendShellCommand("'%s'" % command, timeout_time, |
+ cmd_logger=logging).splitlines() |
if log_result: |
logging.info('\n>>> '.join(result)) |
return result |
@@ -480,7 +514,6 @@ class AndroidCommands(object): |
cmd += ' --start-profiler ' + trace_file_name |
self.RunShellCommand(cmd) |
- |
def CloseApplication(self, package): |
"""Attempt to close down the application, using increasing violence. |
@@ -540,8 +573,8 @@ class AndroidCommands(object): |
# NOTE: We can't use adb_interface.Push() because it hardcodes a timeout of |
# 60 seconds which isn't sufficient for a lot of users of this method. |
push_command = 'push %s %s' % (local_path, device_path) |
- logging.info('>>> $' + push_command) |
- output = self._adb.SendCommand(push_command, timeout_time=30*60) |
+ output = self._adb.SendCommand(push_command, timeout_time=30*60, |
+ cmd_logger=logging) |
assert output |
# Success looks like this: "3035 KB/s (12512056 bytes in 4.025s)" |
# Errors look like this: "failed to copy ... " |