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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 self._pushed_files = [] | 208 self._pushed_files = [] |
209 self._device_utc_offset = self.RunShellCommand('date +%z')[0] | 209 self._device_utc_offset = self.RunShellCommand('date +%z')[0] |
210 self._md5sum_path = '' | 210 self._md5sum_path = '' |
211 self._external_storage = '' | 211 self._external_storage = '' |
212 self._util_wrapper = '' | 212 self._util_wrapper = '' |
213 | 213 |
214 def Adb(self): | 214 def Adb(self): |
215 """Returns our AdbInterface to avoid us wrapping all its methods.""" | 215 """Returns our AdbInterface to avoid us wrapping all its methods.""" |
216 return self._adb | 216 return self._adb |
217 | 217 |
| 218 def IsOnline(self): |
| 219 """Checks whether the device is online. |
| 220 |
| 221 Returns: |
| 222 True if device is in 'device' mode, False otherwise. |
| 223 """ |
| 224 out = self._adb.SendCommand('get-state') |
| 225 return out.strip() == 'device' |
| 226 |
218 def IsRootEnabled(self): | 227 def IsRootEnabled(self): |
219 """Checks if root is enabled on the device.""" | 228 """Checks if root is enabled on the device.""" |
220 root_test_output = self.RunShellCommand('ls /root') or [''] | 229 root_test_output = self.RunShellCommand('ls /root') or [''] |
221 return not 'Permission denied' in root_test_output[0] | 230 return not 'Permission denied' in root_test_output[0] |
222 | 231 |
223 def EnableAdbRoot(self): | 232 def EnableAdbRoot(self): |
224 """Enables adb root on the device. | 233 """Enables adb root on the device. |
225 | 234 |
226 Returns: | 235 Returns: |
227 True: if output from executing adb root was as expected. | 236 True: if output from executing adb root was as expected. |
(...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1207 """ | 1216 """ |
1208 def __init__(self, output): | 1217 def __init__(self, output): |
1209 self._output = output | 1218 self._output = output |
1210 | 1219 |
1211 def write(self, data): | 1220 def write(self, data): |
1212 data = data.replace('\r\r\n', '\n') | 1221 data = data.replace('\r\r\n', '\n') |
1213 self._output.write(data) | 1222 self._output.write(data) |
1214 | 1223 |
1215 def flush(self): | 1224 def flush(self): |
1216 self._output.flush() | 1225 self._output.flush() |
OLD | NEW |