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 """Provides an interface to communicate with the device via the adb command. | 5 """Provides an interface to communicate with the device via the adb command. |
6 | 6 |
7 Assumes adb binary is currently on system path. | 7 Assumes adb binary is currently on system path. |
8 """ | 8 """ |
9 | 9 |
10 import collections | 10 import collections |
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 self.GetExternalStorage() + '/' + base_name % i): | 722 self.GetExternalStorage() + '/' + base_name % i): |
723 i += 1 | 723 i += 1 |
724 return self.GetExternalStorage() + '/' + base_name % i | 724 return self.GetExternalStorage() + '/' + base_name % i |
725 | 725 |
726 def CanAccessProtectedFileContents(self): | 726 def CanAccessProtectedFileContents(self): |
727 """Returns True if Get/SetProtectedFileContents would work via "su". | 727 """Returns True if Get/SetProtectedFileContents would work via "su". |
728 | 728 |
729 Devices running user builds don't have adb root, but may provide "su" which | 729 Devices running user builds don't have adb root, but may provide "su" which |
730 can be used for accessing protected files. | 730 can be used for accessing protected files. |
731 """ | 731 """ |
732 return self.RunShellCommand('su -c cat /dev/null') == [''] | 732 r = self.RunShellCommand('su -c cat /dev/null') |
| 733 return r == [] or r[0].strip() == '' |
733 | 734 |
734 def GetProtectedFileContents(self, filename, log_result=False): | 735 def GetProtectedFileContents(self, filename, log_result=False): |
735 """Gets contents from the protected file specified by |filename|. | 736 """Gets contents from the protected file specified by |filename|. |
736 | 737 |
737 This is less efficient than GetFileContents, but will work for protected | 738 This is less efficient than GetFileContents, but will work for protected |
738 files and device files. | 739 files and device files. |
739 """ | 740 """ |
740 # Run the script as root | 741 # Run the script as root |
741 return self.RunShellCommand('su -c cat "%s" 2> /dev/null' % filename) | 742 return self.RunShellCommand('su -c cat "%s" 2> /dev/null' % filename) |
742 | 743 |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1217 """ | 1218 """ |
1218 def __init__(self, output): | 1219 def __init__(self, output): |
1219 self._output = output | 1220 self._output = output |
1220 | 1221 |
1221 def write(self, data): | 1222 def write(self, data): |
1222 data = data.replace('\r\r\n', '\n') | 1223 data = data.replace('\r\r\n', '\n') |
1223 self._output.write(data) | 1224 self._output.write(data) |
1224 | 1225 |
1225 def flush(self): | 1226 def flush(self): |
1226 self._output.flush() | 1227 self._output.flush() |
OLD | NEW |