Index: build/android/pylib/screenshot.py |
diff --git a/build/android/pylib/screenshot.py b/build/android/pylib/screenshot.py |
index 7fac54a27d7e690b97ae06516a593e7ed913d7f2..228af88f2cb4e73b0ffc3a4e861627b6daf6d29e 100644 |
--- a/build/android/pylib/screenshot.py |
+++ b/build/android/pylib/screenshot.py |
@@ -8,6 +8,10 @@ import time |
from pylib import cmd_helper |
+# TODO(jbudorick) Remove once telemetry gets switched over. |
+import pylib.android_commands |
+import pylib.device.device_utils |
+ |
def _GetTimestamp(): |
return time.strftime('%Y-%m-%d-%H%M%S', time.localtime()) |
@@ -19,20 +23,21 @@ def _EnsureHostDirectory(host_file): |
os.makedirs(host_dir) |
-def TakeScreenshot(adb, host_file): |
+def TakeScreenshot(device, host_file): |
"""Saves a screenshot image to |host_file| on the host. |
Args: |
- adb: AndroidCommands instance. |
+ device: DeviceUtils instance. |
host_file: Path to the image file to store on the host. |
""" |
host_file = os.path.abspath(host_file or |
'screenshot-%s.png' % _GetTimestamp()) |
_EnsureHostDirectory(host_file) |
- device_file = '%s/screenshot.png' % adb.GetExternalStorage() |
- adb.RunShellCommand('/system/bin/screencap -p %s' % device_file) |
- adb.PullFileFromDevice(device_file, host_file) |
- adb.RunShellCommand('rm -f "%s"' % device_file) |
+ device_file = '%s/screenshot.png' % device.old_interface.GetExternalStorage() |
+ device.old_interface.RunShellCommand( |
+ '/system/bin/screencap -p %s' % device_file) |
+ device.old_interface.PullFileFromDevice(device_file, host_file) |
+ device.old_interface.RunShellCommand('rm -f "%s"' % device_file) |
return host_file |
@@ -40,7 +45,7 @@ class VideoRecorder(object): |
"""Records a screen capture video from an Android Device (KitKat or newer). |
Args: |
- adb: AndroidCommands instance. |
+ device: DeviceUtils instance. |
host_file: Path to the video file to store on the host. |
megabits_per_second: Video bitrate in megabits per second. Allowed range |
from 0.1 to 100 mbps. |
@@ -48,10 +53,14 @@ class VideoRecorder(object): |
default. |
rotate: If True, the video will be rotated 90 degrees. |
""" |
- def __init__(self, adb, host_file, megabits_per_second=4, size=None, |
+ def __init__(self, device, host_file, megabits_per_second=4, size=None, |
rotate=False): |
- self._adb = adb |
- self._device_file = '%s/screen-recording.mp4' % adb.GetExternalStorage() |
+ # TODO(jbudorick) Remove once telemetry gets switched over. |
+ if isinstance(device, pylib.android_commands.AndroidCommands): |
+ device = pylib.device.device_utils.DeviceUtils(device) |
+ self._device = device |
+ self._device_file = ( |
+ '%s/screen-recording.mp4' % device.old_interface.GetExternalStorage()) |
self._host_file = host_file or 'screen-recording-%s.mp4' % _GetTimestamp() |
self._host_file = os.path.abspath(self._host_file) |
self._recorder = None |
@@ -60,8 +69,8 @@ class VideoRecorder(object): |
self._is_started = False |
self._args = ['adb'] |
- if self._adb.GetDevice(): |
- self._args += ['-s', self._adb.GetDevice()] |
+ if self._device.old_interface.GetDevice(): |
+ self._args += ['-s', self._device.old_interface.GetDevice()] |
self._args += ['shell', 'screenrecord', '--verbose'] |
self._args += ['--bit-rate', str(megabits_per_second * 1000 * 1000)] |
if size: |
@@ -76,7 +85,7 @@ class VideoRecorder(object): |
self._recorder_stdout = tempfile.mkstemp()[1] |
self._recorder = cmd_helper.Popen( |
self._args, stdout=open(self._recorder_stdout, 'w')) |
- self._recorder_pids = self._adb.ExtractPid('screenrecord') |
+ self._recorder_pids = self._device.old_interface.ExtractPid('screenrecord') |
if not self._recorder_pids: |
raise RuntimeError('Recording failed. Is your device running Android ' |
'KitKat or later?') |
@@ -95,7 +104,8 @@ class VideoRecorder(object): |
self._is_started = False |
if not self._recorder or not self._recorder_pids: |
return |
- self._adb.RunShellCommand('kill -SIGINT ' + ' '.join(self._recorder_pids)) |
+ self._device.old_interface.RunShellCommand( |
+ 'kill -SIGINT ' + ' '.join(self._recorder_pids)) |
self._recorder.wait() |
def Pull(self): |
@@ -104,6 +114,7 @@ class VideoRecorder(object): |
Returns: |
Output video file name on the host. |
""" |
- self._adb.PullFileFromDevice(self._device_file, self._host_file) |
- self._adb.RunShellCommand('rm -f "%s"' % self._device_file) |
+ self._device.old_interface.PullFileFromDevice( |
+ self._device_file, self._host_file) |
+ self._device.old_interface.RunShellCommand('rm -f "%s"' % self._device_file) |
return self._host_file |