# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-import constants
import logging
-import traceback
+
+import pylib.android_commands
+import pylib.device.device_utils
class FlagChanger(object):
once the tests have completed.
"""
- def __init__(self, adb,
- cmdline_file=constants.PACKAGE_INFO['chrome'].cmdline_file):
+ def __init__(self, device, cmdline_file):
"""Initializes the FlagChanger and records the original arguments.
Args:
- adb: An instance of AndroidCommands.
+ device: A DeviceUtils instance.
cmdline_file: Path to the command line file on the device.
"""
- self._adb = adb
+ # TODO(jbudorick) Remove once telemetry switches over.
+ if isinstance(device, pylib.android_commands.AndroidCommands):
+ device = pylib.device.device_utils.DeviceUtils(device)
+ self._device = device
self._cmdline_file = cmdline_file
# Save the original flags.
- self._orig_line = self._adb.GetFileContents(self._cmdline_file)
+ self._orig_line = self._device.ReadFile(self._cmdline_file)
if self._orig_line:
self._orig_line = self._orig_line[0].strip()
# The first command line argument doesn't matter as we are not actually
# launching the chrome executable using this command line.
cmd_line = ' '.join(['_'] + self._current_flags)
- if use_root:
- self._adb.SetProtectedFileContents(self._cmdline_file, cmd_line)
- file_contents = self._adb.GetProtectedFileContents(self._cmdline_file)
- else:
- self._adb.SetFileContents(self._cmdline_file, cmd_line)
- file_contents = self._adb.GetFileContents(self._cmdline_file)
+ self._device.WriteFile(
+ self._cmdline_file, cmd_line, as_root=use_root)
+ file_contents = self._device.ReadFile(
+ self._cmdline_file, as_root=use_root)
assert len(file_contents) == 1 and file_contents[0] == cmd_line, (
'Failed to set the command line file at %s' % self._cmdline_file)
else:
- if use_root:
- self._adb.RunShellCommandWithSU('rm ' + self._cmdline_file)
- else:
- self._adb.RunShellCommand('rm ' + self._cmdline_file)
- assert not self._adb.FileExistsOnDevice(self._cmdline_file), (
+ self._device.RunShellCommand('rm ' + self._cmdline_file,
+ as_root=use_root)
+ assert not self._device.FileExists(self._cmdline_file), (
'Failed to remove the command line file at %s' % self._cmdline_file)
- def _TokenizeFlags(self, line):
+ @staticmethod
+ def _TokenizeFlags(line):
"""Changes the string containing the command line into a list of flags.
Follows similar logic to CommandLine.java::tokenizeQuotedArguments: