| 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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 # Required by third_party/android_testrunner to call directly 'adb'. | 212 # Required by third_party/android_testrunner to call directly 'adb'. |
| 213 os.environ['PATH'] += os.pathsep + adb_dir | 213 os.environ['PATH'] += os.pathsep + adb_dir |
| 214 self._adb = adb_interface.AdbInterface() | 214 self._adb = adb_interface.AdbInterface() |
| 215 if device: | 215 if device: |
| 216 self._adb.SetTargetSerial(device) | 216 self._adb.SetTargetSerial(device) |
| 217 self._device = device | 217 self._device = device |
| 218 self._logcat = None | 218 self._logcat = None |
| 219 self.logcat_process = None | 219 self.logcat_process = None |
| 220 self._logcat_tmpoutfile = None | 220 self._logcat_tmpoutfile = None |
| 221 self._pushed_files = [] | 221 self._pushed_files = [] |
| 222 self._device_utc_offset = self.RunShellCommand('date +%z')[0] | 222 self._device_utc_offset = None |
| 223 self._md5sum_build_dir = '' | 223 self._md5sum_build_dir = '' |
| 224 self._external_storage = '' | 224 self._external_storage = '' |
| 225 self._util_wrapper = '' | 225 self._util_wrapper = '' |
| 226 | 226 |
| 227 def _LogShell(self, cmd): | 227 def _LogShell(self, cmd): |
| 228 """Logs the adb shell command.""" | 228 """Logs the adb shell command.""" |
| 229 if self._device: | 229 if self._device: |
| 230 device_repr = self._device[-4:] | 230 device_repr = self._device[-4:] |
| 231 else: | 231 else: |
| 232 device_repr = '????' | 232 device_repr = '????' |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 # -rw-r----- 1 user group 102 2011-05-12 12:29:54.131623387 +0100 baz.txt | 841 # -rw-r----- 1 user group 102 2011-05-12 12:29:54.131623387 +0100 baz.txt |
| 842 re_file = re.compile('^-(?P<perms>[^\s]+)\s+' | 842 re_file = re.compile('^-(?P<perms>[^\s]+)\s+' |
| 843 '(?P<user>[^\s]+)\s+' | 843 '(?P<user>[^\s]+)\s+' |
| 844 '(?P<group>[^\s]+)\s+' | 844 '(?P<group>[^\s]+)\s+' |
| 845 '(?P<size>[^\s]+)\s+' | 845 '(?P<size>[^\s]+)\s+' |
| 846 '(?P<date>[^\s]+)\s+' | 846 '(?P<date>[^\s]+)\s+' |
| 847 '(?P<time>[^\s]+)\s+' | 847 '(?P<time>[^\s]+)\s+' |
| 848 '(?P<filename>[^\s]+)$') | 848 '(?P<filename>[^\s]+)$') |
| 849 return _GetFilesFromRecursiveLsOutput( | 849 return _GetFilesFromRecursiveLsOutput( |
| 850 path, self.RunShellCommand('ls -lR %s' % path), re_file, | 850 path, self.RunShellCommand('ls -lR %s' % path), re_file, |
| 851 self._device_utc_offset) | 851 self.GetUtcOffset()) |
| 852 |
| 853 def GetUtcOffset(self): |
| 854 if not self._device_utc_offset: |
| 855 self._device_utc_offset = self.RunShellCommand('date +%z')[0] |
| 856 return self._device_utc_offset |
| 852 | 857 |
| 853 def SetJavaAssertsEnabled(self, enable): | 858 def SetJavaAssertsEnabled(self, enable): |
| 854 """Sets or removes the device java assertions property. | 859 """Sets or removes the device java assertions property. |
| 855 | 860 |
| 856 Args: | 861 Args: |
| 857 enable: If True the property will be set. | 862 enable: If True the property will be set. |
| 858 | 863 |
| 859 Returns: | 864 Returns: |
| 860 True if the file was modified (reboot is required for it to take effect). | 865 True if the file was modified (reboot is required for it to take effect). |
| 861 """ | 866 """ |
| (...skipping 29 matching lines...) Expand all Loading... |
| 891 build_id = self.RunShellCommand('getprop ro.build.id')[0] | 896 build_id = self.RunShellCommand('getprop ro.build.id')[0] |
| 892 assert build_id | 897 assert build_id |
| 893 return build_id | 898 return build_id |
| 894 | 899 |
| 895 def GetBuildType(self): | 900 def GetBuildType(self): |
| 896 """Returns the build type of the system (e.g. eng).""" | 901 """Returns the build type of the system (e.g. eng).""" |
| 897 build_type = self.RunShellCommand('getprop ro.build.type')[0] | 902 build_type = self.RunShellCommand('getprop ro.build.type')[0] |
| 898 assert build_type | 903 assert build_type |
| 899 return build_type | 904 return build_type |
| 900 | 905 |
| 906 def GetDescription(self): |
| 907 """Returns the description of the system. |
| 908 |
| 909 For example, "yakju-userdebug 4.1 JRN54F 364167 dev-keys". |
| 910 """ |
| 911 description = self.RunShellCommand('getprop ro.build.description')[0] |
| 912 assert description |
| 913 return description |
| 914 |
| 901 def GetProductModel(self): | 915 def GetProductModel(self): |
| 902 """Returns the namve of the product model (e.g. "Galaxy Nexus") """ | 916 """Returns the name of the product model (e.g. "Galaxy Nexus") """ |
| 903 model = self.RunShellCommand('getprop ro.product.model')[0] | 917 model = self.RunShellCommand('getprop ro.product.model')[0] |
| 904 assert model | 918 assert model |
| 905 return model | 919 return model |
| 906 | 920 |
| 907 def StartMonitoringLogcat(self, clear=True, logfile=None, filters=None): | 921 def StartMonitoringLogcat(self, clear=True, logfile=None, filters=None): |
| 908 """Starts monitoring the output of logcat, for use with WaitForLogMatch. | 922 """Starts monitoring the output of logcat, for use with WaitForLogMatch. |
| 909 | 923 |
| 910 Args: | 924 Args: |
| 911 clear: If True the existing logcat output will be cleared, to avoiding | 925 clear: If True the existing logcat output will be cleared, to avoiding |
| 912 matching historical output lurking in the log. | 926 matching historical output lurking in the log. |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1337 """ | 1351 """ |
| 1338 def __init__(self, output): | 1352 def __init__(self, output): |
| 1339 self._output = output | 1353 self._output = output |
| 1340 | 1354 |
| 1341 def write(self, data): | 1355 def write(self, data): |
| 1342 data = data.replace('\r\r\n', '\n') | 1356 data = data.replace('\r\r\n', '\n') |
| 1343 self._output.write(data) | 1357 self._output.write(data) |
| 1344 | 1358 |
| 1345 def flush(self): | 1359 def flush(self): |
| 1346 self._output.flush() | 1360 self._output.flush() |
| OLD | NEW |