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 pipes | 6 import pipes |
7 import sys | 7 import sys |
8 | 8 |
9 from telemetry.core import util | 9 from telemetry.core import util |
10 | 10 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 particular features or modify otherwise default functionality. To set the | 56 particular features or modify otherwise default functionality. To set the |
57 flags for Chrome on Android, specific files on the device must be updated | 57 flags for Chrome on Android, specific files on the device must be updated |
58 with the flags to enable. This class provides a wrapper around this | 58 with the flags to enable. This class provides a wrapper around this |
59 functionality. | 59 functionality. |
60 """ | 60 """ |
61 | 61 |
62 def __init__(self, adb, backend_settings, startup_args): | 62 def __init__(self, adb, backend_settings, startup_args): |
63 self._adb = adb | 63 self._adb = adb |
64 self._backend_settings = backend_settings | 64 self._backend_settings = backend_settings |
65 self._startup_args = startup_args | 65 self._startup_args = startup_args |
66 self._saved_command_line_file_contents = '' | 66 self._saved_command_line_file_contents = None |
67 | 67 |
68 @property | 68 @property |
69 def command_line_file(self): | 69 def command_line_file(self): |
70 return self._backend_settings.GetCommandLineFile(self._adb.IsUserBuild()) | 70 return self._backend_settings.GetCommandLineFile(self._adb.IsUserBuild()) |
71 | 71 |
72 def SetUpCommandLineFlags(self): | 72 def SetUpCommandLineFlags(self): |
73 args = [self._backend_settings.pseudo_exec_name] | 73 args = [self._backend_settings.pseudo_exec_name] |
74 args.extend(self._startup_args) | 74 args.extend(self._startup_args) |
75 content = ' '.join(_QuoteIfNeeded(arg) for arg in args) | 75 content = ' '.join(_QuoteIfNeeded(arg) for arg in args) |
76 | 76 |
77 try: | 77 try: |
78 # Save the current command line to restore later, except if it appears to | 78 # Save the current command line to restore later, except if it appears to |
79 # be a Telemetry created one. This is to prevent a common bug where | 79 # be a Telemetry created one. This is to prevent a common bug where |
80 # --host-resolver-rules borks people's browsers if something goes wrong | 80 # --host-resolver-rules borks people's browsers if something goes wrong |
81 # with Telemetry. | 81 # with Telemetry. |
82 self._saved_command_line_file_contents = ''.join(self._ReadFile()) | 82 self._saved_command_line_file_contents = self._ReadFile() |
83 if '--host-resolver-rules' in self._saved_command_line_file_contents: | 83 if '--host-resolver-rules' in self._saved_command_line_file_contents: |
84 self._saved_command_line_file_contents = '' | 84 self._saved_command_line_file_contents = None |
| 85 except device_errors.CommandFailedError: |
| 86 self._saved_command_line_file_contents = None |
| 87 |
| 88 try: |
85 self._WriteFile(content) | 89 self._WriteFile(content) |
86 except device_errors.CommandFailedError: | 90 except device_errors.CommandFailedError as exc: |
| 91 logging.critical(exc) |
87 logging.critical('Cannot set Chrome command line. ' | 92 logging.critical('Cannot set Chrome command line. ' |
88 'Fix this by flashing to a userdebug build.') | 93 'Fix this by flashing to a userdebug build.') |
89 sys.exit(1) | 94 sys.exit(1) |
90 | 95 |
91 def RestoreCommandLineFlags(self): | 96 def RestoreCommandLineFlags(self): |
92 self._WriteFile(self._saved_command_line_file_contents) | 97 if self._saved_command_line_file_contents is None: |
| 98 self._RemoveFile() |
| 99 else: |
| 100 self._WriteFile(self._saved_command_line_file_contents) |
93 | 101 |
94 def _ReadFile(self): | 102 def _ReadFile(self): |
95 return self._adb.device().ReadFile(self.command_line_file) | 103 return self._adb.device().ReadFile(self.command_line_file, as_root=True) |
96 | 104 |
97 def _WriteFile(self, contents): | 105 def _WriteFile(self, contents): |
98 self._adb.device().WriteFile(self.command_line_file, contents, as_root=True) | 106 self._adb.device().WriteFile(self.command_line_file, contents, as_root=True) |
| 107 |
| 108 def _RemoveFile(self): |
| 109 self._adb.device().RunShellCommand(['rm', '-f', self.command_line_file], |
| 110 as_root=True, check_return=True) |
OLD | NEW |