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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 | 196 |
197 | 197 |
198 def GetLogTimestamp(log_line, year): | 198 def GetLogTimestamp(log_line, year): |
199 """Returns the timestamp of the given |log_line| in the given year.""" | 199 """Returns the timestamp of the given |log_line| in the given year.""" |
200 try: | 200 try: |
201 return datetime.datetime.strptime('%s-%s' % (year, log_line[:18]), | 201 return datetime.datetime.strptime('%s-%s' % (year, log_line[:18]), |
202 '%Y-%m-%d %H:%M:%S.%f') | 202 '%Y-%m-%d %H:%M:%S.%f') |
203 except (ValueError, IndexError): | 203 except (ValueError, IndexError): |
204 logging.critical('Error reading timestamp from ' + log_line) | 204 logging.critical('Error reading timestamp from ' + log_line) |
205 return None | 205 return None |
206 | 206 |
bulach
2012/07/17 10:26:08
nit: the styleguide requires two \n between top-le
| |
207 def RestartAdbServer(): | |
208 """Restart the adb server.""" | |
209 KillAdbServer() | |
210 StartAdbServer() | |
211 | |
212 def KillAdbServer(): | |
213 """Kill adb server.""" | |
214 adb_cmd = ['adb', 'kill-server'] | |
215 return cmd_helper.RunCmd(adb_cmd) | |
216 | |
217 def StartAdbServer(): | |
218 """Start adb server.""" | |
219 adb_cmd = ['adb', 'start-server'] | |
220 return cmd_helper.RunCmd(adb_cmd) | |
221 | |
207 | 222 |
208 class AndroidCommands(object): | 223 class AndroidCommands(object): |
209 """Helper class for communicating with Android device via adb. | 224 """Helper class for communicating with Android device via adb. |
210 | 225 |
211 Args: | 226 Args: |
212 device: If given, adb commands are only send to the device of this ID. | 227 device: If given, adb commands are only send to the device of this ID. |
213 Otherwise commands are sent to all attached devices. | 228 Otherwise commands are sent to all attached devices. |
214 """ | 229 """ |
215 | 230 |
216 def __init__(self, device=None): | 231 def __init__(self, device=None): |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
312 | 327 |
313 logging.info('>>> $' + install_command) | 328 logging.info('>>> $' + install_command) |
314 return self._adb.SendCommand(install_command, timeout_time=2*60) | 329 return self._adb.SendCommand(install_command, timeout_time=2*60) |
315 | 330 |
316 def MakeSystemFolderWritable(self): | 331 def MakeSystemFolderWritable(self): |
317 """Remounts the /system folder rw. """ | 332 """Remounts the /system folder rw. """ |
318 out = self._adb.SendCommand('remount') | 333 out = self._adb.SendCommand('remount') |
319 if out.strip() != 'remount succeeded': | 334 if out.strip() != 'remount succeeded': |
320 raise errors.MsgException('Remount failed: %s' % out) | 335 raise errors.MsgException('Remount failed: %s' % out) |
321 | 336 |
322 def RestartAdbServer(self): | |
323 """Restart the adb server.""" | |
324 self.KillAdbServer() | |
325 self.StartAdbServer() | |
326 | |
327 def KillAdbServer(self): | |
328 """Kill adb server.""" | |
329 adb_cmd = ['adb', 'kill-server'] | |
330 return cmd_helper.RunCmd(adb_cmd) | |
331 | |
332 def StartAdbServer(self): | |
333 """Start adb server.""" | |
334 adb_cmd = ['adb', 'start-server'] | |
335 return cmd_helper.RunCmd(adb_cmd) | |
336 | |
337 def WaitForSystemBootCompleted(self, wait_time): | 337 def WaitForSystemBootCompleted(self, wait_time): |
338 """Waits for targeted system's boot_completed flag to be set. | 338 """Waits for targeted system's boot_completed flag to be set. |
339 | 339 |
340 Args: | 340 Args: |
341 wait_time: time in seconds to wait | 341 wait_time: time in seconds to wait |
342 | 342 |
343 Raises: | 343 Raises: |
344 WaitForResponseTimedOutError if wait_time elapses and flag still not | 344 WaitForResponseTimedOutError if wait_time elapses and flag still not |
345 set. | 345 set. |
346 """ | 346 """ |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
934 if len(process_results) <= 8: | 934 if len(process_results) <= 8: |
935 continue | 935 continue |
936 # Column 0 is the executable name | 936 # Column 0 is the executable name |
937 # Column 1 is the pid | 937 # Column 1 is the pid |
938 # Column 8 is the Inode in use | 938 # Column 8 is the Inode in use |
939 if process_results[8] == socket_name: | 939 if process_results[8] == socket_name: |
940 pids.append( (int(process_results[1]), process_results[0]) ) | 940 pids.append( (int(process_results[1]), process_results[0]) ) |
941 break | 941 break |
942 logging.info('PidsUsingDevicePort: %s', pids) | 942 logging.info('PidsUsingDevicePort: %s', pids) |
943 return pids | 943 return pids |
OLD | NEW |