Index: build/android/pylib/device/device_utils.py |
diff --git a/build/android/pylib/device/device_utils.py b/build/android/pylib/device/device_utils.py |
index 72238fdc7a606d6b977acff0cb079a959fce94a6..743b1ce1a25f938c15bd94e57e5b9d17af0ddaad 100644 |
--- a/build/android/pylib/device/device_utils.py |
+++ b/build/android/pylib/device/device_utils.py |
@@ -65,13 +65,6 @@ |
CommandFailedError if we fail to kill or restart the server. |
""" |
pylib.android_commands.AndroidCommands().RestartAdbServer() |
- |
- |
-def _JoinLines(lines): |
- # makes sure that the last line is also terminated, and is more memory |
- # efficient than first appending an end-line to each line and then joining |
- # all of them together. |
- return ''.join(s for line in lines for s in (line, '\n')) |
class DeviceUtils(object): |
@@ -865,8 +858,7 @@ |
self.adb.Pull(device_path, host_path) |
@decorators.WithTimeoutAndRetriesFromInstance() |
- def ReadFile(self, device_path, as_root=False, |
- timeout=None, retries=None): |
+ def ReadFile(self, device_path, as_root=False, timeout=None, retries=None): |
"""Reads the contents of a file from the device. |
Args: |
@@ -878,17 +870,22 @@ |
retries: number of retries |
Returns: |
- The contents of |device_path| as a string. Contents are intepreted using |
- universal newlines, so the caller will see them encoded as '\n'. Also, |
- all lines will be terminated. |
- |
- Raises: |
- AdbCommandFailedError if the file can't be read. |
- CommandTimeoutError on timeout. |
- DeviceUnreachableError on missing device. |
- """ |
- return _JoinLines(self.RunShellCommand( |
- ['cat', device_path], as_root=as_root, check_return=True)) |
+ The contents of the file at |device_path| as a list of lines. |
+ |
+ Raises: |
+ CommandFailedError if the file can't be read. |
+ CommandTimeoutError on timeout. |
+ DeviceUnreachableError on missing device. |
+ """ |
+ # TODO(jbudorick) Evaluate whether we want to return a list of lines after |
+ # the implementation switch, and if file not found should raise exception. |
+ if as_root: |
+ if not self.old_interface.CanAccessProtectedFileContents(): |
+ raise device_errors.CommandFailedError( |
+ 'Cannot read from %s with root privileges.' % device_path) |
+ return self.old_interface.GetProtectedFileContents(device_path) |
+ else: |
+ return self.old_interface.GetFileContents(device_path) |
@decorators.WithTimeoutAndRetriesFromInstance() |
def WriteFile(self, device_path, contents, as_root=False, force_push=False, |