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..1b89a393231cca66f58df21aced7ec090ea8bbdc 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): |
@@ -308,21 +310,58 @@ class AndroidCommands(object): |
logging.info('>>> $' + uninstall_command) |
return self._adb.SendCommand(uninstall_command, timeout_time=60) |
- def Install(self, package_file_path): |
+ def Install(self, package_file_path, reinstall=False): |
"""Installs the specified package to the device. |
Args: |
package_file_path: Path to .apk file to install. |
+ reinstall: Whether to reinstall over existing package |
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/10 11:47:07
nit: remove cmd_logger? also, spaces: 2 * 60
Isaac (away)
2012/08/17 04:41:49
removed cmd_logger.
as far as spacing, would rath
|
+ retry_count=0) |
+ |
+ 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. |
+ |
+ 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) |
+ 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) |
+ if 'Success' in install_status: |
+ return install_status |
+ except errors.WaitForResponseTimedOutError: |
+ logging.info('Timout on installing %s' % apk_path) |
+ |
+ if reboots_left <= 0: |
+ raise Exception('Install failure') |
- logging.info('>>> $' + install_command) |
- return self._adb.SendCommand(install_command, timeout_time=2*60) |
+ # Force a hard reboot on last attempt |
+ self.Reboot(full_reboot=(reboots_left == 1)) |
+ reboots_left -= 1 |
def MakeSystemFolderWritable(self): |
"""Remounts the /system folder rw. """ |
@@ -417,8 +456,10 @@ class AndroidCommands(object): |
""" |
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).splitlines() |
+ if ['error: device not found'] == result: |
+ raise errors.DeviceUnresponsiveError('device not found') |
if log_result: |
logging.info('\n>>> '.join(result)) |
return result |
@@ -480,7 +521,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. |