Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Provides an interface to communicate with the device via the adb command. | 5 """Provides an interface to communicate with the device via the adb command. |
| 6 | 6 |
| 7 Assumes adb binary is currently on system path. | 7 Assumes adb binary is currently on system path. |
| 8 """ | 8 """ |
| 9 | 9 |
| 10 import collections | 10 import collections |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 | 392 |
| 393 self._LogShell(install_cmd) | 393 self._LogShell(install_cmd) |
| 394 return self._adb.SendCommand(install_cmd, | 394 return self._adb.SendCommand(install_cmd, |
| 395 timeout_time=2 * 60, | 395 timeout_time=2 * 60, |
| 396 retry_count=0) | 396 retry_count=0) |
| 397 | 397 |
| 398 def ManagedInstall(self, apk_path, keep_data=False, package_name=None, | 398 def ManagedInstall(self, apk_path, keep_data=False, package_name=None, |
| 399 reboots_on_failure=2): | 399 reboots_on_failure=2): |
| 400 """Installs specified package and reboots device on timeouts. | 400 """Installs specified package and reboots device on timeouts. |
| 401 | 401 |
| 402 If package_name is supplied, checks if the package is already installed and | |
| 403 doesn't reinstall if the apk md5sums match. | |
| 404 | |
| 402 Args: | 405 Args: |
| 403 apk_path: Path to .apk file to install. | 406 apk_path: Path to .apk file to install. |
| 404 keep_data: Reinstalls instead of uninstalling first, preserving the | 407 keep_data: Reinstalls instead of uninstalling first, preserving the |
| 405 application data. | 408 application data. |
| 406 package_name: Package name (only needed if keep_data=False). | 409 package_name: Package name (only needed if keep_data=False). |
| 407 reboots_on_failure: number of time to reboot if package manager is frozen. | 410 reboots_on_failure: number of time to reboot if package manager is frozen. |
| 408 | 411 |
| 409 Returns: | 412 Returns: |
| 410 A status string returned by adb install | 413 A status string returned by adb install |
| 411 """ | 414 """ |
| 415 # Check if package is already installed and up to date. | |
| 416 if package_name: | |
| 417 installed_apk_path = self.GetApplicationPath(package_name) | |
| 418 if installed_apk_path and self.CheckMd5Sum(apk_path, installed_apk_path): | |
| 419 logging.info('Skipped install: identical %s apk already installed' % | |
| 420 package_name) | |
| 421 return 'Success: identical %s apk already installed' % package_name | |
|
frankf
2013/07/20 02:18:35
Why do we return a string in this method?
craigdh
2013/07/22 19:03:14
Yeah, I thought that was odd too. Doesn't look lik
| |
| 422 # Install. | |
| 412 reboots_left = reboots_on_failure | 423 reboots_left = reboots_on_failure |
| 413 while True: | 424 while True: |
| 414 try: | 425 try: |
| 415 if not keep_data: | 426 if not keep_data: |
| 416 assert package_name | 427 assert package_name |
| 417 self.Uninstall(package_name) | 428 self.Uninstall(package_name) |
| 418 install_status = self.Install(apk_path, reinstall=keep_data) | 429 install_status = self.Install(apk_path, reinstall=keep_data) |
| 419 if 'Success' in install_status: | 430 if 'Success' in install_status: |
| 420 return install_status | 431 return install_status |
| 421 except errors.WaitForResponseTimedOutError: | 432 except errors.WaitForResponseTimedOutError: |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 717 self.RunShellCommand('pm clear ' + package) | 728 self.RunShellCommand('pm clear ' + package) |
| 718 | 729 |
| 719 def SendKeyEvent(self, keycode): | 730 def SendKeyEvent(self, keycode): |
| 720 """Sends keycode to the device. | 731 """Sends keycode to the device. |
| 721 | 732 |
| 722 Args: | 733 Args: |
| 723 keycode: Numeric keycode to send (see "enum" at top of file). | 734 keycode: Numeric keycode to send (see "enum" at top of file). |
| 724 """ | 735 """ |
| 725 self.RunShellCommand('input keyevent %d' % keycode) | 736 self.RunShellCommand('input keyevent %d' % keycode) |
| 726 | 737 |
| 727 def CheckMd5Sum(self, local_path, device_path, ignore_paths=False): | 738 def CheckMd5Sum(self, local_path, device_path): |
| 728 """Compares the md5sum of a local path against a device path. | 739 """Compares the md5sum of a local path against a device path. |
| 729 | 740 |
| 730 Args: | 741 Args: |
| 731 local_path: Path (file or directory) on the host. | 742 local_path: Path (file or directory) on the host. |
| 732 device_path: Path on the device. | 743 device_path: Path on the device. |
| 733 ignore_paths: If False, both the md5sum and the relative paths/names of | |
| 734 files must match. If True, only the md5sum must match. | |
| 735 | 744 |
| 736 Returns: | 745 Returns: |
| 737 True if the md5sums match. | 746 True if the md5sums match. |
| 738 """ | 747 """ |
| 739 if not self._md5sum_build_dir: | 748 if not self._md5sum_build_dir: |
| 740 default_build_type = os.environ.get('BUILD_TYPE', 'Debug') | 749 default_build_type = os.environ.get('BUILD_TYPE', 'Debug') |
| 741 build_dir = '%s/%s/' % ( | 750 build_dir = '%s/%s/' % ( |
| 742 cmd_helper.OutDirectory().get(), default_build_type) | 751 cmd_helper.OutDirectory().get(), default_build_type) |
| 743 md5sum_dist_path = '%s/md5sum_dist' % build_dir | 752 md5sum_dist_path = '%s/md5sum_dist' % build_dir |
| 744 if not os.path.exists(md5sum_dist_path): | 753 if not os.path.exists(md5sum_dist_path): |
| (...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1460 """ | 1469 """ |
| 1461 def __init__(self, output): | 1470 def __init__(self, output): |
| 1462 self._output = output | 1471 self._output = output |
| 1463 | 1472 |
| 1464 def write(self, data): | 1473 def write(self, data): |
| 1465 data = data.replace('\r\r\n', '\n') | 1474 data = data.replace('\r\r\n', '\n') |
| 1466 self._output.write(data) | 1475 self._output.write(data) |
| 1467 | 1476 |
| 1468 def flush(self): | 1477 def flush(self): |
| 1469 self._output.flush() | 1478 self._output.flush() |
| OLD | NEW |