OLD | NEW |
---|---|
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 constants | 5 import constants |
6 import logging | 6 import logging |
7 import traceback | 7 import traceback |
8 | 8 |
9 | 9 |
10 class FlagChanger(object): | 10 class FlagChanger(object): |
(...skipping 74 matching lines...) Loading... | |
85 self._UpdateCommandLineFile() | 85 self._UpdateCommandLineFile() |
86 | 86 |
87 def Restore(self): | 87 def Restore(self): |
88 """Restores the flags to their original state.""" | 88 """Restores the flags to their original state.""" |
89 self._current_flags = self._TokenizeFlags(self._orig_line) | 89 self._current_flags = self._TokenizeFlags(self._orig_line) |
90 self._UpdateCommandLineFile() | 90 self._UpdateCommandLineFile() |
91 | 91 |
92 def _UpdateCommandLineFile(self): | 92 def _UpdateCommandLineFile(self): |
93 """Writes out the command line to the file, or removes it if empty.""" | 93 """Writes out the command line to the file, or removes it if empty.""" |
94 logging.info('Current flags: %s', self._current_flags) | 94 logging.info('Current flags: %s', self._current_flags) |
95 | 95 # Root is not required to write to /data/local/tmp/. |
96 use_root = '/data/local/tmp/' not in self._cmdline_file | |
96 if self._current_flags: | 97 if self._current_flags: |
97 # The first command line argument doesn't matter as we are not actually | 98 # The first command line argument doesn't matter as we are not actually |
98 # launching the chrome executable using this command line. | 99 # launching the chrome executable using this command line. |
99 self._adb.SetProtectedFileContents(self._cmdline_file, | 100 cmd_line = ' '.join(['_'] + self._current_flags) |
100 ' '.join(['_'] + self._current_flags)) | 101 if use_root: |
102 self._adb.SetProtectedFileContents(self._cmdline_file, cmd_line) | |
103 file_contents = self._adb.GetProtectedFileContents(self._cmdline_file) | |
104 else: | |
105 self._adb.SetFileContents(self._cmdline_file, cmd_line) | |
frankf
2013/10/07 22:09:03
as part of API cleanup, you should just have SetFi
| |
106 file_contents = self._adb.GetFileContents(self._cmdline_file) | |
107 assert file_contents == cmd_line, ( | |
108 'Failed to set the command line file at %s' % self._cmdline_file) | |
101 else: | 109 else: |
102 self._adb.RunShellCommand('su -c rm ' + self._cmdline_file) | 110 prefix = 'su -c ' if use_root else '' |
111 self._adb.RunShellCommand(prefix + 'rm ' + self._cmdline_file) | |
frankf
2013/10/07 22:09:03
We have something like RunShellCommandSu which you
craigdh
2013/10/07 22:36:28
Done.
| |
112 assert not self._adb.FileExistsOnDevice(self._cmdline_file), ( | |
frankf
2013/10/07 22:09:03
as part of API cleanup, rm'ing should guarantee th
| |
113 'Failed to remove the command line file at %s' % self._cmdline_file) | |
103 | 114 |
104 def _TokenizeFlags(self, line): | 115 def _TokenizeFlags(self, line): |
105 """Changes the string containing the command line into a list of flags. | 116 """Changes the string containing the command line into a list of flags. |
106 | 117 |
107 Follows similar logic to CommandLine.java::tokenizeQuotedArguments: | 118 Follows similar logic to CommandLine.java::tokenizeQuotedArguments: |
108 * Flags are split using whitespace, unless the whitespace is within a | 119 * Flags are split using whitespace, unless the whitespace is within a |
109 pair of quotation marks. | 120 pair of quotation marks. |
110 * Unlike the Java version, we keep the quotation marks around switch | 121 * Unlike the Java version, we keep the quotation marks around switch |
111 values since we need them to re-create the file when new flags are | 122 values since we need them to re-create the file when new flags are |
112 appended. | 123 appended. |
(...skipping 28 matching lines...) Loading... | |
141 | 152 |
142 # Tack on the last flag. | 153 # Tack on the last flag. |
143 if not current_flag: | 154 if not current_flag: |
144 if within_quotations: | 155 if within_quotations: |
145 logging.warn('Unterminated quoted argument: ' + line) | 156 logging.warn('Unterminated quoted argument: ' + line) |
146 else: | 157 else: |
147 tokenized_flags.append(current_flag) | 158 tokenized_flags.append(current_flag) |
148 | 159 |
149 # Return everything but the program name. | 160 # Return everything but the program name. |
150 return tokenized_flags[1:] | 161 return tokenized_flags[1:] |
OLD | NEW |