1# Copyright 2013 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5# devil may not be available if we're not in an Android checkout. 6try: 7 from devil.android.tools import video_recorder 8except ImportError: 9 video_recorder = None 10 11from telemetry.internal.platform import profiler 12from telemetry.internal.backends.chrome import android_browser_finder 13 14 15_VIDEO_MEGABITS_PER_SECOND = 4 16 17 18class AndroidScreenRecordingProfiler(profiler.Profiler): 19 """Captures a screen recording on Android.""" 20 21 def __init__(self, browser_backend, platform_backend, output_path, state): 22 super(AndroidScreenRecordingProfiler, self).__init__( 23 browser_backend, platform_backend, output_path, state) 24 self._output_path = output_path + '.mp4' 25 self._recorder = video_recorder.VideoRecorder( 26 browser_backend.device, 27 megabits_per_second=_VIDEO_MEGABITS_PER_SECOND) 28 self._recorder.Start() 29 30 @classmethod 31 def name(cls): 32 return 'android-screen-recorder' 33 34 @classmethod 35 def is_supported(cls, browser_type): 36 if browser_type == 'any': 37 return android_browser_finder.CanFindAvailableBrowsers() 38 return browser_type.startswith('android') 39 40 def CollectProfile(self): 41 self._recorder.Stop() 42 self._recorder.Pull(self._output_path) 43 44 print 'Screen recording saved as %s' % self._output_path 45 print 'To view, open in Chrome or a video player' 46 return [self._output_path] 47