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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
401 | 401 |
402 install_cmd.append(package_file_path) | 402 install_cmd.append(package_file_path) |
403 install_cmd = ' '.join(install_cmd) | 403 install_cmd = ' '.join(install_cmd) |
404 | 404 |
405 self._LogShell(install_cmd) | 405 self._LogShell(install_cmd) |
406 return self._adb.SendCommand(install_cmd, | 406 return self._adb.SendCommand(install_cmd, |
407 timeout_time=2 * 60, | 407 timeout_time=2 * 60, |
408 retry_count=0) | 408 retry_count=0) |
409 | 409 |
410 def ManagedInstall(self, apk_path, keep_data=False, package_name=None, | 410 def ManagedInstall(self, apk_path, keep_data=False, package_name=None, |
411 reboots_on_failure=2): | 411 reboots_on_timeout=2): |
412 """Installs specified package and reboots device on timeouts. | 412 """Installs specified package and reboots device on timeouts. |
413 | 413 |
414 If package_name is supplied, checks if the package is already installed and | 414 If package_name is supplied, checks if the package is already installed and |
415 doesn't reinstall if the apk md5sums match. | 415 doesn't reinstall if the apk md5sums match. |
416 | 416 |
417 Args: | 417 Args: |
418 apk_path: Path to .apk file to install. | 418 apk_path: Path to .apk file to install. |
419 keep_data: Reinstalls instead of uninstalling first, preserving the | 419 keep_data: Reinstalls instead of uninstalling first, preserving the |
420 application data. | 420 application data. |
421 package_name: Package name (only needed if keep_data=False). | 421 package_name: Package name (only needed if keep_data=False). |
422 reboots_on_failure: number of time to reboot if package manager is frozen. | 422 reboots_on_timeout: number of time to reboot if package manager is frozen. |
423 """ | 423 """ |
424 # Check if package is already installed and up to date. | 424 # Check if package is already installed and up to date. |
425 if package_name: | 425 if package_name: |
426 installed_apk_path = self.GetApplicationPath(package_name) | 426 installed_apk_path = self.GetApplicationPath(package_name) |
427 if (installed_apk_path and | 427 if (installed_apk_path and |
428 not self.GetFilesChanged(apk_path, installed_apk_path)): | 428 not self.GetFilesChanged(apk_path, installed_apk_path)): |
429 logging.info('Skipped install: identical %s APK already installed' % | 429 logging.info('Skipped install: identical %s APK already installed' % |
430 package_name) | 430 package_name) |
431 return | 431 return |
432 # Install. | 432 # Install. |
433 reboots_left = reboots_on_failure | 433 reboots_left = reboots_on_timeout |
434 while True: | 434 while True: |
435 try: | 435 try: |
436 if not keep_data: | 436 if not keep_data: |
437 assert package_name | 437 assert package_name |
438 self.Uninstall(package_name) | 438 self.Uninstall(package_name) |
439 install_status = self.Install(apk_path, reinstall=keep_data) | 439 install_status = self.Install(apk_path, reinstall=keep_data) |
440 if 'Success' in install_status: | 440 if 'Success' in install_status: |
441 return | 441 return |
442 else: | |
443 raise Exception('Install failure: ' + install_status) | |
frankf
2013/09/10 22:29:11
nit: use string formatting
'Install failure: %s'
no sievers
2013/09/11 00:21:58
Done.
| |
442 except errors.WaitForResponseTimedOutError: | 444 except errors.WaitForResponseTimedOutError: |
443 print '@@@STEP_WARNINGS@@@' | 445 print '@@@STEP_WARNINGS@@@' |
444 logging.info('Timeout on installing %s on device %s', apk_path, | 446 logging.info('Timeout on installing %s on device %s', apk_path, |
445 self._device) | 447 self._device) |
446 | 448 |
447 if reboots_left <= 0: | 449 if reboots_left <= 0: |
448 raise Exception('Install failure') | 450 raise Exception('Install failure') |
frankf
2013/09/10 22:29:11
Let's make this more specific: 'Install timed out'
no sievers
2013/09/11 00:21:58
Done.
| |
449 | 451 |
450 # Force a hard reboot on last attempt | 452 # Force a hard reboot on last attempt |
451 self.Reboot(full_reboot=(reboots_left == 1)) | 453 self.Reboot(full_reboot=(reboots_left == 1)) |
452 reboots_left -= 1 | 454 reboots_left -= 1 |
453 | 455 |
454 def MakeSystemFolderWritable(self): | 456 def MakeSystemFolderWritable(self): |
455 """Remounts the /system folder rw.""" | 457 """Remounts the /system folder rw.""" |
456 out = self._adb.SendCommand('remount') | 458 out = self._adb.SendCommand('remount') |
457 if out.strip() != 'remount succeeded': | 459 if out.strip() != 'remount succeeded': |
458 raise errors.MsgException('Remount failed: %s' % out) | 460 raise errors.MsgException('Remount failed: %s' % out) |
459 | 461 |
460 def RestartAdbServer(self): | 462 def RestartAdbServer(self): |
461 """Restart the adb server.""" | 463 """Restart the adb server.""" |
462 ret = self.KillAdbServer() | 464 ret = self.KillAdbServer() |
(...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1546 """ | 1548 """ |
1547 def __init__(self, output): | 1549 def __init__(self, output): |
1548 self._output = output | 1550 self._output = output |
1549 | 1551 |
1550 def write(self, data): | 1552 def write(self, data): |
1551 data = data.replace('\r\r\n', '\n') | 1553 data = data.replace('\r\r\n', '\n') |
1552 self._output.write(data) | 1554 self._output.write(data) |
1553 | 1555 |
1554 def flush(self): | 1556 def flush(self): |
1555 self._output.flush() | 1557 self._output.flush() |
OLD | NEW |