| 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 |
| 11 import datetime | 11 import datetime |
| 12 import logging | 12 import logging |
| 13 import os | 13 import os |
| 14 import re | 14 import re |
| 15 import shlex | 15 import shlex |
| 16 import signal | 16 import signal |
| 17 import subprocess | 17 import subprocess |
| 18 import sys | 18 import sys |
| 19 import tempfile | 19 import tempfile |
| 20 import time | 20 import time |
| 21 | 21 |
| 22 import cmd_helper | 22 import cmd_helper |
| 23 import constants | 23 import constants |
| 24 import screenshot |
| 24 try: | 25 try: |
| 25 from pylib import pexpect | 26 from pylib import pexpect |
| 26 except: | 27 except: |
| 27 pexpect = None | 28 pexpect = None |
| 28 | 29 |
| 29 sys.path.append(os.path.join( | 30 sys.path.append(os.path.join( |
| 30 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner')) | 31 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner')) |
| 31 import adb_interface | 32 import adb_interface |
| 32 import am_instrument_parser | 33 import am_instrument_parser |
| 33 import errors | 34 import errors |
| (...skipping 1537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1571 except ValueError: | 1572 except ValueError: |
| 1572 if IsDeviceAttached(self._device): | 1573 if IsDeviceAttached(self._device): |
| 1573 raise errors.DeviceUnresponsiveError('Device may be offline.') | 1574 raise errors.DeviceUnresponsiveError('Device may be offline.') |
| 1574 | 1575 |
| 1575 return False | 1576 return False |
| 1576 | 1577 |
| 1577 def TakeScreenshot(self, host_file): | 1578 def TakeScreenshot(self, host_file): |
| 1578 """Saves a screenshot image to |host_file| on the host. | 1579 """Saves a screenshot image to |host_file| on the host. |
| 1579 | 1580 |
| 1580 Args: | 1581 Args: |
| 1581 host_file: Absolute path to the image file to store on the host. | 1582 host_file: Absolute path to the image file to store on the host or None to |
| 1583 use an autogenerated file name. |
| 1584 |
| 1585 Returns: |
| 1586 Resulting host file name of the screenshot. |
| 1582 """ | 1587 """ |
| 1583 host_dir = os.path.dirname(host_file) | 1588 return screenshot.TakeScreenshot(self, host_file) |
| 1584 if not os.path.exists(host_dir): | |
| 1585 os.makedirs(host_dir) | |
| 1586 device_file = '%s/screenshot.png' % self.GetExternalStorage() | |
| 1587 self.RunShellCommand('/system/bin/screencap -p %s' % device_file) | |
| 1588 self.PullFileFromDevice(device_file, host_file) | |
| 1589 | 1589 |
| 1590 def PullFileFromDevice(self, device_file, host_file): | 1590 def PullFileFromDevice(self, device_file, host_file): |
| 1591 """Download |device_file| on the device from to |host_file| on the host. | 1591 """Download |device_file| on the device from to |host_file| on the host. |
| 1592 | 1592 |
| 1593 Args: | 1593 Args: |
| 1594 device_file: Absolute path to the file to retrieve from the device. | 1594 device_file: Absolute path to the file to retrieve from the device. |
| 1595 host_file: Absolute path to the file to store on the host. | 1595 host_file: Absolute path to the file to store on the host. |
| 1596 """ | 1596 """ |
| 1597 assert self._adb.Pull(device_file, host_file) | 1597 assert self._adb.Pull(device_file, host_file) |
| 1598 assert os.path.exists(host_file) | 1598 assert os.path.exists(host_file) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1662 """ | 1662 """ |
| 1663 def __init__(self, output): | 1663 def __init__(self, output): |
| 1664 self._output = output | 1664 self._output = output |
| 1665 | 1665 |
| 1666 def write(self, data): | 1666 def write(self, data): |
| 1667 data = data.replace('\r\r\n', '\n') | 1667 data = data.replace('\r\r\n', '\n') |
| 1668 self._output.write(data) | 1668 self._output.write(data) |
| 1669 | 1669 |
| 1670 def flush(self): | 1670 def flush(self): |
| 1671 self._output.flush() | 1671 self._output.flush() |
| OLD | NEW |