| 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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 | 216 |
| 217 Args: | 217 Args: |
| 218 device: If given, adb commands are only send to the device of this ID. | 218 device: If given, adb commands are only send to the device of this ID. |
| 219 Otherwise commands are sent to all attached devices. | 219 Otherwise commands are sent to all attached devices. |
| 220 """ | 220 """ |
| 221 | 221 |
| 222 def __init__(self, device=None): | 222 def __init__(self, device=None): |
| 223 self._adb = adb_interface.AdbInterface() | 223 self._adb = adb_interface.AdbInterface() |
| 224 if device: | 224 if device: |
| 225 self._adb.SetTargetSerial(device) | 225 self._adb.SetTargetSerial(device) |
| 226 root_test_output = self.RunShellCommand('ls /root')[0] | |
| 227 self._root_enabled = not 'Permission denied' in root_test_output | |
| 228 self._logcat = None | 226 self._logcat = None |
| 229 self._original_governor = None | 227 self._original_governor = None |
| 230 self._pushed_files = [] | 228 self._pushed_files = [] |
| 231 self._device_utc_offset = self.RunShellCommand('date +%z')[0] | 229 self._device_utc_offset = self.RunShellCommand('date +%z')[0] |
| 232 | 230 |
| 233 def Adb(self): | 231 def Adb(self): |
| 234 """Returns our AdbInterface to avoid us wrapping all its methods.""" | 232 """Returns our AdbInterface to avoid us wrapping all its methods.""" |
| 235 return self._adb | 233 return self._adb |
| 236 | 234 |
| 237 def EnableAdbRoot(self): | |
| 238 self._root_enabled = self.Adb().EnableAdbRoot() | |
| 239 self._adb.SendCommand('wait-for-device') | |
| 240 | |
| 241 def IsRootEnabled(self): | 235 def IsRootEnabled(self): |
| 242 """Returns whether or not _adb.EnabledAdbRoot() has succeeded.""" | 236 """Checks if root is enabled on the device.""" |
| 243 return self._root_enabled | 237 root_test_output = self.RunShellCommand('ls /root') or [''] |
| 238 return not 'Permission denied' in root_test_output[0] |
| 244 | 239 |
| 245 def GetDeviceYear(self): | 240 def GetDeviceYear(self): |
| 246 """Returns the year information of the date on device.""" | 241 """Returns the year information of the date on device.""" |
| 247 return self.RunShellCommand('date +%Y')[0] | 242 return self.RunShellCommand('date +%Y')[0] |
| 248 | 243 |
| 249 def WaitForDevicePm(self): | 244 def WaitForDevicePm(self): |
| 250 """Blocks until the device's package manager is available. | 245 """Blocks until the device's package manager is available. |
| 251 | 246 |
| 252 To workaround http://b/5201039, we restart the shell and retry if the | 247 To workaround http://b/5201039, we restart the shell and retry if the |
| 253 package manager isn't back after 120 seconds. | 248 package manager isn't back after 120 seconds. |
| (...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 984 if len(process_results) <= 8: | 979 if len(process_results) <= 8: |
| 985 continue | 980 continue |
| 986 # Column 0 is the executable name | 981 # Column 0 is the executable name |
| 987 # Column 1 is the pid | 982 # Column 1 is the pid |
| 988 # Column 8 is the Inode in use | 983 # Column 8 is the Inode in use |
| 989 if process_results[8] == socket_name: | 984 if process_results[8] == socket_name: |
| 990 pids.append((int(process_results[1]), process_results[0])) | 985 pids.append((int(process_results[1]), process_results[0])) |
| 991 break | 986 break |
| 992 logging.info('PidsUsingDevicePort: %s', pids) | 987 logging.info('PidsUsingDevicePort: %s', pids) |
| 993 return pids | 988 return pids |
| OLD | NEW |