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

Unified Diff: build/android/pylib/android_commands.py

Issue 10824227: Organize adb install cmds and reboot on failure (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months 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
« no previous file with comments | « build/android/adb_install_content_shell ('k') | build/android/pylib/test_package_apk.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
« no previous file with comments | « build/android/adb_install_content_shell ('k') | build/android/pylib/test_package_apk.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698