[Android] Move screenshot implementation back into AndroidCommands.
BUG=267773 Review URL: https://codereview.chromium.org/234803006 git-svn-id: http://src.chromium.org/svn/trunk/src/build@264674 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
This commit is contained in:
Родитель
656099bedb
Коммит
e500a98327
|
@ -24,10 +24,8 @@ import time
|
|||
|
||||
import cmd_helper
|
||||
import constants
|
||||
import screenshot
|
||||
import system_properties
|
||||
from utils import host_utils
|
||||
from device import device_utils
|
||||
|
||||
try:
|
||||
from pylib import pexpect
|
||||
|
@ -1712,7 +1710,17 @@ class AndroidCommands(object):
|
|||
|
||||
return False
|
||||
|
||||
def TakeScreenshot(self, host_file):
|
||||
@staticmethod
|
||||
def GetTimestamp():
|
||||
return time.strftime('%Y-%m-%d-%H%M%S', time.localtime())
|
||||
|
||||
@staticmethod
|
||||
def EnsureHostDirectory(host_file):
|
||||
host_dir = os.path.dirname(os.path.abspath(host_file))
|
||||
if not os.path.exists(host_dir):
|
||||
os.makedirs(host_dir)
|
||||
|
||||
def TakeScreenshot(self, host_file=None):
|
||||
"""Saves a screenshot image to |host_file| on the host.
|
||||
|
||||
Args:
|
||||
|
@ -1722,7 +1730,15 @@ class AndroidCommands(object):
|
|||
Returns:
|
||||
Resulting host file name of the screenshot.
|
||||
"""
|
||||
return screenshot.TakeScreenshot(device_utils.DeviceUtils(self), host_file)
|
||||
host_file = os.path.abspath(host_file or
|
||||
'screenshot-%s.png' % self.GetTimestamp())
|
||||
self.EnsureHostDirectory(host_file)
|
||||
device_file = '%s/screenshot.png' % self.GetExternalStorage()
|
||||
self.RunShellCommand(
|
||||
'/system/bin/screencap -p %s' % device_file)
|
||||
self.PullFileFromDevice(device_file, host_file)
|
||||
self.RunShellCommand('rm -f "%s"' % device_file)
|
||||
return host_file
|
||||
|
||||
def PullFileFromDevice(self, device_file, host_file):
|
||||
"""Download |device_file| on the device from to |host_file| on the host.
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
import os
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
from pylib import cmd_helper
|
||||
|
||||
|
@ -13,34 +12,6 @@ import pylib.android_commands
|
|||
import pylib.device.device_utils
|
||||
|
||||
|
||||
def _GetTimestamp():
|
||||
return time.strftime('%Y-%m-%d-%H%M%S', time.localtime())
|
||||
|
||||
|
||||
def _EnsureHostDirectory(host_file):
|
||||
host_dir = os.path.dirname(os.path.abspath(host_file))
|
||||
if not os.path.exists(host_dir):
|
||||
os.makedirs(host_dir)
|
||||
|
||||
|
||||
def TakeScreenshot(device, host_file):
|
||||
"""Saves a screenshot image to |host_file| on the host.
|
||||
|
||||
Args:
|
||||
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' % 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
|
||||
|
||||
|
||||
class VideoRecorder(object):
|
||||
"""Records a screen capture video from an Android Device (KitKat or newer).
|
||||
|
||||
|
@ -61,7 +32,8 @@ class VideoRecorder(object):
|
|||
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 = host_file or ('screen-recording-%s.mp4' %
|
||||
device.old_interface.GetTimestamp())
|
||||
self._host_file = os.path.abspath(self._host_file)
|
||||
self._recorder = None
|
||||
self._recorder_pids = None
|
||||
|
@ -81,7 +53,7 @@ class VideoRecorder(object):
|
|||
|
||||
def Start(self):
|
||||
"""Start recording video."""
|
||||
_EnsureHostDirectory(self._host_file)
|
||||
self._device.old_interface.EnsureHostDirectory(self._host_file)
|
||||
self._recorder_stdout = tempfile.mkstemp()[1]
|
||||
self._recorder = cmd_helper.Popen(
|
||||
self._args, stdout=open(self._recorder_stdout, 'w'))
|
||||
|
|
Загрузка…
Ссылка в новой задаче