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 1739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1750 output = self._adb.SendShellCommand(cmd, timeout_time=timeout) | 1750 output = self._adb.SendShellCommand(cmd, timeout_time=timeout) |
1751 # uiautomator doesn't fully conform to the instrumenation test runner | 1751 # uiautomator doesn't fully conform to the instrumenation test runner |
1752 # convention and doesn't terminate with INSTRUMENTATION_CODE. | 1752 # convention and doesn't terminate with INSTRUMENTATION_CODE. |
1753 # Just assume the first result is valid. | 1753 # Just assume the first result is valid. |
1754 (test_results, _) = am_instrument_parser.ParseAmInstrumentOutput(output) | 1754 (test_results, _) = am_instrument_parser.ParseAmInstrumentOutput(output) |
1755 if not test_results: | 1755 if not test_results: |
1756 raise errors.InstrumentationError( | 1756 raise errors.InstrumentationError( |
1757 'no test results... device setup correctly?') | 1757 'no test results... device setup correctly?') |
1758 return test_results[0] | 1758 return test_results[0] |
1759 | 1759 |
| 1760 def DismissCrashDialogIfNeeded(self): |
| 1761 """Dismiss the error/ANR dialog if present. |
| 1762 |
| 1763 Returns: Name of the crashed package if a dialog is focused, |
| 1764 None otherwise. |
| 1765 """ |
| 1766 re_focus = re.compile( |
| 1767 r'\s*mCurrentFocus.*Application (Error|Not Responding): (\S+)}') |
| 1768 |
| 1769 def _FindFocusedWindow(): |
| 1770 match = None |
| 1771 for line in self.RunShellCommand('dumpsys window windows'): |
| 1772 match = re.match(re_focus, line) |
| 1773 if match: |
| 1774 break |
| 1775 return match |
| 1776 |
| 1777 match = _FindFocusedWindow() |
| 1778 if not match: |
| 1779 return |
| 1780 package = match.group(2) |
| 1781 logging.warning('Trying to dismiss %s dialog for %s' % match.groups()) |
| 1782 self.SendKeyEvent(KEYCODE_DPAD_RIGHT) |
| 1783 self.SendKeyEvent(KEYCODE_DPAD_RIGHT) |
| 1784 self.SendKeyEvent(KEYCODE_ENTER) |
| 1785 match = _FindFocusedWindow() |
| 1786 if match: |
| 1787 logging.error('Still showing a %s dialog for %s' % match.groups()) |
| 1788 return package |
| 1789 |
1760 | 1790 |
1761 class NewLineNormalizer(object): | 1791 class NewLineNormalizer(object): |
1762 """A file-like object to normalize EOLs to '\n'. | 1792 """A file-like object to normalize EOLs to '\n'. |
1763 | 1793 |
1764 Pexpect runs adb within a pseudo-tty device (see | 1794 Pexpect runs adb within a pseudo-tty device (see |
1765 http://www.noah.org/wiki/pexpect), so any '\n' printed by adb is written | 1795 http://www.noah.org/wiki/pexpect), so any '\n' printed by adb is written |
1766 as '\r\n' to the logfile. Since adb already uses '\r\n' to terminate | 1796 as '\r\n' to the logfile. Since adb already uses '\r\n' to terminate |
1767 lines, the log ends up having '\r\r\n' at the end of each line. This | 1797 lines, the log ends up having '\r\r\n' at the end of each line. This |
1768 filter replaces the above with a single '\n' in the data stream. | 1798 filter replaces the above with a single '\n' in the data stream. |
1769 """ | 1799 """ |
1770 def __init__(self, output): | 1800 def __init__(self, output): |
1771 self._output = output | 1801 self._output = output |
1772 | 1802 |
1773 def write(self, data): | 1803 def write(self, data): |
1774 data = data.replace('\r\r\n', '\n') | 1804 data = data.replace('\r\r\n', '\n') |
1775 self._output.write(data) | 1805 self._output.write(data) |
1776 | 1806 |
1777 def flush(self): | 1807 def flush(self): |
1778 self._output.flush() | 1808 self._output.flush() |
OLD | NEW |