OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 import logging | 5 import logging |
6 import os | 6 import os |
7 import re | 7 import re |
8 import subprocess | 8 import subprocess |
9 import sys | 9 import sys |
10 import time | 10 import time |
11 | 11 |
12 from telemetry.core import exceptions | 12 from telemetry.core import exceptions |
13 from telemetry.core import forwarders | 13 from telemetry.core import forwarders |
14 from telemetry.core import util | 14 from telemetry.core import util |
15 from telemetry.core.backends import adb_commands | 15 from telemetry.core.backends import adb_commands |
16 from telemetry.core.backends import browser_backend | 16 from telemetry.core.backends import browser_backend |
17 from telemetry.core.backends.chrome import chrome_browser_backend | 17 from telemetry.core.backends.chrome import chrome_browser_backend |
18 from telemetry.core.forwarders import android_forwarder | 18 from telemetry.core.forwarders import android_forwarder |
19 | 19 |
| 20 util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'build', 'android') |
| 21 from pylib.device import device_errors |
20 from pylib.device import intent | 22 from pylib.device import intent |
21 | 23 |
22 | 24 |
23 class AndroidBrowserBackendSettings(object): | 25 class AndroidBrowserBackendSettings(object): |
24 | 26 |
25 def __init__(self, adb, activity, cmdline_file, package, pseudo_exec_name, | 27 def __init__(self, adb, activity, cmdline_file, package, pseudo_exec_name, |
26 supports_tab_control): | 28 supports_tab_control): |
27 self.adb = adb | 29 self.adb = adb |
28 self.activity = activity | 30 self.activity = activity |
29 self.cmdline_file = cmdline_file | 31 self.cmdline_file = cmdline_file |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 cmdline_file=ChromeBackendSettings._GetCommandLineFile(adb), | 71 cmdline_file=ChromeBackendSettings._GetCommandLineFile(adb), |
70 package=package, | 72 package=package, |
71 pseudo_exec_name='chrome', | 73 pseudo_exec_name='chrome', |
72 supports_tab_control=True) | 74 supports_tab_control=True) |
73 | 75 |
74 def GetDevtoolsRemotePort(self): | 76 def GetDevtoolsRemotePort(self): |
75 return 'localabstract:chrome_devtools_remote' | 77 return 'localabstract:chrome_devtools_remote' |
76 | 78 |
77 def PushProfile(self, new_profile_dir): | 79 def PushProfile(self, new_profile_dir): |
78 # Pushing the profile is slow, so we don't want to do it every time. | 80 # Pushing the profile is slow, so we don't want to do it every time. |
79 # Avoid this by pushing to a safe location using PushIfNeeded, and | 81 # Avoid this by pushing to a safe location using PushChangedFiles, and |
80 # then copying into the correct location on each test run. | 82 # then copying into the correct location on each test run. |
81 | 83 |
82 (profile_parent, profile_base) = os.path.split(new_profile_dir) | 84 (profile_parent, profile_base) = os.path.split(new_profile_dir) |
83 # If the path ends with a '/' python split will return an empty string for | 85 # If the path ends with a '/' python split will return an empty string for |
84 # the base name; so we now need to get the base name from the directory. | 86 # the base name; so we now need to get the base name from the directory. |
85 if not profile_base: | 87 if not profile_base: |
86 profile_base = os.path.basename(profile_parent) | 88 profile_base = os.path.basename(profile_parent) |
87 | 89 |
88 saved_profile_location = '/sdcard/profile/%s' % profile_base | 90 saved_profile_location = '/sdcard/profile/%s' % profile_base |
89 self.adb.device().old_interface.PushIfNeeded( | 91 self.adb.device().PushChangedFiles(new_profile_dir, saved_profile_location) |
90 new_profile_dir, saved_profile_location) | |
91 | 92 |
92 self.adb.device().old_interface.EfficientDeviceDirectoryCopy( | 93 self.adb.device().old_interface.EfficientDeviceDirectoryCopy( |
93 saved_profile_location, self.profile_dir) | 94 saved_profile_location, self.profile_dir) |
94 dumpsys = self.adb.device().RunShellCommand( | 95 dumpsys = self.adb.device().RunShellCommand( |
95 'dumpsys package %s' % self.package) | 96 'dumpsys package %s' % self.package) |
96 id_line = next(line for line in dumpsys if 'userId=' in line) | 97 id_line = next(line for line in dumpsys if 'userId=' in line) |
97 uid = re.search('\d+', id_line).group() | 98 uid = re.search('\d+', id_line).group() |
98 files = self.adb.device().RunShellCommand( | 99 files = self.adb.device().RunShellCommand( |
99 'ls "%s"' % self.profile_dir, as_root=True) | 100 'ls "%s"' % self.profile_dir, as_root=True) |
100 files.remove('lib') | 101 files.remove('lib') |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 def IsProtectedFile(name): | 239 def IsProtectedFile(name): |
239 if self._adb.device().old_interface.FileExistsOnDevice(name): | 240 if self._adb.device().old_interface.FileExistsOnDevice(name): |
240 return not self._adb.device().old_interface.IsFileWritableOnDevice(name) | 241 return not self._adb.device().old_interface.IsFileWritableOnDevice(name) |
241 else: | 242 else: |
242 parent_name = os.path.dirname(name) | 243 parent_name = os.path.dirname(name) |
243 if parent_name != '': | 244 if parent_name != '': |
244 return IsProtectedFile(parent_name) | 245 return IsProtectedFile(parent_name) |
245 else: | 246 else: |
246 return True | 247 return True |
247 | 248 |
248 if IsProtectedFile(self._backend_settings.cmdline_file): | 249 protected = IsProtectedFile(self._backend_settings.cmdline_file) |
249 if not self._adb.device().old_interface.CanAccessProtectedFileContents(): | 250 try: |
250 logging.critical('Cannot set Chrome command line. ' | |
251 'Fix this by flashing to a userdebug build.') | |
252 sys.exit(1) | |
253 self._saved_cmdline = ''.join( | 251 self._saved_cmdline = ''.join( |
254 self._adb.device().old_interface.GetProtectedFileContents( | 252 self._adb.device().ReadFile( |
255 self._backend_settings.cmdline_file) | 253 self._backend_settings.cmdline_file, as_root=protected) |
256 or []) | 254 or []) |
257 self._adb.device().old_interface.SetProtectedFileContents( | 255 self._adb.device().WriteFile( |
258 self._backend_settings.cmdline_file, file_contents) | 256 self._backend_settings.cmdline_file, file_contents, |
259 else: | 257 as_root=protected) |
260 self._saved_cmdline = ''.join( | 258 except device_errors.CommandFailedError: |
261 self._adb.device().old_interface.GetFileContents( | 259 logging.critical('Cannot set Chrome command line. ' |
262 self._backend_settings.cmdline_file) | 260 'Fix this by flashing to a userdebug build.') |
263 or []) | 261 sys.exit(1) |
264 self._adb.device().old_interface.SetFileContents( | |
265 self._backend_settings.cmdline_file, file_contents) | |
266 | 262 |
267 def Start(self): | 263 def Start(self): |
268 self._SetUpCommandLine() | 264 self._SetUpCommandLine() |
269 self._adb.device().RunShellCommand('logcat -c') | 265 self._adb.device().RunShellCommand('logcat -c') |
270 if self.browser_options.startup_url: | 266 if self.browser_options.startup_url: |
271 url = self.browser_options.startup_url | 267 url = self.browser_options.startup_url |
272 elif self.browser_options.profile_dir: | 268 elif self.browser_options.profile_dir: |
273 url = None | 269 url = None |
274 else: | 270 else: |
275 # If we have no existing tabs start with a blank page since default | 271 # If we have no existing tabs start with a blank page since default |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 subprocess.Popen([tombstones, '-w', '--device', | 408 subprocess.Popen([tombstones, '-w', '--device', |
413 self._adb.device_serial()], | 409 self._adb.device_serial()], |
414 stdout=subprocess.PIPE).communicate()[0]) | 410 stdout=subprocess.PIPE).communicate()[0]) |
415 return ret | 411 return ret |
416 | 412 |
417 def AddReplayServerOptions(self, extra_wpr_args): | 413 def AddReplayServerOptions(self, extra_wpr_args): |
418 if not self.forwarder_factory.does_forwarder_override_dns: | 414 if not self.forwarder_factory.does_forwarder_override_dns: |
419 extra_wpr_args.append('--no-dns_forwarding') | 415 extra_wpr_args.append('--no-dns_forwarding') |
420 if self.browser_options.netsim: | 416 if self.browser_options.netsim: |
421 extra_wpr_args.append('--net=%s' % self.browser_options.netsim) | 417 extra_wpr_args.append('--net=%s' % self.browser_options.netsim) |
OLD | NEW |